转载自: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(); }
获取Box2D中已创建体的边界框
本文解答了如何在Box2D中获取已创建并正在世界中交互的体的边界框的问题,通过迭代体的所有碰撞形状来生成新的AABB。
764

被折叠的 条评论
为什么被折叠?



