Skip to main content
gamedev.net
🔒 Locked

Bounding Boxes

Started by Mr_Ridd 14 replies 900+ views
Original Post
Mr_Ridd
Mr_Ridd
Howzit How do I calculate the bounding box of a model that I have imported? I''ve searched on google but can''t find anything substantial. Shot
The ability to succeed is the ability to adapt
Ximmer
Ximmer
Mesh is an array ov Vertexes


Vertex v;

Vertex Min;
Vertex Max;

Min = Mesh[0];
Max = Mesh[0];

for(j = 1; j < NumVerts; j++)
{
if(Mesh[j].x < Min.x) Min.x = Mesh[j].x;
if(Mesh[j].y < Min.y) Min.y = Mesh[j].y;
if(Mesh[j].z < Min.z) Min.z = Mesh[j].z;
if(Mesh[j].x > Max.x) Max.x = Mesh[j].x;
if(Mesh[j].y > Max.y) Max.y = Mesh[j].y;
if(Mesh[j].z > Max.z) Max.z = Mesh[j].z;
}

now Min and Max define a Bounding Box
(edit) Stupid italics

[edited by - Ximmer on January 27, 2004 3:06:29 AM]
Mr_Ridd
Mr_Ridd
Looks simple enough.

Just one thing, does that mesh contain all the vertexes for all the meshes, or will I have to do that for every mesh?

[edited by - Mr_Ridd on January 27, 2004 3:31:25 AM]
The ability to succeed is the ability to adapt
Ximmer
Ximmer
The Mesh would contain all the Vertecies for what your trying to make the bounding box for.

also that only makes 2 corners of the box but you should be able to get the other corners from that
gotton
gotton
You can define a bounding box with a convex hull
Mr_Ridd
Mr_Ridd
How do you do that and what is a convex hull?
The ability to succeed is the ability to adapt
oliii
oliii
don't worry about convex hulls

a simple box, defined by 2 points, is as simple as it gets. It's something you can use for simple collision detection.

and if you want, you can make boxes for sub parts of the model. The algorithm above builds a box around the list of vertices you supply, so you can supply anything, and it will build a box around it.

[edited by - oliii on January 27, 2004 6:49:26 AM]
Everything is better with Metal.
Mr_Ridd
Mr_Ridd
I did what is above and Max and Min ended up to be the same values.
The ability to succeed is the ability to adapt
oliii
oliii
you must have done something wrong in the signs, or using the ''j'' parameter.

unless your number of vertices is <= 1.
Everything is better with Metal.
gotton
gotton
oliii, know something about any other kind of bounding box?
the bounding box must >= convex hull of the vertices and must easy to caculate the distance between 2 bounding boxes, thx!
oliii
oliii
I''m not sure I understand the question

there are only 2 kinds of bounding boxes I know of. Oriented and Axis Aligned (which is a special case of oriented bounding box).

to calculate bounding box distances, and (penetration depths as well), you can use the separation axis algorithm. Well, I never tried to use that algo for distances (when not intersecting), but I use it for interpenetrations, and at the same time calculating the contact points on both boxes.
Everything is better with Metal.
gotton
gotton
Thx!
Any other 3D bounding **** such as sphere, cone, or simplex?
The boxes are too "big" for the meshes in some cases.
I need a fast algorithm to build the bounding **** and calculate the distance between 2 bounding ****.
oliii
oliii
an algo for distance calculations is the GJK algorithm. It apply for any convex shape.

and as far as bounding objects go, the tightest convex shape (I think) you can wrap around an object is a convex hull. And even then, there is a lot of space wasted in some occasions. And building a convex hull is not that simple.

you can also try using a simple and very coarse octree, and finding approximations of the distance using the octree.
Everything is better with Metal.
sirSolarius
sirSolarius
How do you recalculate the bounding box if the object rotates?
oliii
oliii
as a simple solution, make 8 points at the bounding box corner, rotate them (and translate to the object position), and use the min-max algo above to get the axis aligned box around your box corners. It''s not super accurate, but fast.
Everything is better with Metal.
gotton
gotton
What is a octree?
where can i find some articles about octrees?
thx!

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.