I'm new to farseer and I've been experimenting a bit with the texture to polygon tools. I have some questions I was hoping to get help with.
Here's a view of the texture and the generated polygon (enlarged to make it easier to see):
//Build polygon for texture
uint data = new uint[texture2d.Width*texture2d.Height];
Vertices verts = PolygonTools.CreatePolygon(data, texture2d.Width, texture2d.Height);
//translate and scale polygon to screen
Vector2 origin = new Vector2(-texture2d.Width / 2, -texture2d.Height / 2);
Vector2 scale = new Vector2(1, -1);
scale = Vector2.Transform(scale, game.worldparams.PixelToMeterMatrix);
List<Vertices> list = EarclipDecomposer.ConvexPartition(verts);
//remove empty vertices
for (int i = 0; i < list.Count; i++)
if (list[i].Count == 0)
List<Fixture> compound = FixtureFactory.CreateCompoundPolygon(game.fs_world, list, 1);
fs_body = compound.Body;
fs_fixture = compound;
A few of the questions I have are:
1) Is it unusual to have so many polygons for a simple texture? Is there any sort of performance penalty that comes with having a body represented by more polygons?
2) I added some code to apply a force to the texture, and I noticed there's a slight rotation that is getting applied over time. This rotation does not happen if I use a rectangular body created by BodyFactory. Is this because the generated polygons are
not perfectly symmetrical?
Vector2 impulse = new Vector2(0, 3);
Matrix rotation = Matrix.CreateRotationZ(playerobj.Fs_body.Rotation);
impulse = Vector2.Transform(impulse, rotation);
Thanks for any help!