I do not understand the order of operations of a SAP. This is how I understand it:
1.) Add an object(s) to the SAP. This computes the AABB of the rigidbody, add the min and max endpoints to each dynamic array (one for each axis), and adds the box/AABB to the array of boxes. This step does no sorting or collision detection. Some example code:
Code: Select all
void SapBroadPhase::AddObject( const RigidBody& body )
{
// See if it's been all ready added
std::list<Box>::iterator it = boxes.begin();
std::list<Box>::iterator end = boxes.end();
for( ; it !=end; it++ )
{
if(it->owner->Id() == body.Id() ) return;
}
// Create the new Box and AABB
Box* newBox = new Box;
newBox->owner = body;
newBox->aabb = ComputeAABB(body);
// Add the new Box
boxes.push_back(newBox);
++numBoxes;
xAxis.push_back(boxes->min[0]);
xAxis.push_back(boxes->max[0]);
yAxis.push_back(boxes->min[1]);
yAxis.push_back(boxes->max[1]);
zAxis.push_back(boxes->min[2]);
zAxis.push_back(boxes->max[2]);
}
How it checks for intersections on all three axis makes no sense to me since the it seems impossible to check overlaps in all 3 dimensions because the arrays are sorted. Can someone explain how this works, and/or possibly provide pseudocode?
Thanks!