5
\$\begingroup\$

I am fairly new to openGL( 3 months ) and am asking for assistance in understanding the fundamentals behind gluLookAt().

Currently I have spent most of my time with openGL modeling scenes with fixed views, and I wanted to begin using gluLookAt combined with keyboard and mouse callbacks to "explore" my scenes. I created a simple program to play around with the functionality of gluLookAt when I first realized I may not understand fully what is happening.

My program creates a world using glOrtho(-4,4, -4,4, -4,4) confining my area somewhat around the origin (0,0,0) upon which I place the standard glutSolidTeapot(0.5). Then in an attempt to create a "camera" revolve around the teapot, in an idle callback function I write this

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt( cos(business), 0, sin(business), 0.0,0.0,0.0, 0.0,1.0,0.0 /*up vector*/ );
glutPostRedisplay();

Turns out, this worked. The view shows a revolving teapot. So I take another step and attempt to create an elliptical path around the teapot, multiplying either cos() or sin() (not both) by 2. This works as well but does not have the same effect I was expecting. The view rotates around the teapot, but I imagined along the path the teapot would "appear" to be closer at points, a zooming in effect of sorts. This leads to my question.

What exactly do I not understand about this? or.. Why is this not doing what I am expecting?

\$\endgroup\$
6
\$\begingroup\$

That is simple. You are using orthographic projection (viewing rays are parallel), so it doesn't make any difference if you are at distance 1 or 100.

Use gluPerspective and it will work how you expect.

(left img ortho projection, right img perspective proj)

your code may look like this:

glMatrixMode(GL_PROJECTION);
gluPerspective( PI / 3.0f, window_width/window_height, zNear, zFar);

...

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt( cos(business) * radius, 0, sin(business) * radius, 0.0,0.0,0.0, 0.0,1.0,0.0 /*up vector*/ );
glutPostRedisplay();

img source

\$\endgroup\$
  • 2
    \$\begingroup\$ Thank you very much. Not only did this answer my question/fix my code, I now have some direction in my studies tonight. :) Thanks again. \$\endgroup\$ – user7679 May 30 '11 at 2:28
  • \$\begingroup\$ No problem, its always nice to help :) \$\endgroup\$ – Notabene May 30 '11 at 2:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.