Contents / Previous / Next


Viewing with gluLookAt()

The gluLookAt() utility routine is designed for looking at a scene from an arbitrary point of view.

It takes three sets of arguments, which specify the location of the viewpoint, define a reference point toward which the camera is aimed, and indicate which direction is up.

gluLookAt(GLdouble eyex, GLdouble eyey, GLdouble
eyez, GLdouble centerx, GLdouble centery, GLdouble
centerz, GLdouble upx, GLdouble upy, GLdouble upz);

gluLookAt() defines a viewing matrix and multiplies it to the right of the current matrix. The desired viewpoint is specified by eyex, eyey, and eyez. The centerx, centery, and centerz arguments specify any point along the desired line of sight, but typically they are some point in the center of the scene being looked at. The upx, upy, and upz arguments indicate which direction is up (that is, the direction from the bottom to the top of the viewing volume).



The Figure shows the effect of a typical gluLookAt() routine.

gluLookAt( 4.0, 2.0, 1.0, 2.0, 4.0, -3.0, 2.0, 2.0, -1.0 );

The camera position (eyex, eyey, eyez) is at (4, 2, 1).
It looking right at the model, so the reference point is at (2, 4, -3).
An orientation vector of (2, 2, -1) is chosen to rotate the viewpoint to this 45-degree angle.