The JSL example below uses Push Matrix and Pop Matrix to position pieces of the toy top and then return to the origin. This is faster than using the Translate command a second time in reverse.
图 13.15 Drawing With a Matrix Stack
toyTop = Scene Display List();
toyTop << Push Matrix;
toyTop << Pop Matrix;
toyTop << Push Matrix;
toyTop << Pop Matrix;
toyTop << Push Matrix;
toyTop << Pop Matrix;
toyTop << Push Matrix;
toyTop << Pop Matrix;
scene << Call List( toyTop );
There are some cases where you want to replace the current matrix on the stack. For these cases, use the Load Matrix command.
where m is a 4x4 JMP matrix that is loaded onto the current matrix stack.
Similar is the Mult Matrix command
When the Mult Matrix command is issued, the matrix on the top of the current matrix stack is multiplied by m.
Rotation about x-axis:
Rotation about y-axis:
Rotation about z-axis:
gl << Push Matrix;
gl << Mult Matrix( xt * xr * yr * zr );
gl << Pop Matrix;
gl << Push Matrix;
gl << Pop Matrix;