Frustum Help in OpenGL
Author |
Message |
102jon
|
Posted: 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. |
|
|
|
|
|
Sponsor Sponsor
|
|
|
TerranceN
|
Posted: 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 gluPerspective, as it takes this ratio into account. A typical call to gluPerspective would look like this:
c++: |
gluPerspective(45.0f, (float)width / height, 0.1f, 100.0f);
|
Also, you should check out NeonHelium, as they hve some really good openGL tutorials. |
|
|
|
|
|
|
|