Replaces the current Transformation matrix with
an arbitrary matrix supplied. It may be more efficient to use some of
the other matrix manipulation functions such as glLoadIdentity,
glRotate, glTranslate, and glScale.
Parameters
*m
GLdouble or GLfloat: This array represents a 4 x 4 matrix that will be used for the current Transformation matrix. The array is stored in column-major order as 16 consecutive values.
Returns
None.
Example
The following two segments of code are equivalent. They both load the Modelview matrix with the Identity matrix.
This function multiplies the currently selected
matrix stack with the one specified. The resulting matrix is then stored
as the current matrix at the top of the matrix stack.
Parameters
*m
GLdouble or GLfloat: This array represents a 4 x 4 matrix that will be multiplied by the current matrix. The array is stored in column-major order as 16 consecutive values.
Returns
None.
Example
The following code creates a Translation matrix and multiplies it by the current Modelview matrix. The newly created matrix replaces the values in the Modelview matrix. The multiplication shown here could also have been accomplished by calling glTranslate(10.0f, 0.0f, 0.0f);.
// Define the Translation matrix
glFloat m[] = { 1.0f, 0.0f, 0.0f, 10.0f,
0.0f, 1.0f, 0.0f, 0.0f,
0.0f, 0.0f, 1.0f, 0.0f,
0.0f, 0.0f, 0.0f, 1.0f };
// Multiply the Translation matrix by the current Modelview
// matrix. The new matrix becomes the Modelview matrix
glMatrixMode(GL_MODELVIEW);
glMultMatrixf(m);
This function is used to pop the last (topmost) matrix off the current matrix stack. This is most often used to restore the previous condition of the current Transformation matrix if it was saved with a call to glPushMatrix.
Returns
None.
Example
The code below is from the ATOM example program for this chapter. This section saves the Modelview matrix state with a call to glPushMatrix (which is centered in the atom). Then the coordinate system is rotated and translated appropriately to place the electron, which is represented by a small sphere. The coordinate system is then restored by a call to glPopMatrix before the next electron is drawn.
// First Electron Orbit
glPushMatrix();
glRotatef(fElect1, 0.0f, 1.0f, 0.0f);
glTranslatef(90.0f, 0.0f, 0.0f);
auxSolidSphere(6.0f);
glPopMatrix();
See Also
glPushMatrix
glPushMatrix
Purpose
Pushes the current matrix onto the matrix stack.
Include File
<gl.h>
Syntax
void glPushMatrix(void);
Description
This function is used to push the current matrix onto the current matrix stack. This is most often used to save the current Transformation matrix so that it can be restored later with a call to glPopMatrix.