Download Box2D v2.2.1 User Manual
Transcript
b2Body* node = myWorld->GetBodyList();
while (node)
{
b2Body* b = node;
node = node->GetNext();
GameActor* myActor = (GameActor*)b->GetUserData();
if (myActor->IsDead())
{
bool otherBodiesDestroyed = GameCrazyBodyDestroyer(b);
if (otherBodiesDestroyed)
{
node = myWorld->GetBodyList();
}
}
}
Obviously to make this work, GameCrazyBodyDestroyer must be honest about what it has destroyed.
AABB Queries
Sometimes you want to determine all the shapes in a region. The b2World class has a fast log(N) method
for this using the broad-phase data structure. You provide an AABB in world coordinates and an
implementation of b2QueryCallback. The world calls your class with each fixture whose AABB overlaps
the query AABB. Return true to continue the query, otherwise return false. For example, the following
code finds all the fixtures that potentially intersect a specified AABB and wakes up all of the associated
bodies.
class MyQueryCallback : public b2QueryCallback
{
public:
bool ReportFixture(b2Fixture* fixture)
{
b2Body* body = fixture->GetBody();
body->SetAwake(true);
// Return true to continue the query.
return true;
}
};
...
MyQueryCallback callback;
b2AABB aabb;
aabb.lowerBound.Set(-1.0f, -1.0f);
aabb.upperBound.Set(1.0f, 1.0f);
myWorld->Query(&callback, aabb);
You cannot make any assumptions about the order of the callbacks.