How to get a correct AABB for a collision shape?

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

How to get a correct AABB for a collision shape?

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

Function NewtonCollisionCalculateAABB() return and AABB designed for fast determination of colliding pairs.
The AABB in most cases 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 CalculateLocalAABB (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 shapes, 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: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

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

Postby JernejL » Wed May 05, 2010 1: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
JernejL
 
Posts: 1587
Joined: Mon Dec 06, 2004 2:00 pm
Location: Slovenia


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 2 guests