Box2D 2.2.0 を使用して、Box2D を使用したゲームに取り組んでいます。プレイヤーは AABB を撃ちます。各 step() で、AABB を移動し、b2World->QueryAABB( &queryCallback, 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)