# How to go orthographic instead of perspective view in XNA with CreateOrthographicOffCenter?

Using these view and projection values:

var eye = new Vector3(0, 0, 10f);
var view = Matrix.CreateLookAt(eye, Vector3.Zero, Vector3.Up);
var projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.PiOver4, GraphicsDevice.Viewport.AspectRatio, 1.0f, 1000f);


and then applying world rotation to the effects with this matrix:

var rotation = Matrix.CreateRotationX(-MathHelper.PiOver2)*Matrix.CreateRotationY(MathHelper.PiOver2);


I am able to render my animated model:

But simply changing projection matrix to something like this:

var projection = Matrix.CreateOrthographicOffCenter(0, GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height, 0, 1.0f, 1000.0f);


Renders pure CornBlue screen. I don’t see my model at all. What should I do to make it visible?

## 1 Answer

To summarize, you probably want to use the CreateOrthographic method instead:

var projection = Matrix.CreateOrthographic(GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height, 1.0f, 1000.0f);


Or if you still wanted to use CreateOrthographicOffCenter, change to the following values instead:

var projection = Matrix.CreateOrthographicOffCenter(-GraphicsDevice.Viewport.Width/2f, GraphicsDevice.Viewport.Width/2f, -GraphicsDevice.Viewport.Height/2f, GraphicsDevice.Viewport.Height/2f, 1, 10000);


If I remember correctly CreateOrthographicOffCenter maps the view space origin to the top-left corner of your viewport, and it also inverts the Y axis so that it increases donwards. This is ideal for 2D stuff, just like using the SpriteBatch class

(Edit) With CreateOrthographicOffCenter you specify the left/right/top/bottom/far/near extents of the viewable area directly. The order in which you specify these parameters also dictate the direction of the corresponding axes. E.g. it is frequent for 2D games to invert the Y axis so that it points downards.

Since you were specifying a top/left value of 0, the viewing space origin was being mapped to the top left corner of the screen instead of the center of the screen as you probably intended. And the order in which you specified the bottom/top parameters also inverted the Y-axis which would make the model appear rendered upside down.

On the other hand CreateOrhographic maps the view space origin into the middle of your viewport which is probably what you wanted to do.

So I believe you're just not seeing the model because its position lies outside the viewport after being projected. Just switch to the other function and it should start working (as long as your model is within viewing range).

For reference, here's what I got when I used the same scene and only changed the projection between each screenshot (with values similar to the OP):

• Your explanation of CreateOrthographicOffCenter is incorrect. It can do everything CreateOrthographic can, if you pass in the right values. – Andrew Russell Dec 13 '11 at 5:28
• Thanks for the warning. I've just rechecked the documentation and saw that my description is only accurate for this particular usage (left=0, right=width, bottom=height, top=0). I'll try to review my explanation. – David Gouveia Dec 13 '11 at 5:36