Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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.

  1. 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?
  2. 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.
  3. 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?
share|improve this question

1 Answer 1

up vote 2 down vote accepted

Here is my code for drawing Farseer debug objects. They line up perfectly with my real world objects. I had to play around with it for a long time before I got it to draw just right. This may be of use to you.

Matrix proj = Matrix.CreateOrthographicOffCenter(0f, Viewport.Width, Viewport.Height, 0f, 0f, 1f);
Matrix view2 = Matrix.CreateScale(32);
view2 *= view;
_worldDebug.RenderDebugData(ref proj, ref view2);

The "view" above, is the matrix used when drawing everything else.

share|improve this answer
    
I'm comfortable using a view matrix within a 2d game as it is used to transform all of the items rendered by the spritebatch. I do find the projection matrix confusing though, because when I think of a projection matrix I think of camera options such as FOV. What purpose does splitting the matrix used as the spritebatch transformation into view and projection serve? –  ClassicThunder Feb 13 '12 at 4:59
    
Maybe you should make that a separate question and link it from here. I would be interested in that too. –  Krumelur Feb 13 '12 at 8:48
    
jan, are you using a camera in your project? –  Krumelur Feb 13 '12 at 8:49
    
@ClassicThunder the XNA pipeline really wants you to use a projection matrix - even if it's 2D. A matrix created with those specific parameters basically means 'pre-transformed'. Remember your graphics card works in [0...1] for screen space - where you are working on [0...Axis Size], so you need to transform your vertices to that. Yes, a simple scale might work (but you will still call it projection) - but I stand to be corrected there. –  Jonathan Dickinson Feb 13 '12 at 9:38
    
I tried your solution. The circle is now drawn in the top left corner, so I only see a quearter of it. But at least it is circular! What is "CreateOrthographicOffCenter" actually doing? And why do I need a projection AND a view? Is there a good place that explains all this business? –  Krumelur Feb 13 '12 at 19:32

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.