View Full Version : glFrustum()...

jtwoods

12-19-2000, 05:14 PM

I feel I have somewhat of a grip on teh GL_MODELVIEW matrix, but the GL_PROJECTION matrix is still beyond me...Primarily, I don't understand glFrustum(), the command that sets a perspective projection matrix by defining a viewing frustum. Could someone please explain this command to me, and how it relates to gluPerspective()? Thanks.

I don't know gluPerspective but i can say something about glFrustum.

the function is:

glFrustum(left,right,bottom,top,near,far);

(all parameters are GLdouble).

the "near" parameter is the distance between the camera and the first seen plane. Objects between the camera and the near plane aren't seen.

the "far" parameter is the distance between the camera and the last seen plane. Objects beyond this plane aren't seen. So you will see only objects between the near and far planes.

Now we have four parameters: left, right, bottom and top. These parameters describe the coordinates of the NEAR plane. Example:

if you define left = -1; right = 1; top = 1 and bottom = -1 then the near frustrum plane will be a square with side 2 centered in (x=0,y=0,z=near). Then objects as distant as the near plane are seen only if they are in OR intercept the x range (-1;1) and the y range(-1;1). Objects far away the near plane are clipped by a larger range because frustum will open.

Note: the values of left,right,bottom and top will affect the position of the objects in the screen. If left is negative then objects with negative x coordinates (after ModelView transformation) will appear in left of the window else (left+) that objects will appear in RIGHT of the screen. Idem with top and bottom.

Hope this help

marcio

jtwoods

12-19-2000, 07:12 PM

Thanks for the reply, it was very helpful, but I am unclear of one thing. If you only define the top, bottom, left ,right coords for the near plane, then wouldn't OGL have to use those for the far plane too...in effect, setting the frustum to a rectangular prism. How can OGL calc the far plane coords by itself? I need my frustum to be a pyramid...This doesn't part doesn't make sense, how to get a pyramid from 2 rectangles x distance apart. If anyone can understand what I mean, please reply. Thanks!

softland_gh

12-19-2000, 09:59 PM

It's very easy for OpenGL to calculat far plane bounds. That's because you supplied the near and the fare distances. For example, if OpenGL want's to calculate the left bound for the far plane it uses this simple formula:

FarLeft=NearLeft*(FarDist/NearDist)

So don't worry. It will look finally like a pyramid.

Deiussum

12-20-2000, 10:22 AM

If the OpenGL used the same coordinates for the far plane as you specify for the near plane you're frustum would actually be reversed becuase those same coordinates further away would be a smaller area. (The same way that objects appear smaller the further away you get.) By using the distance of the near plane with the width and height of the near plane, you can basically get your field of view. If you think of the eye point as the top of the pyramid, and the near plane as the bottom of the pyramid, you can caluclate the angles from the eypoint to the edges of the near plane. Extend those angles out to the far plane, and you can calculate the coordinates of that.

jtwoods

12-20-2000, 12:08 PM

Thanks guy, I think I understand the glFrustum() call now. It makes sense now. Now I just have to go find the glu source for gluPerspective and see how it takes its angle param and calcs the frustum http://www.opengl.org/discussion_boards/ubb/smile.gif. Ciao

Powered by vBulletin® Version 4.2.3 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.