Polygon Shape error

Aug 7, 2011 at 5:04 PM

Hi, is this my fault?

Vector2[] Vectors=new Vector2[4];

Vectors[0] = new Vector2(0, 0);
Vectors[1] = new Vector2(Size.X, 0);
Vectors[2] = new Vector2(0, Size.Y);
Vectors[3] = new Vector2(Size.X, Size.Y);

Vertices v = new Vertices(Vectors);
PolygonShape myshape = new PolygonShape(v,1);

I got this Error:
http://dl.dropbox.com/u/32013158/pictures/errorscreen01.jpeg

Aug 8, 2011 at 12:51 AM

Your error is coming from the constructor so my question would be were is this initialization happening ?

Aug 8, 2011 at 1:16 PM

What's wrong with the constructor? The code is in the constructor of the main game class. 

Developer
Aug 8, 2011 at 1:45 PM

Short answer to your question: Yes, it is your fault.

Long answer (assuming you wanted to create a rectangle): Farseer loves convex, non-selfintersecting polygons. Since a picture says more than a thousand words...

Left: This makes Farseer very happy... Right: This is what you provided :(

Also you might want to take a look at:

Body myBody = BodyFactory.CreateRectangle(...);
Should the right side of the picture show your expected result, you'll need to attach two triangle fixtures to your body.

Aug 8, 2011 at 2:19 PM

I used the Polygon shape because the tutorial: http://farseerphysics.codeplex.com/documentation uses also a fixture. Do you know a good tutorial?

But now: THANK YOU!

Developer
Aug 8, 2011 at 2:22 PM

I don't know about any documentation, which is up to date. It is always a good idea to have a look at the Box2D docs. The next step would be taking a look at our samples. Most of the time they try to use all the latest features of Farseer.