How to get a correct AABB for a collision shape?

Looking for answers? Check here first

How to get a correct AABB for a collision shape?

Postby Julio Jerez » Tue May 19, 2009 4:59 pm

Function NewtonCollisionCalculateAABB() return and AABB designed for fast determination of colliding pairs.
The AABB in must case will fix the collision shape, but in some other cases it will be just an approximation of the shape.
For example this function will calculate a fitting box for a cylinder but will not do so if this cylinder has an offset matrix or and scaled matrix.
As long as the box is larger than the shape this is not problem for the physic engine, but will report inacurate result to the client application.

if an application requires a tight fitting bounding box, the application should use function SupportVertex, here it is a function to do that

Code: Select all
void CalculteLocalAABB (const dMatrix& matrix, NewtonCollision *collision, dVector& p0, dVector& p1)
{
   for (int i = 0; i < 3; i ++) {
      dVector dir (0.0f, 0.0f, 0.0f, 0.0f);

      dir[i] = 1.0f;
      dir = matrix.RotateVector (dir);
      NewtonCollisionSupportVertex (collision, &dir[0], &p1[0]);

      dir = dir.Scale (-1.0f);
      NewtonCollisionSupportVertex (collision, &dir[0], &p0[0]);
   }
}


This function is accurate for all shape, and it calculates a generic AABB,
by setting matrix to identity you get the local aabb.
if you want a global AABB you just the matrix of the object an pass the inverse to the functions.
Julio Jerez
Moderator
Moderator
 
Posts: 3668
Joined: Sun Sep 14, 2003 1:18 pm
Location: Los Angeles

Re: How to get a correct AABB for a collision shape?

Postby Delfi » Wed May 05, 2010 12:05 pm

I already put warnings about that in calculateAABB wiki page, directing people to NewtonCollisionSupportVertex page, which already has a example how to calculate a proper tight AABB from one of your older posts, i'll add this local aabb there aswell (function there is for global aabb only).
Help improving the Newton Game Dynamics WIKI
User avatar
Delfi
 
Posts: 1028
Joined: Mon Dec 06, 2004 1:00 pm
Location: Slovenia


Return to FAQ

Who is online

Users browsing this forum: No registered users and 2 guests