0

使用 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)
4

1 回答 1

0

看起来你做的一切都是正确的。我怀疑您的项目的一部分没有使用新修改的标头重新完全编译,因此 ReportFixture 的第二个参数甚至没有被传递。也就是说,调用代码仍然使用函数的原始单参数版本,因此 childIndex 永远不会被压入调用堆栈。

您是否有机会使用 Xcode?当你有预编译的头文件时,Xcode 很擅长把它搞砸——它根本不会检测到它们何时需要刷新。除了清理和重建之外,您还可以尝试删除“派生数据”——我相信 Apple 的另一个绝妙想法是出于好意,但实施起来似乎很匆忙。显然,在“构建”和“清理”选项旁边放置一个删除“派生数据”的选项太明显了,因此您可以在“管理器”窗口的“项目”选项卡中找到它隐藏起来。</rant>

于 2013-12-16T10:47:56.377 回答