I am doing my own world -> cam transforms (instead of using gluLookAt
). I was following the info here, but Im getting a different sign for translation for the final 4x4 model view transform.
The article says "Since we are looking down the x-axis, the world is translated by the negative position of the camera.". And then they translate by -eye
, which is -camPos
in my code.
I don't think this is right, since opengl is right handed, and camera typically looks down -Z (away into screen). So it seems the correct translation transform should be +camPos
.
float lookAtP[3] = {0,0,0}; /* camera look at point */
float camPos[3] = {0,0,-150}; /* camera location */
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(camPos[0],camPos[1],camPos[2], lookAtP[0],lookAtP[1],lookAtP[2], 0,1,0);
GLfloat matrix[16];
glGetFloatv (GL_MODELVIEW_MATRIX, matrix);
mat_print(matrix);
Result (gluLookAt):
-1.0000 0.0000 0.0000 0.0000
0.0000 1.0000 0.0000 0.0000
0.0000 0.0000 -1.0000 0.0000
0.0000 0.0000 -150.0000 1.0000
When i follow the article, i get the translation of different sign (+150). I calculate rotation matrix R
, then translation T
. Then, load the transpose of T*R
with glLoadMatrix
(cause opengl is right handed, and the article deals with left-handed coord system).
-1.0000 0.0000 0.0000 0.0000
0.0000 1.0000 0.0000 0.0000
0.0000 0.0000 -1.0000 0.0000
0.0000 0.0000 150.0000 1.0000
The question is, is the article correct???