Orthogonal projections

Started by
3 comments, last by d000hg 18 years, 9 months ago
To render my GUI, I plan to use an orthogonal projection matrix, instead of just using pre-transformed vertices with the RHW component. However I'm confused and would like a quick (pseudo)code example of how to set this up... Assuming I have an identity world matrix, and I set a view matrix using
D3DXMatrixLookAtLH(&view,(wdith/2,height/2,-1000),(width/2,height/2,0),(0,1,0));
Then what should I enter into the D3DXMatrixOrthLH function? I think I should be specifying the width and height as the size of my viewport/window but I don't know! What I want is to set the view & projection so that a vertex at (0,0,z) is drawn at the bottom-left of the screen, and (1,1,z) at the top right. z<0 so that all GUI items are always in front of the game scene. It must be pretty simple? rating++ for any help, I am too busy to be held up on stupid little things!
Advertisement
Check out the Offcenter version of that function, it should do exactly what you want.
Stay Casual,KenDrunken Hyena
Good point Ken. But I still don't get what values to use for the left,right, top & bottom values? How about:
left=0
bottom=0
right=1024
top=768
Then set the camera to be pointing along the z-axis at (512,384), with up being the positive y direction?

Is this correct, or should I be using values in the range [0.0f,1.0f] rather than screen coordinates?
Those values look good. Worst case you'll have to swap them, but it will be very obvious if that is the case.

The Ortho matrix is your camera/view, so just set that matrix as your view and you're ready to go.
Stay Casual,KenDrunken Hyena
Oh... I was trying to set the Ortho matrix as my projection...
But hang on that's correct right? I've managed to get all confused over this simple stuff now!

Could you or someone else provide a simple world, view & projection matrix so that a vertex at (0,0,0) maps to the bottom left of the monitor and (1,1,0) to the top right? I know it's basic but I have amental block right now.

Definitely more ratings to give out on this. Stupid 4E4 and time constraints!

This topic is closed to new replies.

Advertisement