This project has moved. For the latest updates, please go here.

How to Find Vertices that make up the Shape

Topics: User Forum
Jul 31, 2012 at 3:30 AM

Could someone please advise me how to find the vertices that make up the shape object. I would like to find one of these vertices and use as the location where I launch my bullets.

I assume using a helper method, I can convert this local vertex to World Point.

Aug 7, 2012 at 2:26 AM

You can use Body.GetTransform() to get the transformations that have been applied to the body, and then apply those transformations to the vertices. Like this:

private Vector2[] _tempVertices = new Vector2[Settings.MaxPolygonVertices];
private bool Rectangle_OnCollision(Fixture fixtureA, Fixture fixtureB, Contact contact)
	PolygonShape shape = (PolygonShape)fixtureA.Shape;
	Transform xf;
	fixtureA.Body.GetTransform(out xf);
	for (int i = 0; i < shape.Vertices.Count; ++i)
		//Transform them from local to world coordinates
		_tempVertices[i] = MathUtils.Multiply(ref xf, shape.Vertices[i]);

	return true;
_tempVertices will then contain the world coordinates that you can draw directly to the screen.