使用 Box2D 2.2.0,我正在使用 Box2D 开发游戏。玩家射击 AABB。在每个 step() 中,我通过 b2World->QueryAABB( &queryCallback, aabb ) 移动 AABB 并处理冲突。然而,我的游戏世界是由链形组成的。所以 b2World->QueryAABB 只检测倾斜链形状的 AABB。所以我目前的目标是从 ReportFixture() 获取子索引,以便我可以针对链形的指定边缘测试 AABB。
我发现了这个:http ://www.box2d.org/forum/viewtopic.php?f=3&t=8902
在那篇文章之后,我将子索引添加到 Report Fixture,如下面的代码所示。
我的问题是,当我取回 childIndex 时,它总是类似于 -1082069312、-1053558930、-1073540884。
//in b2WorldCallbacks.h
class b2QueryCallback
{
public:
virtual ~b2QueryCallback() {}
/// Called for each fixture found in the query AABB.
/// @return false to terminate the query.
virtual bool ReportFixture(b2Fixture* fixture, int32 childIndex) = 0;
};
和
//in b2World.cpp
struct b2WorldQueryWrapper
{
bool QueryCallback(int32 proxyId)
{
b2FixtureProxy* proxy = (b2FixtureProxy*)broadPhase->GetUserData(proxyId);
return callback->ReportFixture(proxy->fixture, proxy->childIndex);
}
const b2BroadPhase* broadPhase;
b2QueryCallback* callback;
};
这是我的 b2QueryCallback:
class MyQueryCallback : public b2QueryCallback {
public:
vector<b2Fixture*> foundFixtures;
vector<int32> foundIndex;
bool ReportFixture(b2Fixture* fixture, int32 childIndex) {
foundFixtures.push_back ( fixture );
foundIndex.push_back( childIndex );
return true;
}
};
在测试台中:
// PolyShapes.h, line 85
bool ReportFixture(b2Fixture* fixture, int32 childIndex)
和
//Test.cpp, line 113
bool ReportFixture(b2Fixture* fixture, int32 childIndex)