I feel like I understand the usage of the modelview matrix and gluLookAt
. That is, by declaring gluLookAt(ex,ey,ez,lx,ly,lz,ux,uy,uz)
, one can easily set up a way to look at a certain point directly.
My question is - since gluLookAt
postmultiplies the current matrix, assuming you load the identity prior to calling gluLookAt
, and the current matrixmode is modelview, what happens if you draw a cube?
So something like this :
glMatrixMode(GL_PERSPECTIVE);
glLoadIdentity();
glFrustum(-5, 5, -5, 5, 15, 150);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(0, 0, 16, 0, 0, 0, 0, 1, 0);
glutSolidCube(1.0);
Where is the cube rendered in world coordinates? For some reason, in this case, it's rendered at the world origin, and you can see it in the viewport - but why? Shouldn't gluLookAt
have modified the modelview matrix with the view rotation and translation? Should't the cube be rendered essentially with the camera inside?
glutSolidCube(1.0) draws a cube with side-length 1.0 which is centered at the world origin.
so the vertices are:
now gluLookAt(0, 0, 16, 0, 0, 0, 0, 1, 0) generates a modeView matrix that transforms these coordinates into the camera coordinates.
Since the camera position is just translated by (0,0,16) wrt the default camera position (0,0,0), this modelView matrix basically translates each vertex by (0,0,-16).
Clear?