PDA

View Full Version : Perspective Projection Question



gareththegeek
12-13-2007, 05:03 AM
Lets say I have a screen resolution of 320x240 pixels and I am using perspective projection. What I am hoping to do is set up a projection matrix which will allow me to treat opengl x and y coordinates as screen coordinates for a certain value of z.

At this particular z value, if I were to render a quad from [ -160.0f, 120.0f ] to [ 160.0f, -120.0f ] it would exactly fill the screen.

Objects in my application should be rendered 3d with perspective so that, for example, a cube will look like a cube as it moves and rotates; just when the cube is orthogonal to the camera and at this particular z value I can treat the surface as if it were in an orthographic projection.

How can I calculate the values necessary for a call to glFrustum which will give me this matrix?

Hope I have made myself clear, if not please ask!

Many thanks,
G!

k_szczech
12-13-2007, 05:21 AM
Check glFrustum specification. At distance zNear, your screen fits exactly to (left,top)-(right,bottom).

So, if you pass -1.6/+1.6 as your left/right, -1.2/+1.2 as your bottom/top and 0.1 as your zNear then:
-screen has 3.2x2.4 pixels at distance of 0.1
-screen has 320x240 pixels at distance of 10

gareththegeek
12-13-2007, 05:54 AM
Yes, thanks very much - it seems obvious once someone tells you the answer ;)

I had read the glFrustum spec and worked out the zNear part but for some reason I couldn't take it that step further and move backwards on z axis...

Thanks again!
G!