gluLookAt and glLoadMatrix

I had read a lot of discussions and articles about gluLookAt and how it works etc. However, I am having trouble replicating it with my project.
I will have to use glLoadMatrix to load the 16 values of the object. However, I realized that the object tends to “move” (translate) with the use of gluLookAt.

Please see the below example:

{ 0.540302    0        0.841471       0
  0           1        0              0
 -0.841471    0        0.540302     -10
  0           0        0              1 }
glMatrixMode( GL_MODELVIEW );
glLoadIdentity();
glLoadMatrixd([matrix_above]);
gluLookAt(0 ,0,10,
              0,0,0,
              0,1, 0);
glutWireTeapot(1);

The teapot will be displayed as the following (left), (right) was supposed to be how the teapot is (in the middle of display but rotate on the y-axis).

I tried looking around for a couple of days now but can’t find a better reason on why this is happening. I had tried it with glRotate and glTranslate and gluLookAt works fine. It seems to work weirdly when pairing with glLoadMatrix? Or am I wrong?

You probably want gluLookAt followed by glMultMatrix. If the gluLookAt comes afterwards, the vectors (eye, center, up) will be in the coordinate system established by the glLoadMatrix call.

Also, you’ll probably be wanting the center vector to be (0,0,-10), given that’s where your matrix moves the object’s origin to.

gluLookAt is useful mainly when you want to move the camera relative to the “world” but keep the camera looking at the object. If you’re orbiting the camera around the object, it makes more sense to use glRotate and glTranslate.

1 Like

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.