Box2D libgdx多边形形状

时间:2014-11-23 17:56:48

标签: libgdx box2d

为什么这样可行:

Vector2[] vertexArray = new Vector2[3];
vertexArray[0] = new Vector2(0f, 0f);
vertexArray[1] = new Vector2(1f, 1f);
vertexArray[2] = new Vector2(2f, 5f);

polygonShape.set(vertexArray);

这会产生运行时错误

Vector2[] vertexArray = new Vector2[3];
vertexArray[0] = new Vector2(0f, 0f);
vertexArray[1] = new Vector2(1f, 1f);
vertexArray[2] = new Vector2(2f, 2f);

polygonShape.set(vertexArray);

错误:

AL lib: (EE) alc_cleanup: 1 device not closed
Assertion failed!

Program: C:\Program Files\Java\jre1.8.0_25\bin\javaw.exe
File: /var/lib/jenkins/workspace/libgdx/extensions/gdx-box2d/gdx-box2d/jni/Box2D/Collision/Shapes/b2PolygonShape.cpp, Line 223

Expression: false

没有任何意义。第一个代码工作正常,绘制三角形,但第二个代码没有。有人可以解释我做错了什么......

1 个答案:

答案 0 :(得分:3)

顶点(0,0),(1,1),(2,2)都是直线 - 它们不是多边形。这会导致断言触发,如错误消息(b2PolygonShape.cpp,第223行)所示