c++ - Box2D: Triangle causing "Polygon is degenerate" -


i porting small game engine linux ubuntu 14.04.4. works great, have encountered problem box2d. use poly2tri triangulate shapes. library returns counter-clockwise triangles, create box2d fixtures with.

some triangles work, @ least 1 not, 1 example:

p1: (-0.135156, -0.042188) p2: (-0.136719, -0.050000) p3: (-0.131250, -0.053125) 

as can see, triangle counter-clockwise. when box2d attempts create shape these vertices using polygonshape->set(), polygon 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. 

i wondering why this? after doing research, have found polygons have counter-clockwise , not tiny (coords have greater 0.00001 or something), triangle respects both constraints. also, it worked fine on windows!

it interesting note seems assert can thrown if box2d's convex hull algorithm breaks on polygon (or i've heard).

box2d versions:

  • on ubuntu: 2.3.0+ds-2
  • on windows: 2.3.0

according the source i've found, b2polygonshape::set() gluing vertices close each other. close means square distance less half of b2_linearslop defined default 0.005f.

which means distance less sqrt(0.005f / 2), 0.05. case, , may want redefine b2_linearslop smaller, or scale coordinates of points.

note: math vertex gluing varies 1 box2d version another, making sure vertices farther 0.05f seems safe.


Comments

Popular posts from this blog

java - nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet Hibernate+SpringMVC -

sql - Postgresql tables exists, but getting "relation does not exist" when querying -

asp.net mvc - breakpoint on javascript in CSHTML? -