CreatePolygon with Many Vertices (FP3)

Aug 26, 2010 at 12:58 PM

I am upgrading from FP2 to FP3, and am trying to create a large polygon with lots of vertices using FixtureFactory.CreatePolygon.

The first thing I noticed is that Settings.MaxPolygonVertices is set low (8 by default). So I upped that to a bigger number.

But now it doesn't seem to like my Vertices list I send into CreatePolygon - it fails on the Assert where it checks for "Non-Convex (has an indentation) or colinear edges."

Is there a better way to create a large Polygon in FP3, and how do I send in Vertices? (In FP2, Vertices were offset from 0,0 at center of the body, is that still the case in FP3?)

Thanks!!
-Andy

Coordinator
Aug 26, 2010 at 1:56 PM
Edited Aug 26, 2010 at 2:04 PM

Andy, is this a static polygon?

Box2D and therefore FP3 does not support concave polygon rigid bodies.  You can, however, create "polygons" with only 2 points so you could just create a large concave polygon by stringing together a bunch of 2 point polygons.  One for each "edge" of your polygon.

If you are trying to create landscape type polygon, then I'd recommend using "EdgeShapes".  See the edgeshape demo on the FP3 demo project.  This will allow you to string together single edge polygons like mentioned above, but it will also handle collision more accurately at the seams.

The best way to get familiar with FPE, are the demos that come with the download and the Box2D documentation: http://box2d.org/manual.html

Hope this helps.

Aug 26, 2010 at 3:05 PM

These might not be static.

What I'm trying to do is convert the Physics Helper Library stuff to FP3. In the library, I treat everything as a Polygon, whether it is static or not, and there is an algorithm which traces the outline of the XAML or Image elements.

So I guess I'm looking for a generic type Polygon that would fit this bill - it could be terrain or an element in the game.

Maybe Edge Shapes are the way to go with this, I'll give it a go.

Coordinator
Aug 26, 2010 at 3:36 PM
Edited Aug 26, 2010 at 3:38 PM

Well Box2D uses SAT for it's polygon collision so it can't do Concave polygons collision like the distance grid collisions in FPE2.

One thing you might look at are the algorithms for decomposing a Concave polygon into multiple Convex polys. I think there are some algos in FPE3 for doing this although I have not used them.  I think this is going to give you the most accurate simulation for dynamic polygons because you should be able to get the mass properties correct.  You would create a single body, then add a fixture/shape for each convex polygon the decomposer gives you.  Together, these fixture/shapes would make up your concave polygon.

If you use just edges, the mass properties of the final overall "polygon" might not be as realistic. (not sure as I have not tried this.)

If  your polygon is static then definelty use the edge shapes or just multiple single edge polys like I mentioned previously.

 

-Jeff Weber

Aug 30, 2010 at 6:26 PM
crashlander wrote:

trying to create landscape type polygon, then I'd recommend using "EdgeShapes".  See the edgeshape demo on the FP3 demo project.  This will allow you to string together single edge polygons like mentioned above, but it will also handle collision more accurately at the seams.

 

 Hi Crashland - where can I find the edgeshape demo? can't find it in the fp3 samples.. Thank you!!