Orthographic projection and resizing

Started by
7 comments, last by Rompa 13 years, 10 months ago
Hi. I have a problem with redrawing my 3D objects after resizing.

First of all, my problems is that when I resize the window, the objects are not drawn with the new settings, meaning they still have the same size like in the original window which leads to some parts not being visible any more.

Second of all, I am currently using orthographic projection. I used before perspective projection and I didn't have this problems because I was setting the device's BackBufferWidth and BackBufferHeight with the new values of the window's width and height. But now, this approach does not work any more.

Does anybody have an idea why this problem appears?


Thank you in advance.

Madalina
Advertisement
Are you changing the projection when the window size changes? Also, can you post the code where you set up the projection?
I am not changing the projection when I resize. I had before an implementation where I was using perspective projection but now I need orthographic projection.
I don't have the code here, but the setting of the projection is like this:

D3DVIEWPORT9 mViewport;

m_p3DDevice->GetViewport(&mViewport);
D3DXMATRIX matOrtho;
D3DXMatrixOrthoLH(&matOrtho, mViewport.Width, mViewport.Height, -1000.0f,1000.0f);
Do you reset the viewport when the window resizes?

In any case, if you don't want the apparent size of the objects to depend on the screen resolution, you probably don't want to be using the screen dimensions for the orthographic projection. Rather, choose a single, fixed resolution (possibly adapted to the window's aspect ratio) and use that for your orthographic projection.
I don't need to reset the viewport because it changes automatically when I change the back buffer width and height of the device leading to the viewport's settings being changed automatically.

But, I did like you said, I've used some fixed values for the width and the height of the orthographic projection matrix. They don't depend on the aspect ration of the window, I just used 1000.0f for the width and 800.0f for the height. And it works. But I don't know why. Could you explain to me why, if you know?
Quote:But, I did like you said, I've used some fixed values for the width and the height of the orthographic projection matrix. They don't depend on the aspect ration of the window, I just used 1000.0f for the width and 800.0f for the height. And it works. But I don't know why. Could you explain to me why, if you know?
Keep in mind that if the aspect ratio of the projection doesn't match that of the screen, your image may be distorted (i.e. stretched or squashed).

As for why it works, it's because (more or less) the orthographic projection is independent of the screen resolution; they're not 'tied together', so to speak. You can use an orthographic projection of, say, 800x600 with *any* resolution for which the aspect ratio is 4:3 (assuming you don't want the image to be distorted), and it'll work fine.

In other words, the parameters of the orthographic projection do not need to match the viewport; rather, you can set up the orthographic projection in any way that makes sense to you. (For example, the projection could extend from -1 to 1 in the x direction and -.75 to .75 in the y direction, even if the screen resolution were, say, 1024x768, and as long as your objects were sized and positioned appropriately, the results would still make sense.)
Quote:Original post by jyk
You can use an orthographic projection of, say, 800x600 with *any* resolution for which the aspect ratio is 4:3 (assuming you don't want the image to be distorted), and it'll work fine.

To make this even clearer. The projection width and height are WORLD SPACE units, not on screen pixels. You choose how much of your world you want visible, and use that.

Typically you'll pick the length of one axis, width or height (depending on which is most critical to your game), and calculate the other axis based on the aspect ratio of the window or screen resolution. If widescreen users shouldn't see extra to the sides, then made the width the fixed size, and calculate the height based on the aspect. If seeing the expected top and bottom is more critical, you'll pick the height, and calculate the width.
Thank you very much to both of you. Now I understand better how orthographic projection works.
Quote:Original post by Namethatnobodyelsetook
The projection width and height are WORLD SPACE units, not on screen pixels.

Actually, to be pedantic, I'm pretty sure the projection width and height are in view (or camera) space units, not world space nor screen pixels. In most cases there won't be a scale on the view transform, making them equivalent but I thought it important to clarify. Its also very important to understand that the viewport transform is for all intents and purposes independant from the projection transform. If you "visualise" the MVP composite matrix as a sequence of coordinate system transforms such as Model->World->View->Projection then you can see that the Projection component transforms "things" from View space.

This topic is closed to new replies.

Advertisement