[Hill: 358-366. Foley & van Dam: p. 237-242 (slightly different terminology]

Viewing Transformations

The modelling transformation expresses the position of objects in the world. We derive the viewing transformation by first expressing the position of the camera in the world. This transformation is then inverted to express the position of the world with respect to the camera.



Defining Mcam

A common way of defining the camera position and orientation is to use:






Building M_cam

The vectors i,j,k can be determined as follows:


These vectors can then be used to form a change-of-basis matrix, which is composed with a translation to yield the camera-to-world transformation and its inverse, which is what we really desire.


Positioning the camera in OpenGL

The OpenGL auxilliary library provides the call gluLookAt() to create the viewing transformation.

gluLookAt(ex,ey,ez,rx,ry,rz,ux,uy,uz>

where (ex,ey,ez) gives the eye point, (rx,ry,rz) gives the reference or 'lookat' point, and (ux,uy,uz) gives the up vector.
This function call postmultiplies the current matrix, so the easiest way to use it is:

  glMatrixMode(GL_MODELVIEW);
  glLoadIdentity();
  gluLookAt(ex,ey,ez,rx,ry,rz,ux,uy,uz);
  /* setup modelling transformations here */