我是box2d的新手。我在box2d开始了一个新游戏,在世界上创造了5个动态的机构。最初我需要防止它们之间的冲突。所以我设置所有身体的组索引为负。触摸身体后,我想让与身体发生碰撞。如何重置组索引。请帮忙..
答案 0 :(得分:2)
听起来像是在寻找像
这样的东西b2Body *body = world->GetBodyList();
b2Filter filter = body->GetFilterData();
filter.maskBits = filter.maskBits | THE_RELEVANT_CATEGORY_BITS;
body->SetFilterData(&filter);
这里的想法是你可以获得任何对象的碰撞过滤数据,使用一些布尔逻辑将碰撞数据分配给maskBits字段,然后使用SetFilterData将新的碰撞数据应用到主体。 THE_RELEVANT_CATEGORY_BITS应该是枚举类型的元素,其中每个碰撞过滤类别由唯一的二进制整数表示。
的更多信息,请查看box2D教程答案 1 :(得分:1)
如果你有超过1个身体的灯具,那么你可以使用这个代码块
for (b2Fixture* fix = body->GetFixtureList(); fix; fix = fix->GetNext())
{
b2Filter filter= fix->GetFilterData();
filter.groupIndex = 0;
filter.categoryBits = 0x0004;
filter.maskBits = 0x0002;
fix->SetFilterData(filter);
}