I have been trying to understand the the coordinates of the frustum gluPerspective() creates. In case of glOrtho we explicitly define the coordinate space. for example:

    glOrtho(left, right,bottom,top,nearVal, farVal);

tells me what my x,y,z boundaries are, and I can conveniently place objects using

    glVertex();

But in case of gluPerspective() I get the frustum but I don't know the the limits of x,y,z coordinates so sometimes when I draw the objects, it is not even in the view.

for example, if i define the frustum like

      gluPerspective(45.0f, w/h, 0.1f, 100.0f); 

and i draw something like :

     glBegin(GL_POLYGON);
         glVertex3f(30,30,50);
         glVertex3f(-80,20,50);
         glVertex3f(60,50,50);
      glEnd();

where in the scene would it be? where is the origin located?

also, How the arguments of gluLookat() related to the arguments of gluPerspective();

有帮助吗?

解决方案

gluLookat() transforms the objects from world coordinates to camera coordinates.

gluPerspective() Applies perspective to the objects.

The origin is (0,0,0). You locate it where your vertices say.

If you want to know the right and top parameters of the frustum use:

top = n * tan((fov*0.5f) * PI / 180.0f);
r = top * (float)w/(float)h;

In your case fov = 45.

gluLookat() and gluPerspective() have different purposes, so their arguments have nothing to do with each other.

You can use instead of gluPerspective():

glFrustum(left,right,bottom,top,nearVal,farVal)
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top