Box2D(C ++)三角形失效区域断言

时间:2017-07-10 06:50:14

标签: c++ box2d polygon shape vertex

我正在使用以下代码在Box2D(C ++)中创建一个三角形多边形:

b2FixtureDef fixtureDef;
b2PolygonShape dynamicPolygon;
b2Vec2 vertices[3];
vertices[0].Set(0, -1);
vertices[1].Set(-1, 1);
vertices[2].Set(1, 1);
dynamicPolygon.Set(vertices, 3);
fixtureDef.shape = &dynamicPolygon;

但是,运行此代码后,我收到此错误:

a.out: ./Box2D/Collision/Shapes/b2PolygonShape.cpp:127: b2Vec2 ComputeCentroid(const b2Vec2*, int32): Assertion `area > 1.19209289550781250000e-7F' failed.

该区域似乎太小,但是这些点应该是一个正确的三角形?

有什么想法吗?

1 个答案:

答案 0 :(得分:0)

我需要交换顶点1和2的值:

b2FixtureDef fixtureDef;
b2PolygonShape dynamicPolygon;
b2Vec2 vertices[3];
vertices[0].Set(0, -1);
vertices[1].Set(1, 1);
vertices[2].Set(-1, 1);
dynamicPolygon.Set(vertices, 3);
fixtureDef.shape = &dynamicPolygon;

此选项按逆时针顺序放置顶点...