Sweep and Prune order of operations confusion

Please don't post Bullet support questions here, use the above forums instead.
bronxbomber92
Posts: 10
Joined: Mon Oct 01, 2007 9:36 pm

Sweep and Prune order of operations confusion

Post by bronxbomber92 »

Hello,

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]);
}
2.) The update method. This recomputes the AABB, sorts each axis array, then check for collision (using box pruning - which I don't know much about?). If a collision it found, it adds it to the pair manager.

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!