Computer Science Canada Frustum Help in OpenGL |
Author: | 102jon [ Tue Jan 11, 2011 12:02 pm ] |
Post subject: | Frustum Help in OpenGL |
I created a frustum in openGL with the arguments glFrustum(-1.0, 1.0, -1.0, 1.0, 2.0, 100.0). The last two arguments represent distances to near and far clipping planes respectively. My question is, how do I place an object at a given set of z-coordinates? x and y are easy enough to do as I can place the object anywhere in the range of -1.0 to 1.0, but I'm not exactly sure how the z-coordinates work. |
Author: | TerranceN [ Tue Jan 11, 2011 4:21 pm ] | ||
Post subject: | Re: Frustum Help in OpenGL | ||
What the near and far clipping planes mean is that openGL will only draw thing that have a distance from the camera d, in the range nearDistance < d < farDistance. Since the camera is at the origin, and facing down the -z axis, something with a negative z value in between -2.0 and -100.0 can be drawn to the screen. Also, messing around with glFrustum, I noticed it will skew the image unless the values you give it for left/right and top/bottom are in the same ratio as the window width and window height. A better function to use is <a href="http://www.opengl.org/sdk/docs/man/xhtml/gluPerspective.xml">gluPerspective</a>, as it takes this ratio into account. A typical call to gluPerspective would look like this:
Also, you should check out <a href="http://nehe.gamedev.net/">NeonHelium</a>, as they hve some really good openGL tutorials. |