Using Box2D 2.2.0, I'm working on a game using Box2D. The player shoots AABBs. In each step() I move the AABB and handle collisions by going through b2World->QueryAABB( &queryCallback, aabb ). However, my game world is made up of chain shapes. So b2World->QueryAABB is only detecting the AABBs of inclined chain shapes. So my goal at the moment is to get the child index from ReportFixture() so that I can test the AABB against the chainshape's specified edge.
I found this: http://www.box2d.org/forum/viewtopic.php?f=3&t=8902
Following that post, I added the child index to Report Fixture, as seen in the code below.
My problem is that when I get back the childIndex, it's always something along the lines of -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;
};
and
//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;
};
Here is my 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;
}
};
In testbed:
// PolyShapes.h, line 85
bool ReportFixture(b2Fixture* fixture, int32 childIndex)
and
//Test.cpp, line 113
bool ReportFixture(b2Fixture* fixture, int32 childIndex)