2
votes

I've been working on a game project for Windows for a while now. I used to have a static 1600 x 900 resolution, which worked fine for me. But not so much for some of my beta testers.

This got me looking into resolution independence in XNA-based games. I've gone through a lot of the Virtual Resolution systems that draw everything on a RenderTarget2D and stretch that to fit the window size. But that doesn't work for me.

What I want to know is how I could calculate a similar projection matrix as to what Terraria uses. For those who don't know how it works in terraria (now days anyway, I think it used to be different) is that once you resize the game window, you see more stuff on the screen.

Currently my projection matrix is defined as such:

            Projection = Matrix.CreateOrthographicOffCenter(-25 * _graphics.Viewport.AspectRatio, 
            25 * _graphics.Viewport.AspectRatio,
            -25, 25,
            -1, 1 );

This works when the window's size changes horizontally. I see more stuff sideways and everything is fine. But once I resize the window vertically, everything clamps together.

Is there a way to calculate the projection matrix so that it'd allow me to resize the window both horizontally and vertically?

EDIT:

I am using a camera class indirectly. Everything is in Farseer Physics coordinate space, and when something is getting drawn to the screen, its converted via Viewport.Unproject().

SOLUTION:

As gareththegeek pointed out in the comment section of the chosen answer, my particular projection matrix I was after is formed like this:

 Projection = Matrix.CreateOrthographicOffCenter(-(_graphics.Viewport.Width / 1600f * 44),
        (_graphics.Viewport.Width / 1600f * 44),
        -(_graphics.Viewport.Height / 900f * 25), (_graphics.Viewport.Height / 900f * 25),
        -1, 1);
1
Why not just call the bit of code you have above every time the window re-sizes?ClassicThunder
I do that, in the Window.ClientSizeChanged event, but as said above, it works only when resizing the window horizontally, and breaks horribly when doing so vertically.aRkker

1 Answers

1
votes

If you include the resolution of the display in the orthographic projection you can achieve the desired effect I think.

Projection = Matrix.CreateOrthographicOffCenter(
    0.0f, _graphics.Viewport.Width,
    _graphics.Viewport.Height, 0.0f,
    -1.0f, 1.0f);