How can I create triangles?

Topics: User Forum
May 17, 2013 at 3:19 PM
How can I create triangles in Farseer? I have no clue how to do that.
May 20, 2013 at 7:53 AM
I used pyramids in one game, but I'm sure you could adapt this to more generic triangles.

So I have a create pyramid method:
private static Vertices CreateSimplePyramid(float width, float height)
{
    Vertices vertices = new Vertices();
    vertices.Add(new Vector2(0f, -height * .5f));
    vertices.Add(new Vector2(-width * .5f, height * .5f));
    vertices.Add(new Vector2(width * .5f, height * .5f));
    return vertices;
}
Then I create my pyramid as you would normally in Farseer, so code something like:
_body = BodyFactory.CreateBody(_world, ConvertUnits.ToSimUnits(_position), this);
Vertices vertices = CreateSimplePyramid(ConvertUnits.ToSimUnits(bDef.blockWidth), ConvertUnits.ToSimUnits(bDef.blockHeight));
vertices.ForceCounterClockWise();
_shape = new PolygonShape(vertices, density);
_fixture = _body.CreateFixture(_shape);
... etc
Maybe also of use, I remember Farseer has some "decomposer" routines that will split larger shapes into triangles, that was either in the samples or there was a class like eg EarclipDecomposer.