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

Drawing/transforming PolygonShape vertices for drawing

Mar 22, 2011 at 6:23 AM
Edited Mar 22, 2011 at 6:25 AM

I have a simple rectangle PolygonShape.  I want to draw it in XNA using a LineList, for example.  The problem is that the vertices stored in the PolygonShape object are untransformed.  Now, it appears that I can get the transform of a Body, which theoretically I can apply to each of the vertices to use for drawing my LineList.  But unfortunately this Transform isn't a Matrix, so I can't simply use Vector2.Transform.  Before I start reverse engineering the FarseerPhysics.Common.Transform class, is there an easy way to accomplish what I want?  I assume there must be, as physics objects are pretty useless if you can't draw them properly on screen. :)

Mar 22, 2011 at 8:46 AM

What you are looking for is probably body.position and body.rotation. Either you pass that to Matrix.CreateTranslation/Rotation or you could alternatively use MathUtils.Multiply in FarseerPhysics.Common.MathUtils. Have a look at the DrawShape method in the debug view for further reference.

Mar 23, 2011 at 4:52 AM

Thanks, it's simpler than I feared. :)