0

我正在使用下面的代码来尝试生成多边形形状的精灵。我遇到了代码问题,有人能发现它有什么问题吗?

   b2BodyDef woodBodyDef;
     woodBodyDef.position.Set(400/PTM_RATIO,100/PTM_RATIO);
     woodBodyDef.type = b2_dynamicBody;
     woodBodyDef.userData = _wood;
     _body = _world->CreateBody(&woodBodyDef);

     b2PolygonShape woodShape;

     int num = 4;
     b2Vec2 vertices[] = {
     b2Vec2(-137.0f/PTM_RATIO,-32.5f/PTM_RATIO),
     b2Vec2(-137.0f /PTM_RATIO,36.5f/PTM_RATIO),
     b2Vec2(137.0f /PTM_RATIO,36.5f/PTM_RATIO),
     b2Vec2(136.0f /PTM_RATIO, -32.5f/PTM_RATIO)
     };
     woodShape.Set(vertices, num);



     b2FixtureDef woodShapeDef;
     woodShapeDef.shape = &woodShape;
     woodShapeDef.density = 1.0f;
     woodShapeDef.friction = 1.0f;
     woodShapeDef.restitution = 0.5f;
     woodBodyDef.userData = _wood;
     _body = _world->CreateBody(&woodBodyDef);
4

1 回答 1

0

我最好的猜测是顶点的顺序很重要。您按顺时针顺序定义它们,Box2D 可能希望它们按逆时针顺序排列。这很容易验证,所以只需尝试一下,看看是否修复了断言(顺便说一句,多边形区域 <= 0)。

于 2013-02-04T21:10:32.927 回答