Geometry Offset Problem

Topics: User Forum
Jan 31, 2009 at 12:57 AM
Hello,

I am having a problem getting Farseer to work correctly  (running 2.0.1 for Silverlight).  What I'm seeing is this:



The magenta lines/dots are a mapping of the Geom vertices.  The orange rectangles just represent the related sprite.  In both of these cases, the geometries are colliding and pushing against each other.  But as you can see, the geometry is somehow offset.  On the left, there is a gap between them.  On the right, they are overlapping.  Both the geometry and the body is created using the same vertex points, a set as follows:
            Vertices vbox = new Vertices();
            vbox.Add(new Vector2(-20, -40));
            vbox.Add(new Vector2(-20, 40));
            vbox.Add(new Vector2(20, 40));
            //vbox.Add(new Vector2(20, -40));
            vbox.Add(new Vector2(-20, -40));
When I uncomment the line above (making the geometry a rectangle) the collisions work perfectly. What am I missing?
Coordinator
Jan 31, 2009 at 1:05 AM
Do you have a sample I can take a look at?

When you define your vertices for a rectangle, they need to be relative to 0 and have a counterclockwise order.
You also need to add some vertices along the sides. From what I can see, you are doing all of them but the counterclock wise order. That is not a big deal because Farseer detects it and reverses their order.

The problem must be somewhere else, so I would like to look at a sample.
You are welcome to pack it up and send it to me. You can use an upload service and send the link to me or send a mail to me and I will reply with my email.