Sign in to follow this  


Recommended Posts

giugio    246
hy. i have this line: glFrustum(-15.5f, 15.5f, -12.0f, 12.0f, 0.0, 10.0f); i'm not undderstand very well the glfrustum and i try to draw at 1,1,1 , but draw nothing. Why?

Share this post

Link to post
Share on other sites
haegarr    7372
glFrustum(left,right, bottom ,top,near,far);

geometrically defines a frustum of pyramid (i.e. a pyramid with a cut apex), where the more narrow plane is "near" units away and the wider plane is "far" units away from the apex. Hence, if you specify "near" to be 0, you've skrinked the plane down to a size of 0 (since it is moved into the apex itself). In other words, you ask the pyramid's mantle planes to hit the far plane, but the mantle planes are in parallel with the far plane, so that cannot work. Hence don't do so.

man page
Typically, the matrix mode is GL_PROJECTION, and (left, bottom, -zNear) and (right, top, -zNear) specify the points on the near clipping plane that are mapped to the lower left and upper right corners of the window, assuming that the eye is located at (0, 0, 0). -zFar specifies the location of the far clipping plane. Both zNear and zFar must be positive.
GL_INVALID_VALUE is generated if zNear or zFar is not positive, or if left = right, or bottom = top.

So please check the error value after glFrustum returns.

Share this post

Link to post
Share on other sites
haegarr    7372
There are infinitely many solutions to your question. So rather giving you a particular solution, I tell you how the stuff works in principle. The part of the scene one can see depends on the following things (assuming you use a standard set-up):

The MODEL portion of the MODELVIEW matrix defines how geometry is located and orientated in the global space. When the point [1,1,1] you've mentioned _is_ already meant w.r.t. the global space, then your MODEL transformation is just the identity.

The VIEW portion of the MODELVIEW matrix defines how the global space is located and orientated w.r.t. the camera (or the eye, if you like). Please notice that I haven't written "how the camera is located in global space", since the VIEW transformation is just the inverse of "how the camera is located in global space". If you use the identity matrix for this purpose, then your camera is located at [0,0,0] and is looking along the negative z axis.

With this information, your point
p := [ 1 1 1 ]T
is transformed into the view space by
p' = V * M * p
Your OP doesn't mention how you've set-up the MODELVIEW matrix. If you've done nothing at that point, then
p' == p

Now, the view frustum clips anything that is not contained. Most obviously, it clips away anything that is before zNear and behind zFar. So anything visible must match the condition
zNear <= p'z <= zFar
(okay, I'm not sure whether <= or < is correct). For the top/bottom and left/right things some more math is required, since the perspective projection has to be done. I think that the conditions look like
xLeft <= p'x * zNear / p'z <= xRight
yBottom <= p'y * zNear / p'z <= yTop
As you can see, any p' that is beyond the near plane is experiencing depth fore-shortening.

(BTW: From the 2 conditions above you can see what happens mathematically if zNear is 0: any p' vanishes into a single point.)

With this information you can determine whether a perticular frustum meets your needs.

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this