Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

aker_jus

Bounding Spheres?

This topic is 5828 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have implemented a frustum calculation method in my engine and test for sphere. What I need now is an algorithm for creating a bounding sphere from a mesh (I use ms3d meshes with my on renderer). So basically, is there a way to make a bounding sphere (center and radius) from the mesh''s vertices? I have searched google and flipcode, but I didnt get good results.

Share this post


Link to post
Share on other sites
Advertisement
Actualy there has been COTD on flipcode about generation minimal bouding spheres with some kind recursion algorithem.

You should never let your fears become the boundaries of your dreams.

Share this post


Link to post
Share on other sites
Creating bounding spheres is quite simple really. You need to first find the center the object, and then test the distance between that and every vertex in the object to get the max. distance. Save that and the radius. To test for collision between two objects, test the sum of their radiuses and against the distance between the two center vertexes. If that distance is greater, the two objects are not colliding.

How do I find the center and the maximum vertex? Well, for the center, you need to create a bounding box and find the midpoint between two diagomally opposite vertexes. But how do you compute the box?! Still easy! You need to find the minimum and maximum x, y, and z values in the entire object. Just iterate through and test each one against the currently stored values.

I don't have much more time, so I can't give you all the algorithms and such. Just search "bounding sphere collision detection" on google.com. You _should_ find something, I've tried it before. At worst you may need to invest in a book. The first of the Gems series explains this very well (that's where I learned it ).

[edited by - aggregate on November 1, 2002 12:39:24 PM]

Share this post


Link to post
Share on other sites
Some of my code to do a bounding box, I hope this helps:


  
//in the header

typedef struct
{
float min_x;
float min_y;
float min_z;
float max_x;
float max_y;
float max_z;

}box;

//whatever function

//clear the bounding box

box.min_x=1200.0f;
box.min_y=1200.0f;
box.min_z=1200.0f;

box.max_x=-1200.0f;
box.max_y=-1200.0f;
box.max_z=-1200.0f;

for(k=0;k<numVertices;k++)
{
//get x,y,z, from your mesh


//do the bounding box

if(box.min_x>x)box.min_x=x;

if(box.max_x<x)box.max_x=x;

if(box.min_y>y)box.min_y=y;

if(box.max_y<y)box.max_y=y;

if(box.min_z>z)box.min_z=z;

if(box.max_z<z)box.max_z=z;
}



[edited by - Raduprv on November 1, 2002 4:50:05 PM]

Share this post


Link to post
Share on other sites
Use both! First do a quick sphere test then only if sphere is partly inside do bouding box test.

You should never let your fears become the boundaries of your dreams.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!