Sub Divide Edges FP 3.0

Dec 21, 2010 at 6:57 AM


I'm trying to make a 2D World with a image as ground, the image got special features so, I thought of using Vertices to create my fixture.

So far so good, but the problems come when I try to drop stuff on the terrain and they just fal throught, but then gets stopped, and continues. (It looks kinda weird)

So I thought of Sub dividing the edges, just like in FP 2.1 but I cann't find the function.

Please help! (I'm using an version of Farseer which I downloaded from source code reprostory just a couple of days ago)

Dec 21, 2010 at 7:43 AM

In Farseer 3.x there is no need anymore to subdivide edges. The only thing you would achieve by subdividing edges is a little performance loss. As the rest of your description is pretty vague some more details regarding your setup could help.

The usual suspects would be:

Units not tuned to MKS system or maybe bodys moved by hand after they have been added to the world, which can cause some weird behaviour.

Dec 21, 2010 at 11:34 AM

This behavior can also happen when you add concave shapes to the world. This would imply you run in release mode to bypass all asserts.

Dec 21, 2010 at 12:35 PM
        public void CreateScenery(string texturefile, out Texture2D texture, out Fixture fixture, float density, BodyType body, Vector2 position)
            texture = Content.Load<Texture2D>(texturefile);
            uint[] data = new uint[texture.Width * texture.Height];

            Vertices verts = PolygonTools.CreatePolygon(data, texture.Width, texture.Height);
            fixture = FixtureFactory.CreatePolygon(World, verts, density);
            fixture.Body.Position = position;
            fixture.Body.BodyType = body;

I'm using this function to create my objects


Dec 21, 2010 at 2:13 PM
Edited Dec 21, 2010 at 2:14 PM

Ok there are several steps missing to make this work. I'd suggest you have a look at the Demo1Screen.cs of the Advanced Samples in the latest source, as it features exactly the source code you need in its LoadContent() method.

In short:

You need to scale all your units from pixel based to MKS based. (i.e. meters kilos seconds) -> There are dozens of discussions going on here if you are interested in the how and why in more detail ;)

You need to partition your polygon into convex polygons and make sure they are counterclockwise and have no more than 8 vertices.

You therefore probably need to return more than one fixture, so returning the body all the fixtures are attached to might be better.