• Advertisement
Sign in to follow this  

Orthographic projection

This topic is 3967 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello, I'm trying to make an orthographic projection to render (stupid) squares seen from a top-down point of view. All my objects have a Z value between 0 and 1 and I wish to have the left top corner of the screen as the (0, 0) origin. Therefore I've set up my view matrix as: ::D3DXMATRIX viewMatrix; const ::D3DXVECTOR3 cameraPos(0.0f, 0.0f, 2.0f); const ::D3DXVECTOR3 cameraLookAtPos(0.0f, 0.0f, 1.0f); const ::D3DXVECTOR3 upDirection(0.0f, -1.0f, 0.0f); ::D3DXMatrixLookAtLH(&viewMatrix, &cameraPos, &cameraLookAtPos, &upDirection); m_dxDevice->m_direct3DDevice9->SetTransform(D3DTS_VIEW, &viewMatrix); which seem to do the job as if I then put a perspective projection as: ::D3DXMATRIX projectionMatrix; float aspect = (float) windowSize.getX() / windowSize.getY(); ::D3DXMatrixPerspectiveFovLH( &projectionMatrix, D3DX_PI/4, aspect, -1.0f, 1.0f); m_dxDevice->m_direct3DDevice9->SetTransform(D3DTS_PROJECTION, &projectionMatrix); a square running from (0, 0) to (windowSize.getX(), windowSize.getY()) shows up with the corner right on the middle of the screen. Now my problem is to replace such a perspective projection with an ortho one. As I want the left top corner of the window to be the (0,0) origin I've attempted ::D3DXMATRIX projectionMatrix; ::D3DXMatrixOrthoOffCenterLH(&projectionMatrix, 0, getAppSize().getX(), getAppSize().getY(), -1.0f, 1.0f); m_dxDevice->m_direct3DDevice9->SetTransform(D3DTS_PROJECTION, &projectionMatrix); And here the screen keeps black. I wonder if I have understood well the Ortho method. Can anybody hint me to my mistake?

Share this post


Link to post
Share on other sites
Advertisement
I remember a while ago when I was playing around with this I had to fiddle with the sign (-+) of the values to get it in the right corner of the plane. (Unfortunatly I'm at work and don't have access to my old files right now) But your problem (assuming your clearing the screen black), I believe is that your view isn't in the right quadrant.

Ummm. Plus aren't you missing a parameter?

D3DXMatrixOrthoOffCenterLH(&projectionMatrix, 0, getAppSize().getX(),
getAppSize().getY(), 0,
-1.0f, 1.0f);

Share this post


Link to post
Share on other sites
Yep, 0 is missing but that's a copy & paste into forum syndrome. :)
I seem to have finally made the thing work. I simply had to kick
the view matrix out (set view to identity matrix).
0_o

Thanks for the help, it's greatly appreciated.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement