Box2D Get Bounding Box of a Body
转载自:http://gamedev.stackexchange.com/questions/1366/box2d-get-bounding-box-of-a-body
问题:
In Box2D, I was curious if it's possible to get a bounding box of a body already created in the world.
So basically, the Body is created, it's interacting with the world and such. And I needed that Body's bounding box. Is it possible?
答案:In Box2D, bodies don't have bounding boxes associated with them, fixture do.
So you need to iterate over all the fixtures and generate a new AABB. Something like this:
b2AABB aabb; aabb.lowerBound = b2Vec2(FLT_MAX,FLT_MAX); aabb.upperBound = b2Vec2(-FLT_MAX,-FLT_MAX); b2Fixture* fixture = body->GetFixtureList(); while (fixture != NULL) { aabb.Combine(aabb, fixture->GetAABB()); fixture = fixture->GetNext(); }