The Technical Content Window displays how the viewing transformation matrix is computed. If we compute this 4x4 matrix versus calling the OpenGL function gluLookAt, we would then need to appply it to the model-view stack.
First, suppose we use the following two-dimensional array for storing our 4x4 viewing transformation matrix (vtm).
double vtm[4][4];Since the current matrix on top of the model-view stack is applied to the geometry, we only have to combine through matrix multiplication our viewing transformation matrix with the current model-view matrix. This is accomplished with the following function.
glMultMatrixd(const GLdouble *m)where m is an array of 16 values holding the entries of our matrix vtm. Further, the entries of vtm must be stored in m column by column -- that is, the four entries of the first column are stored first, then the entries of the second column, etc. The following declaration of m and nested iteration achieves our goal of storing in m the entries of our viewing transformation matrix.
double m[16];
for (int j=0; j<4; j++)
for (int i=0; i<4; i++)
m[i+4*j] = vtm[i][j];
Of course, when we call glMultMatrixd, the model-view stack must be the current one. We also need the identity matrix on top of the stack. The following code snippet carries out the tasks of setting our viewing transformation matrix so as it is used in converting our world to viewing coordinates.
glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glMultMatrixd(m);