Search code examples
c#xnaphysicsgame-physicsfarseer

Farseer 3.3 DebugViewXNA - Hooking it up


I have been trialling farseer 3.3 in XNA. For the life of me I cannot get DebugViewXNA to work.

I have a World object with a couple of bodies in there. The bodies are fixed to polygonal models, so I need the debugviewXNA class to draw these for me but cant find how to do it. I assume I need to pass it the vertices but cannot find how to access these from the World object nor do I understand which method to call exactly. One of the issues I find with farseer 3.3 is the support seems limited to "look at the examples" but they just dont seem to show the answers, google tells me I am not the only one feeling this way.

Any help from those more experienced would be very much appreciated!

Thanks in advance


Solution

  • You shouldn't need to pass DebugViewXNA any vertices - it grabs that info from the Fixtures attached to the Bodies in the World. Here's how I got it working:

    physicsWorld = new World(GRAVITY);
    physicsDebug = new DebugViewXNA(physicsWorld);
    physicsDebug.LoadContent(this.GraphicsDevice, this.Content);
    physicsDebug.AppendFlags(DebugViewFlags.Shape);
    physicsDebug.AppendFlags(DebugViewFlags.PolygonPoints);
    

    And later on for drawing:

    Matrix proj = Matrix.CreateOrthographicOffCenter(0f, GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height, 0f, 0f, 1f);
    Matrix view = camera.GetViewMatrix(Vector2.One);
    physicsDebug.RenderDebugData(ref proj, ref view);