2
\$\begingroup\$

As you can understand from the title, I'm pretty new to game development. I'm doing this for fun. Anyway here's my question.

I have this Farseer Physics samples and i've been studying them for a few days. One thing i can't understand is, how the vertices creates the shape? I mean, in the game sample, where you create a shape for your car from vertices, there is a code like this:

Vertices vertices = new Vertices(8);
vertices.Add(new Vector2(-2.6f, 0.10f));
vertices.Add(new Vector2(-2.375f, -0.46f));
vertices.Add(new Vector2(-0.58f, -0.92f));
vertices.Add(new Vector2(0.46f, -0.72f));
vertices.Add(new Vector2(2.7f, -0.07f));
vertices.Add(new Vector2(2.5f, 0.205f));
vertices.Add(new Vector2(2.3f, 0.23f));
vertices.Add(new Vector2(-2.55f, 0.35f));

PolygonShape chassis = new PolygonShape(vertices, 2f);

I understand you create a vertices list and add 8 points(?) to it and then you make a polygonshape from those vertices, a random shape created from your points(?). The thing i can't understand is what are those numbers which inside the Vectors? I mean where in the shape are those? Corners? Edges? or a line between those two floats? Or the line between the corners?

Now lets say I want to make a shape like this

https://i.stack.imgur.com/Ac7Dv.png

What are those vertices for this picture? You can give random numbers thats not a problem, only thing I want to understand is, what are those Vectors on this picture? Thank you very much for your help and time.

\$\endgroup\$

2 Answers 2

0
\$\begingroup\$

Vector2, in this case, represents a position in 2D space. The first number you pass to the constructor is a position along the X-axis, and the second is a position along the Y-axis.

(You can also use Vector2 to represent the relative displacement between two positions, or a direction and a magnitude - as in a velocity.)

The Vertices class from Farseer Physics represents a closed shape. That shape is made of of a list vectors (it derives from List<Vector2>). Vertices interprets its list of vectors as a list of vertices (to use the technical term). That is to say: Vertices is a list of positions that form the corners of a polygon.

Vertices represents a closed shape. So there are implied straight edges between each vertex and the one following it, and between the first and the last vertex.

Furthermore, many parts of Farseer expect shapes to be defined in counter-clockwise order (in standard Cartesian space, with the Y-axis pointing upwards - this differs from Client space, which is used for drawing by SpriteBatch, where the Y axis points down). Fortunately Vertices provides IsCounterClockWise and ForceCounterClockWise to help ensure your shapes are defined in the correct order.

The PolygonShape class is essentially a wrapper Vertices, which allows Farseer to differentiate it from other possible shapes, like CircleShape.

(For context: A Body provides position, rotation, velocity, etc, and has one or more Fixtures. A Fixture provides friction, collision detection, etc, and has a Shape. If that Shape is a PolygonShape, then it will have Vertices.)

\$\endgroup\$
1
  • \$\begingroup\$ Thank you very much for this clear answer. This is exacly what I was looking for. \$\endgroup\$ Mar 2, 2013 at 20:42
1
\$\begingroup\$

Those points describe the perimeter of the polygon. For your random shape those would be

(-10, -10), (10, -10), (-15,10) (15, 10)

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .