Contents / Previous / Next


GLU: Coordinate Transformation


Viewing Transformation

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).


Projection Transformation

The gluPerspective() routine creates a viewing volume of the same shape as glFrustum() does, but you specify it in a different way.

Rather than specifying corners of the near clipping plane, you specify the angle of the field of view (fovy=theta) in the y direction and the aspect ratio of the width to height (x/y). (For a square portion of the screen, the aspect ratio is 1.0.) These two parameters are enough to determine an untruncated pyramid along the line of sight.

You also specify the distance between the viewpoint and the near and far clipping planes, thereby truncating the pyramid.

  void gluPerspective( GLdouble fovy, GLdouble aspect,
                       GLdouble near, GLdouble far );
fovy, the angle of the field of view in the x-z plane must be in the range [0.0,180.0].
aspect is the aspect ratio of the frustum, its width divided by its height.
near and far values the distances between the viewpoint and the clipping planes, along the negative z-axis.
They should always be positive.

Note that gluPerspective() is limited to creating frustums that are symmetric in both the x- and y-axes along the line of sight, but this is usually what you want.


gluOrtho2D sets up a two-dimensional orthographic viewing region.
This is equivalent to calling glOrtho with near = -1 and far = 1 .


gluProject transforms the specified object coordinates (objx, objy, objz) into window coordinates
using modelMatrix, projMatrix, and viewport as parameter.
The result is stored in winx, winy, and winz.
A return value of GL_TRUE indicates success, and GL_FALSE indicates failure.
int gluProject( GLdouble objx, GLdouble objy, GLdouble objz, 
                const GLdouble modelMatrix[16], 
	        const GLdouble projMatrix[16], 
		const GLint viewport[4],
		GLdouble *winx, GLdouble *winy, GLdouble *winz )

gluUnProject maps the specified window coordinates into object coordinates
using modelMatrix, projMatrix, and viewport.
The result is stored in objx, objy, and objz.