Advertisement

Question on how to calculate AABB box

Started by October 28, 2002 12:09 AM
3 comments, last by nachilau 22 years, 3 months ago
Hello, I have a question about the calculation of AABB box. I am using DirectX 8.1 api, and would like to calculate a AABB box with my object. Actually, the object is keep rotating and so the AABB box is going to change all the time. However, since what I am currently doing is transform my 3d object with the rotation matrix in every render call, I have no idea to get the final vertices of the object that has been transformed. Therefore, I have no idea to find the pMax and pMin of my rotating object. So, can anyone give me some idea how can I actually implement and update the AABB box in directX? Moreover, is there any way to calculate the AABB box of the rotation object in each frame from the information in the initial AABB box of the object? Then, I don''t need to go to check all vertices in the object to find the pMax and pMin in every frame. Thanks! Nachi
Nachi Lau (In Christ, I never die)www.sky-dio.com/Nachi
Hi,

I think you''re a little confused, the point of AABB is that it never changes, it always remains axis aligned, and by definition should encompass your entire model.

The only problem with rotating the model and using a AABB is if the models origin is not at the center of the model. Also if the model is animated, then each frame will need a unique AABB or a single one which encompasses all the animation frames.

To calculate a AABB, simply loop through all the models vertices, and store the x,y,z values if they are < or > the min max x,y,z values. This is the model AABB, to use it within the world, just add the models transform to it. If you wanted you could also apply the models rotation, but it would no longer be axis aligned.

Alternatively you could look into OBB (orientated Bounding box)

hope this helps
noisecrime
Advertisement
The AABB of an object does change each time the object is rotated.

Think of a rectangle that is rotated 45 degrees. Its AABB would be different that when it is rotated 0 degrees.

This is one of the reasons some engines use spheres instead of AABB for gross collision detection.

To get the bounds for your AABB, a common method is to have 2 verticies that specify the Lower Left & Upper Right of the AABB at ''rest'' ( ie the object is not rotated ). To get the AABB of a rotated object, pass these 2 verticies throught the objects current matrix. The resulting verticies are the objects new AABB values.

pcode:


UpdateAABB( object )
{
object->aabb.ll = object->ll * object->matrix
object->aabb.ur = object->ur * object->matrix

}

where ll, ur are verticies that define the object abbb at rest.
matrix is the object current transformation matrix
aabb is a set of 2 verticies ( ll, ur ) that are the ''current'' aabb.

Hope this helps.

>>To get the AABB of a rotated object, pass these 2 verticies throught the objects current matrix. The resulting verticies are the objects new AABB values.<<

I don''t think that''s correct. I''m pretty sure that if you try to do that then you''re bounding box will squish itself down to nothing as you rotate around.

As far as I know there are two methods you can go about when using an AABB with a rotating object:

1. Use a box that is big enough so that it always encompasses your object, no matter how it rotates. I''m sure there are a number of methods to pre-calculate the least possible size of this one-size fits all box.

2. The second method involves creating a new AABB each frame to encompass your objects new orientation. I believe that the simplest method is to take ALL 8 points of the box, rotate them, and then find the min/max in each axis from those 8 points to find the two points(min & max) points of your new AABB.

There could be other/better methods, but that''s what I know

-John
- John
Yes,

Finally, I use the second method. Just pass the two vertices pMax, and pMin to the transform matrix doesn''t work, since I think the result is just a OBB box but not AABB. But anyway, thank the suggestion from all you guys!

Nachi
Nachi Lau (In Christ, I never die)www.sky-dio.com/Nachi

This topic is closed to new replies.

Advertisement