Importing polygons into Box2d.xna

Mar 9, 2010 at 12:15 AM


If you could help me with this issue it would be great!

I'm switching from Farseer to Box2d.xna because of performance issues. Since this engine is limited to 8 vertexes per polygon, is there a way to section the vertexes of a complex polygon into several 8-vertex polygons? I'm trying to read the polygon definition from a file where I wrote the vertexes, but I keep getting a warning of a negative area at PolygonShape.cs, line 155.

Thanks in advance.

Mar 9, 2010 at 3:15 PM

You are correct that box2d only supports 8 vertices per polygon.  The way you represent higher vertex polygons is by using multiple shapes.  To turn an arbitrary polygon into a simpler polygon you'll need to implement some form of tesselation.  Ear clipping is a relatively straitforward way to do this.  It will give you triangles, which you can then attempt to combine into sets of shapes with <= 8 vertices.


Mar 9, 2010 at 4:45 PM

Ok, thanks!

Mar 19, 2010 at 5:58 PM

I wrote a helper class to load a triangle list from a complex polygon using the algorithm you mentioned. If someone is interested in using it go here.

Apr 10, 2010 at 11:40 PM

The latest release of Farseer physics has 2 polygon decomposition algorithms that can easily be ported over to Box2d.XNA.