public class MatrixStack
extends java.lang.Object
Matrix3D
transformations. It allows pushing and popping
Matrix3D
s in a manner analogous to the deprecated OpenGL matrix
stacks (e.g. ModelView, Projection, and Texture matrix stacks).
The class is modeled after the GLMatrixStack class in the GLTools package
of the text "OpenGL SuperBible, 5th Edition", by Richard Wright.Constructor and Description |
---|
MatrixStack(int maxSize)
Creates a
MatrixStack with the specified maximum depth. |
Modifier and Type | Method and Description |
---|---|
void |
loadIdentity()
Sets the
Matrix3D at the top of the stack to be the Identity
matrix, discarding the previous contents of the top of the stack. |
void |
loadMatrix(Matrix3D mat)
Sets the
Matrix3D at the top of the stack to be a copy of
the specified matrix, discarding the previous contents of the top of the stack. |
void |
multMatrix(Matrix3D mat)
Concatenates the specified matrix with the matrix currently at the top
of the stack, replacing the top of the stack with the resulting product
matrix.
|
Matrix3D |
peek()
Returns a copy of the
Matrix3D at the top of the stack without
affecting the stack. |
void |
popMatrix()
Pops the top element off the stack and discards it, or throws a
RuntimeException if the stack is empty. |
void |
pushMatrix()
Makes a copy of the
Matrix3D currently at the top of the stack
and pushes that copy onto the stack (i.e., duplicates the top of the stack). |
void |
rotate(double degrees,
double x,
double y,
double z)
Applies the specified rotation by angle degrees about the specified
axis x,y,z to the
Matrix3D at the top
of the stack. |
void |
scale(double x,
double y,
double z)
Applies the specified scale factors to the
Matrix3D at the top
of the stack. |
void |
translate(double x,
double y,
double z)
Applies the specified translation factors to the
Matrix3D at the top
of the stack. |
public MatrixStack(int maxSize)
MatrixStack
with the specified maximum depth.
Each entry in the MatrixStack
is a single Matrix3D
.
A newly-created MatrixStack
is automatically initialized with
an Identity Matrix3D at the top of the stack.maxSize
- - the maximum size (depth) of the stack before a
stack overflow exception occurspublic void loadIdentity()
Matrix3D
at the top of the stack to be the Identity
matrix, discarding the previous contents of the top of the stack.public void loadMatrix(Matrix3D mat)
Matrix3D
at the top of the stack to be a copy of
the specified matrix, discarding the previous contents of the top of the stack.mat
- - the matrix to be copied onto the top of the stack, replacing
the current top of the stackpublic void multMatrix(Matrix3D mat)
stack[top] = stack[top] * mat ;
mat
- - the matrix to be concatenated onto the matrix at the top of
the stackpublic void pushMatrix()
Matrix3D
currently at the top of the stack
and pushes that copy onto the stack (i.e., duplicates the top of the stack).
Analogous to OpenGL routine glPushMatrix()
.
Throws a RuntimeException
if there is not room on the stack to
push another matrix onto the stack.public void popMatrix()
RuntimeException
if the stack is empty.public void scale(double x, double y, double z)
Matrix3D
at the top
of the stack. This is done by creating a new Matrix3D
representing
the specified scaling and then concatenating the new matrix with the matrix
at the top of the stack using multMatrix(Matrix3D)
.
Analogous to OpenGL method glScaled().x
- - the scale factor in Xy
- - the scale factor in Yz
- - the scale factor in Zpublic void rotate(double degrees, double x, double y, double z)
Matrix3D
at the top
of the stack. This is done by creating a new Matrix3D
representing
the specified rotation and then concatenating the new matrix with the matrix
at the top of the stack using multMatrix(Matrix3D)
.
Analogous to OpenGL method glRotated().degrees
- - the angle of rotation in degreesx
- - the X component of the rotation axisy
- - the Y component of the rotation axisz
- - the Z component of the rotation axispublic void translate(double x, double y, double z)
Matrix3D
at the top
of the stack. This is done by creating a new Matrix3D
representing
the specified translation and then concatenating the new matrix with the matrix
at the top of the stack using multMatrix(Matrix3D)
.
Analogous to OpenGL method glTranslated().x
- - the translation in Xy
- - the translation in Yz
- - the translation in Z