This project has moved and is read-only. For the latest updates, please go here.

Vertices -> BodyFactor.CreatePolygon trouble

Sep 30, 2011 at 4:54 AM
Edited Sep 30, 2011 at 5:52 AM


I'm having trouble with the creating custom polygons with programatically defined points.

I've modified SimpleDemo1.LoadContent to include this code:


World.Gravity = new Vector2(0, 19.8f);
Vertices verts=new Vertices();
verts.Add(new Vector2(30, 30)); verts.Add(new Vector2(50, 50)); verts.Add(new Vector2(20, 50));

_rectangle = BodyFactory.CreatePolygon(World, x, 1);
_rectangle.BodyType = BodyType.Dynamic;

The Sprite is drawn, and falls below the screen (without colliding with the Border).

This is... odd. The body should exist, since 1) Gravity affects it,and 2) The sprite is drawn from the Body's fixture.

However, 1) F1 Debug suggests it does not exist.  2) It does not collide with the border.

Also, for different vales of Vector2s, it fails to create the Polygon.


What is the correct way to use BodyFactory.CreatePolygon? Why do different Vector2s fail (is this a counterclockwise problem?)?



So I've been experimenting a bit. Apprently, BodyFactory.CreatePolygon assumes that the average Vertices are (0,0).

What seems to be a solution is to translate the Vertices by its Centroid (which ALMOST aligns the Vertices), and then translate the Body.Position to put the Body where it belongs.

Sep 30, 2011 at 8:55 PM
Edited Sep 30, 2011 at 8:55 PM

You have to use the Braizer decomposer. Look for it to find how to use it correctly. It'll fix the problem you are experiencing.