Box2D:三角形导致 "Polygon is degenerate"
Box2D: Triangle causing "Polygon is degenerate"
我目前正在将一个小型游戏引擎移植到 Linux Ubuntu 14.04.4。一切正常,但我遇到了 Box2D. I use Poly2Tri to triangulate my shapes. This library returns counter-clockwise triangles, which I then create Box2D fixtures with.
的问题
有些三角形有效,但至少有一个无效,例如这个:
P1: (-0.135156, -0.042188)
P2: (-0.136719, -0.050000)
P3: (-0.131250, -0.053125)
如你所见,这个三角形是逆时针方向的。当 Box2D 尝试使用 polygonShape->Set()
创建具有这些顶点的形状时,我得到一个 Polygon is degenerate assert:
/build/buildd/box2d-2.3.0+ds/Box2D/Box2D/Collision/Shapes/b2PolygonShape.cpp:158: void b2PolygonShape::Set(const b2Vec2*, int32): Assertion `false' failed.
我想知道为什么我会得到这个?在做了一些研究之后,我发现多边形必须是逆时针的并且不能太小(坐标必须大于 0.00001 或其他东西),但是我的三角形 遵守两个约束 。此外,它在 Windows!
上运行良好
同样有趣的是,如果 Box2D 的凸包算法在多边形上中断(或者我听说过),似乎可以抛出此断言。
Box2D 版本:
- 在 Ubuntu 上:2.3.0+ds-2
- 在 Windows 上:2.3.0
根据the source that I've found, b2PolygonShape::Set()
is gluing together the vertices that are close to each other. Close means that the square distance is less than half of b2_linearSlop
which is defined by default to 0.005f。
表示距离小于sqrt(0.005f / 2)
,即0.05
。这绝对是你的情况,你可能想将 b2_linearSlop
重新定义为更小的值,或者放大点的坐标。
注意:顶点粘合的数学因不同的 Box2D 版本而异,但确保顶点远于 0.05f
似乎是安全的。
我目前正在将一个小型游戏引擎移植到 Linux Ubuntu 14.04.4。一切正常,但我遇到了 Box2D. I use Poly2Tri to triangulate my shapes. This library returns counter-clockwise triangles, which I then create Box2D fixtures with.
的问题有些三角形有效,但至少有一个无效,例如这个:
P1: (-0.135156, -0.042188)
P2: (-0.136719, -0.050000)
P3: (-0.131250, -0.053125)
如你所见,这个三角形是逆时针方向的。当 Box2D 尝试使用 polygonShape->Set()
创建具有这些顶点的形状时,我得到一个 Polygon is degenerate assert:
/build/buildd/box2d-2.3.0+ds/Box2D/Box2D/Collision/Shapes/b2PolygonShape.cpp:158: void b2PolygonShape::Set(const b2Vec2*, int32): Assertion `false' failed.
我想知道为什么我会得到这个?在做了一些研究之后,我发现多边形必须是逆时针的并且不能太小(坐标必须大于 0.00001 或其他东西),但是我的三角形 遵守两个约束 。此外,它在 Windows!
上运行良好同样有趣的是,如果 Box2D 的凸包算法在多边形上中断(或者我听说过),似乎可以抛出此断言。
Box2D 版本:
- 在 Ubuntu 上:2.3.0+ds-2
- 在 Windows 上:2.3.0
根据the source that I've found, b2PolygonShape::Set()
is gluing together the vertices that are close to each other. Close means that the square distance is less than half of b2_linearSlop
which is defined by default to 0.005f。
表示距离小于sqrt(0.005f / 2)
,即0.05
。这绝对是你的情况,你可能想将 b2_linearSlop
重新定义为更小的值,或者放大点的坐标。
注意:顶点粘合的数学因不同的 Box2D 版本而异,但确保顶点远于 0.05f
似乎是安全的。