🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

What does gluLookAt exactly do for us?

Started by
4 comments, last by Sneftel 18 years, 3 months ago
I've heard from somewhere that all GLU functions are base on the GL functions, they are only a group calls of GL functions. If this is true, gluLookAt must be some basic calls of glTranslate, glRotate and glScale, etc. So what does gluLookAt exactly do for us? I used gluLookAt(eyex, eyey, eyez, centerx, centery, centerz, 0.0, 1.0, 0.0), and I would like to add some objects into the scene whose coordinates are based on the original point (0.0, 0.0, 0.0). How can I use glTranslate to move current position to (0.0, 0.0, 0.0)? Thanks to every one read this message!
Advertisement
Quote: Original post by WWWFdisk
I've heard from somewhere that all GLU functions are base on the GL functions, they are only a group calls of GL functions. If this is true, gluLookAt must be some basic calls of glTranslate, glRotate and glScale, etc.

Yes. In most implementations, the only GL function that gluLookAt will call is glMultMatrix. It could do the same thing with glTranslate and glRotate but the process would be considerably less efficient.

Quote: So what does gluLookAt exactly do for us?

gluLookAt generates, and postmultiplies the active matrix by, a transformation matrix which includes a translation and a rotation. The rotation is built up as an orthonormal basis from the eye-to-target vector and the up-vector using Gramm-Schmidt orthonormalization. In practical terms, it lets you define a rotation matrix based on the global "up" and the local "forwards", and also has a translation to put the "camera" somewhere.

Quote: I used gluLookAt(eyex, eyey, eyez, centerx, centery, centerz, 0.0, 1.0, 0.0), and I would like to add some objects into the scene whose coordinates are based on the original point (0.0, 0.0, 0.0). How can I use glTranslate to move current position to (0.0, 0.0, 0.0)?
I'm not sure what you mean by "original point" or "current position". What are you trying to do?
say you have a vector camera... (center - eye) = L (look direction), U = camera's up vector. gluLookAt computes U x L to get a side vector S, then recomputes U = S x L to guarantee axes are orthogonal.

then it maps L to the -Z axis, S to the X axis, and U to the Y axis. this is equivalent to a rotation matrix. gluLook at actually creates the matrix then calls glMultMatrix to load it to (what should be) the modelview matrix.

then gluLookAt calls glTranslate to translate the camera's eye point to the origin.

so the tranformation is R*T = translate to origin, and then align axes. to see the exact code how it works, you can download MESA, or here is my own code (I wrote my own vector camera class because I don't like gluLookAt's center point thing and I prefer to use the gl***TransposeMatrix functions).

EDIT: Oh yeah, you're right. Corrected. He he he...

void SLCamera3D::UpdateModelview(void){ // normalize D (Direction, Look At vector) D.Normalize(); // L = U x D (L = Left Vector) L = U.CrossWith(D); L.Normalize(); // U = D x L (recompute Up Vector) U = D.CrossWith(L); U.Normalize(); // update modelview matrix // vM = (R)x(T) vM[0][0] = -L[0]; vM[0][1] = -L[1]; vM[0][2] = -L[2]; vM[0][3] = -(vM[0][0]*E[0] + vM[0][1]*E[1] + vM[0][2]*E[2]); vM[1][0] = U[0]; vM[1][1] = U[1]; vM[1][2] = U[2]; vM[1][3] = -(vM[1][0]*E[0] + vM[1][1]*E[1] + vM[1][2]*E[2]); vM[2][0] = -D[0]; vM[2][1] = -D[1]; vM[2][2] = -D[2]; vM[2][3] = -(vM[2][0]*E[0] + vM[2][1]*E[1] + vM[2][2]*E[2]); vM[3][0] = 0.0; vM[3][1] = 0.0; vM[3][2] = 0.0; vM[3][3] = 1.0;}
Quote: Original post by yadango
then calls glLoadMatrix to load it to (what should be) the projection matrix.


A minor nitpick: gluLookAt invokes glMultMatrix, not glLoadMatrix. It combines with, rather than replaces, the current matrix. So if there's cruft there, make sure to use glLoadIdentity to clear it out.
Thanks.
My English is poor, and also my knowlegde of OpenGL. :P
What I mean is that if I used
glLookAt(5.0, 4.0, -3.0, 5.0, 4.0, 3.0, 0.0, 1.0, 0.0), and now I want to put some object in the center of the screen, so I must use glTranslate to move the current point to this place.
How much should I translate in every direction?
Should I change the matrix mode at first?
Well, you're looking at the point [5,4,3]. So, if you wanted something to show up at that point, I'd say you'd glTranslate by [5,4,3].

This topic is closed to new replies.

Advertisement