This project has moved. For the latest updates, please go here.

Vertices question 3.2

Topics: Developer Forum, User Forum
Jul 27, 2011 at 5:33 PM

      I seem to be having a problem when i define a new fixture with a set of Vertices. Could someone please tell me how i should be doing this?


The Vertices are defined like this:

           #region Verts
            Vertices verts = new Vertices(22);
            verts.Add(ConvertUnits.ToSimUnits(new Vector2(28, 0)));
            verts.Add(ConvertUnits.ToSimUnits(new Vector2(34, 0)));
            verts.Add(ConvertUnits.ToSimUnits(new Vector2(49, 6)));
            verts.Add(ConvertUnits.ToSimUnits(new Vector2(60, 20)));
            verts.Add(ConvertUnits.ToSimUnits(new Vector2(58, 34)));
            verts.Add(ConvertUnits.ToSimUnits(new Vector2(52, 34)));
            verts.Add(ConvertUnits.ToSimUnits(new Vector2(54, 44)));
            verts.Add(ConvertUnits.ToSimUnits(new Vector2(51, 57)));
            verts.Add(ConvertUnits.ToSimUnits(new Vector2(41, 66)));
            verts.Add(ConvertUnits.ToSimUnits(new Vector2(32, 70)));
            verts.Add(ConvertUnits.ToSimUnits(new Vector2(31, 88)));
            verts.Add(ConvertUnits.ToSimUnits(new Vector2(23, 88)));
            verts.Add(ConvertUnits.ToSimUnits(new Vector2(10, 82)));
            verts.Add(ConvertUnits.ToSimUnits(new Vector2(2, 72)));
            verts.Add(ConvertUnits.ToSimUnits(new Vector2(0, 67)));
            verts.Add(ConvertUnits.ToSimUnits(new Vector2(1, 54)));
            verts.Add(ConvertUnits.ToSimUnits(new Vector2(6, 54)));
            verts.Add(ConvertUnits.ToSimUnits(new Vector2(5, 50)));
            verts.Add(ConvertUnits.ToSimUnits(new Vector2(5, 39)));
            verts.Add(ConvertUnits.ToSimUnits(new Vector2(12, 27)));
            verts.Add(ConvertUnits.ToSimUnits(new Vector2(20, 21)));
            verts.Add(ConvertUnits.ToSimUnits(new Vector2(28, 19)));

            circleFixture = FixtureFactory.CreatePolygon(, verts, 0.1f);


But then i get an Error from class PolygonShape:

        public void Set(Vertices vertices)
            Debug.Assert(vertices.Count >= 2 && vertices.Count <= Settings.MaxPolygonVertices); /// Here an error is thrown because the MaxPolygonVertcies value is only 8. Surely it is possible to define fixture's with more than 8 Vertices?


Thanks in advance

Jul 27, 2011 at 8:29 PM

You need to decompose your polygons into smaller fixtures like this. See the documentation for an explanation of the different decomposition algorithms.

List<Vertices> polygons = EarclipDecomposer.ConvexPartition(verts);
FixtureFactory.AttachCompoundPolygon(polygons, density, body);

Jul 27, 2011 at 8:58 PM

Change this line in settings.cs to any other number you want.

public static int MaxPolygonVertices = 8;

Jul 27, 2011 at 10:26 PM

Ah thank you both, although i decided to go with zazery's idea in the end, as it seems more commonly used, there is probably a good reason for the max polygon vertices being set to 8?

Jul 28, 2011 at 10:01 AM

I think the reason may be performance, or maybe to avoid creating complex convex polygons. However, I gave you the "easy way" in case you are in a hurry and have various bodies created in this way, but obviously the zazery's answer is the way to go if you can.