4

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();

Bounty Collector
  • 615
  • 7
  • 19

1 Answers1

0

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)
Luis
  • 678
  • 8
  • 14
  • "The origin is (0,0,0). You locate it where your vertices say". Sorry, I didn't understand that line. Ok, to simply ask the question again how do you select the coordinates in glVertex(x,y,z), what is the relationship of gluPerspective() arguments and how do we determine object coordinates which would fit in it. – Bounty Collector Nov 13 '13 at 17:24
  • You can use glFrustum() and provide the limits yourself. – Luis Nov 13 '13 at 18:27
  • What is "n" ?If glFrustum() is not used then how to calculate x,y co ordinates –  Feb 18 '15 at 14:39
  • "n" is the near viewing plane distance. You have to create the matrix yourself and multiply every point by it. http://www.songho.ca/opengl/gl_projectionmatrix.html – Luis Feb 20 '15 at 13:09