This project is read-only.

Importing polygons into Box2d.xna

Mar 9, 2010 at 1:15 AM

Hi,

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 4: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.

-Brandon

Mar 9, 2010 at 5:45 PM

Ok, thanks!

Mar 19, 2010 at 6: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 11, 2010 at 12:40 AM

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