render
Class Matrix

java.lang.Object
  |
  +--render.Matrix

public class Matrix
extends java.lang.Object

Provides functionality for 4x4 3D matrix manipulations. It's thread-safe.


Constructor Summary
Matrix()
          Default constructor.
Matrix(double[] a)
          Constructor takes an array of 16 elements to populate the 4x4 matrix.
 
Method Summary
 void copy(Matrix src)
          Copies contents from matrix src to the object matrix.
 double[] get()
          Returns a copy of matrix (thread-safe)/
 double get(int i, int j)
          Returns matrix value at m[i, j].
 double[] getUnsafe()
          Returns the actual array containing the matrix (not thread-safe).
 void identity()
          Sets the object matrix to the identity matrix.
static void identity(Matrix m)
          Sets the desired matrix to the identity matrix.
 void invert(Matrix msrc)
          Inverts the 4x4 matrix and stores the result in the object matrix.
 void postMultiply(Matrix mb)
          Postmultiplies the object matrix by mb and stores the result in the object matrix; As a result, the translation, scaling and rotation operations contained in mb are effectively performed after those in the object matrix .
 void preMultiply(Matrix mb)
          Premultiplies the object matrix by mb and stores the result in the object; As a result, the translation, scaling and rotation operations contained in mb are effectively performed before those in the object .
 void rotate(double theta, double x, double y, double z)
          Modifies the object matrix to rotate by angle theta about axis x,y,z.
 void rotateX(double theta)
          Modifies the object matrix to rotate about the X axis by angle theta.
 void rotateY(double theta)
          Modifies the object matrix to rotate about the Y axis by angle theta.
 void rotateZ(double theta)
          Modifies the object matrix to rotate about the Z axis by angle theta.
 void scale(double x, double y, double z)
          Scales the transformation matrix by x,y,z in the respective directions.
 void set(int i, int j, double d)
          Sets matrix value at m[i,j] to d.
 java.lang.String toString()
           
 java.lang.String toString(Matrix mm)
          Converts the transformation matrix to a String.
 void translate(double x, double y, double z)
          Applies a translation by x, y, z to the obeject matrix.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Matrix

public Matrix()
Default constructor.


Matrix

public Matrix(double[] a)
Constructor takes an array of 16 elements to populate the 4x4 matrix.

Parameters:
a - 4x4 quaternion values
Method Detail

get

public final double get(int i,
                        int j)
Returns matrix value at m[i, j].

Parameters:
i - row index
j - column index
Returns:
value at specified location

set

public final void set(int i,
                      int j,
                      double d)
Sets matrix value at m[i,j] to d.

Parameters:
i - row index
j - column index
d - the new value

getUnsafe

public final double[] getUnsafe()
Returns the actual array containing the matrix (not thread-safe).

Returns:
the actual matrix array of 16 elements
See Also:
get(int, int)

get

public final double[] get()
Returns a copy of matrix (thread-safe)/

Returns:
a copy of the matrix array (16 elements).
See Also:
getUnsafe()

identity

public static final void identity(Matrix m)
Sets the desired matrix to the identity matrix.

Parameters:
m - the matrix to be modified

identity

public final void identity()
Sets the object matrix to the identity matrix.


copy

public final void copy(Matrix src)
Copies contents from matrix src to the object matrix.

Parameters:
src - original matrix to be copied

preMultiply

public final void preMultiply(Matrix mb)
Premultiplies the object matrix by mb and stores the result in the object; As a result, the translation, scaling and rotation operations contained in mb are effectively performed before those in the object .

Parameters:
mb - the multiplier matrix

postMultiply

public final void postMultiply(Matrix mb)
Postmultiplies the object matrix by mb and stores the result in the object matrix; As a result, the translation, scaling and rotation operations contained in mb are effectively performed after those in the object matrix .

Parameters:
mb - the multiplier matrix

translate

public final void translate(double x,
                            double y,
                            double z)
Applies a translation by x, y, z to the obeject matrix. The shape or orientation of the object are not affected.

Parameters:
x - amount of translation along the x axis
y - amount of translation along the y axis
z - amount of translation along the z axis

rotateX

public final void rotateX(double theta)
Modifies the object matrix to rotate about the X axis by angle theta.

Parameters:
theta - angle of rotation in radians

rotateY

public final void rotateY(double theta)
Modifies the object matrix to rotate about the Y axis by angle theta.

Parameters:
theta - angle of rotation in radians

rotateZ

public final void rotateZ(double theta)
Modifies the object matrix to rotate about the Z axis by angle theta.

Parameters:
theta - angle of rotation in radians

rotate

public final void rotate(double theta,
                         double x,
                         double y,
                         double z)
Modifies the object matrix to rotate by angle theta about axis x,y,z.

Parameters:
theta - angle of rotation in radians
x - 1st coord of rotation axis
y - 2nd coord of rotation axis
z - 3rd coord of rotation axis

scale

public final void scale(double x,
                        double y,
                        double z)
Scales the transformation matrix by x,y,z in the respective directions.

Parameters:
x - scale factor along the x axis
y - scale factor along the y axis
z - scale factor along the z axis

invert

public final void invert(Matrix msrc)
Inverts the 4x4 matrix and stores the result in the object matrix.

Parameters:
msrc - original matrix to be inverted

toString

public final java.lang.String toString(Matrix mm)
Converts the transformation matrix to a String.

Returns:
a textual representation of the matrix

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object