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.