1
votes

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???

1
Well, you're right when you say that the GL_MODELVIEW matrix is right-handed and the camera matrix is left handed... I'll read the article to see if I can get more conclusions.fvdalcin
NDC, which is the coordinate space you ultimately wind up in before the final viewport transform is left-handed. This is the only coordinate space in OpenGL that you have no control over, z=-1 is always the nearest depth and z=1 is always the farthest depth. Depth range, projection and your modelview matrix can all have your various intermediate coordinate spaces in different handedness so long as the final product logically maps to left-handed NDC. In the fixed-function pipeline, everything before projection was right-handed and the projection matrix / depth range is what produced proper NDC.Andon M. Coleman

1 Answers

0
votes

OpenGL itself is not left- or right-handed. OpenGL's clip and window spaces are typically considered to be right-handed (although one could use them the other way around, if one really wants to).

In the classic fixed-function pipeline, eye and object space were typically defined left-handed. gluLookAt() uses this convention. Also gluPerspective()/glFrustum()/glOrtho() use this convention as the positive values for near and far that they take actually refer to negative z values in eye space. These projection matrices typically change the handedness.