Question

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);
Was it helpful?

Solution

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);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top