I'm trying to get into Farseer and XNA. Before I do any real graphics, I want to use the Farseer debug view only. The problem ist, that I don't really know which matrix to use and the other thing is that my objects look "squeezed". But in detail:
this.oGraphicsMgr.SupportedOrientations = DisplayOrientation.Portrait;
this.oGraphicsMgr.IsFullScreen = false;
this.oGraphicsMgr.PreferredBackBufferWidth = 640;
this.oGraphicsMgr.PreferredBackBufferHeight = 960;
this.oGraphicsMgr.ApplyChanges();
this.oWorld = new World( Vector2.Zero );
My gaming field is 640x960 screen units (pixels).
The setup of the debug view:
this.oDebugView = new DebugViewXNA( this.oWorld )
{
DefaultShapeColor = Color.Red,
SleepingShapeColor = Color.Pink,
StaticShapeColor = Color.Yellow,
};
this.oDebugView.LoadContent( this.GraphicsDevice, this.Content );
this.oDebugView.AppendFlags( DebugViewFlags.Shape );
this.oDebugView.AppendFlags( DebugViewFlags.DebugPanel );
this.oDebugView.AppendFlags( DebugViewFlags.PolygonPoints );
this.oDebugView.AppendFlags( DebugViewFlags.CenterOfMass );
this.oDebugView.AppendFlags( DebugViewFlags.Controllers );
I create a circular body and place it in the middle of the screen. "Puck" inherits from Body.
public Puck(World oWorld) : base( oWorld )
{
FixtureFactory.AttachCircle( 0.1, 1f, this );
this.Restitution = RESTITUTION;
this.BodyType = FarseerPhysics.Dynamics.BodyType.Dynamic;
}
My game's draw method:
protected override void Draw( GameTime oGameTime )
{
GraphicsDevice.Clear( Color.CornflowerBlue );
Matrix oProj = Matrix.Identity;
this.oDebugView.RenderDebugData( ref oProj );
base.Draw( oGameTime );
}
The output is a window that is 640x960 pixels. In the middle I can see what is supposingly a circle but it is drawn elliptical: twice as high as it is wide.
- It will only be shown as a circle if my game field's width and height are equal. As soon as they differ, the debug view draws all objects stretched using the ratio of width to height. Why? How to avoid?
- I'm not using a camera. After long trying I figured out that Matrix.Identity is the only projection matrix that will actually make the debug view draw everything in the correct size. But to my understanding it should instead be a scaled matrix, transforming my physic units into screen units.
- I want my gaming field to be 3x2 meters and the puck 0.2m diameter. Therefore I will have to define a scale factor from sim units to screen units. But nowhere can I see that the debug view would require this. How can it possibly know how big a shape has to be drawn?