net.jinx.slowmath
Class Matrix3D

java.lang.Object
  extended by net.jinx.slowmath.Matrix3D

public class Matrix3D
extends java.lang.Object

Matrix3D is a 4x4 matrix class intended for graphical tranformation operations, however, it isn't designed in the typical fashion of most graphical Matrix classes I've seen. It's immutable, just like the rest of the classes in this package and is designed for precision and code readability, not speed, but it should be capable of either depending on how the MathUtil class is configured.


Constructor Summary
Matrix3D(Quaternion r1, Quaternion r2, Quaternion r3, Quaternion r4)
          Constructs a Matrix3D from four Quaternions.
Matrix3D(Real[] values)
          Constructs a Matrix3D using the array of Reals.
 
Method Summary
 Matrix3D applyPerspective(Real d)
          Applies a perspective transformation and returns the result.
 Real get(int row, int col)
          Returns a given element of this Matrix3D.
static Matrix3D identity()
          Provides an identity Matrix3D.
 Matrix3D multiply(Matrix3D m)
          Multiplies m (the multiplicand) by this (the multiplier).
static Matrix3D perspectiveMatrix(Real d)
          Constructs a perspective transformation Matrix3D.
 Matrix3D rotate(Quaternion q)
          Applies a rotation transformation and returns the result.
 Matrix3D rotate(Vector v)
          Applies a rotation transformation and returns the result.
 Matrix3D rotateX(Real t)
          Applies a rotation transformation and returns the result.
 Matrix3D rotateY(Real t)
          Applies a rotation transformation and returns the result.
 Matrix3D rotateZ(Real t)
          Applies a rotation transformation and returns the result.
static Matrix3D rotationMatrix(Quaternion q)
          Constructs a rotation Matrix3D for q.
static Matrix3D rotationMatrix(Vector v)
          Constructs a rotation Matrix3D for v.
 Matrix3D scale(Real s)
          Applies a scale transformation and returns the result.
 Matrix3D scale(Real x, Real y, Real z)
          Applies a scale transformation and returns the result.
 Matrix3D scale(Vector v)
          Applies a scale transformation and returns the result.
static Matrix3D scalingMatrix(Real s)
          Constructs a scaling Matrix3D.
static Matrix3D scalingMatrix(Real vx, Real vy, Real vz)
          Constructs a scaling Matrix3D.
static Matrix3D scalingMatrix(Vector v)
          Constructs a scaling Matrix3D.
 double[] toDoubleArray()
           
 float[] toFloatArray()
           
 java.lang.String toString()
           
 Quaternion transform(Quaternion v)
          Transforms v and returns the result.
 Vector transform(Vector v)
          Transforms v and returns the result.
 Matrix3D translate(Vector v)
          Applies a translation transformation and returns the result.
static Matrix3D translationMatrix(Vector v)
          Constructs a translation Matrix3D.
 Matrix3D transpose()
          Returns a transposed version of this Matrix.
static Matrix3D xRotationMatrix(Real t)
          Constructs a rotation Matrix3D for rotating around the X axis.
static Matrix3D yRotationMatrix(Real t)
          Constructs a rotation Matrix3D for rotating around the Y axis.
static Matrix3D zRotationMatrix(Real t)
          Constructs a rotation Matrix3D for rotating around the Z axis.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Matrix3D

public Matrix3D(Quaternion r1,
                Quaternion r2,
                Quaternion r3,
                Quaternion r4)
Constructs a Matrix3D from four Quaternions.

Parameters:
r1 - the first row.
r2 - the first row.
r3 - the first row.
r4 - the first row.

Matrix3D

public Matrix3D(Real[] values)
Constructs a Matrix3D using the array of Reals.

Parameters:
values - the Reals to use.
Method Detail

get

public Real get(int row,
                int col)
Returns a given element of this Matrix3D. The indices are not zero based, like an array. They're one based, because that is the natural, mathematical way to look at it (at least according to the references I've read).

Parameters:
row - the row to access.
col - the column to access.
Returns:
the value of the accessed element.

transpose

public Matrix3D transpose()
Returns a transposed version of this Matrix.

Returns:
the resulting Matrix3D.

transform

public Vector transform(Vector v)
Transforms v and returns the result.

Parameters:
v - the Vector to transform.
Returns:
the resulting Quaternion.

transform

public Quaternion transform(Quaternion v)
Transforms v and returns the result.

Parameters:
v - the Quaternion to transform.
Returns:
the resulting Quaternion.

multiply

public Matrix3D multiply(Matrix3D m)
Multiplies m (the multiplicand) by this (the multiplier). The order of operations for this is important! Reversing the order will not work the same! In addition, Java will not take care of the ordering for you. You must be very careful to order your operations the way they need to occur!

Parameters:
m - the multiplicand.
Returns:
the resulting Matrix3D.

translate

public Matrix3D translate(Vector v)
Applies a translation transformation and returns the result.

Parameters:
v - the Vector holding values for translation along the three axes.
Returns:
the resulting Matrix3D. This one isn't modified.

scale

public Matrix3D scale(Vector v)
Applies a scale transformation and returns the result.

Parameters:
v - the Vector containing scaling factors for the three axes.
Returns:
the resulting Matrix3D. This one isn't modified.

scale

public Matrix3D scale(Real s)
Applies a scale transformation and returns the result.

Parameters:
s - the scaling factor for all three axes.
Returns:
the resulting Matrix3D. This one isn't modified.

scale

public Matrix3D scale(Real x,
                      Real y,
                      Real z)
Applies a scale transformation and returns the result.

Parameters:
x - the scaling factor along the X axis.
y - the scaling factor along the Y axis.
z - the scaling factor along the Z axis.
Returns:
the resulting Matrix3D. This one isn't modified.

rotateX

public Matrix3D rotateX(Real t)
Applies a rotation transformation and returns the result.

Parameters:
t - the angle of rotation used to rotate around the X axis.
Returns:
the resulting Matrix3D. This one isn't modified.

rotateY

public Matrix3D rotateY(Real t)
Applies a rotation transformation and returns the result.

Parameters:
t - the angle of rotation used to rotate around the Y axis.
Returns:
the resulting Matrix3D. This one isn't modified.

rotateZ

public Matrix3D rotateZ(Real t)
Applies a rotation transformation and returns the result.

Parameters:
t - the angle of rotation used to rotate around the Z axis.
Returns:
the resulting Matrix3D. This one isn't modified.

rotate

public Matrix3D rotate(Vector v)
Applies a rotation transformation and returns the result.

Parameters:
v - the Vector representing the rotation.
Returns:
the resulting Matrix3D. This one isn't modified.

rotate

public Matrix3D rotate(Quaternion q)
Applies a rotation transformation and returns the result.

Parameters:
q - the Quaternion representing the rotation.
Returns:
the resulting Matrix3D. This one isn't modified.

applyPerspective

public Matrix3D applyPerspective(Real d)
Applies a perspective transformation and returns the result.

Parameters:
d - the distance from the viewpoint to the viewpane.
Returns:
the resulting Matrix3D. This one isn't modified.

toFloatArray

public float[] toFloatArray()

toDoubleArray

public double[] toDoubleArray()

toString

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

translationMatrix

public static Matrix3D translationMatrix(Vector v)
Constructs a translation Matrix3D.

Parameters:
v - the Vector to translate by.
Returns:
the Matrix3D.

scalingMatrix

public static Matrix3D scalingMatrix(Real s)
Constructs a scaling Matrix3D.

Parameters:
s - the scaling factor all three axes.
Returns:
the Matrix3D.

scalingMatrix

public static Matrix3D scalingMatrix(Vector v)
Constructs a scaling Matrix3D.

Parameters:
v - the scaling Vector with factors for the three axes.
Returns:
the Matrix3D.

scalingMatrix

public static Matrix3D scalingMatrix(Real vx,
                                     Real vy,
                                     Real vz)
Constructs a scaling Matrix3D.

Parameters:
vx - the scaling factor along the X axis.
vy - the scaling factor along the Y axis.
vz - the scaling factor along the Z axis.
Returns:
the Matrix3D.

xRotationMatrix

public static Matrix3D xRotationMatrix(Real t)
Constructs a rotation Matrix3D for rotating around the X axis.

Parameters:
t - (short for theta) the angle of rotation.
Returns:
the Matrix3D.

yRotationMatrix

public static Matrix3D yRotationMatrix(Real t)
Constructs a rotation Matrix3D for rotating around the Y axis.

Parameters:
t - (short for theta) the angle of rotation.
Returns:
the Matrix3D.

zRotationMatrix

public static Matrix3D zRotationMatrix(Real t)
Constructs a rotation Matrix3D for rotating around the Z axis.

Parameters:
t - (short for theta) the angle of rotation.
Returns:
the Matrix3D.

perspectiveMatrix

public static Matrix3D perspectiveMatrix(Real d)
Constructs a perspective transformation Matrix3D.

Parameters:
d - the distance from the viewpoint and the viewing plane.
Returns:
the Matrix3D.

rotationMatrix

public static Matrix3D rotationMatrix(Vector v)
Constructs a rotation Matrix3D for v. Each component of v describes how much to rotate azround it's axis.

Parameters:
v - the Vector describing a 3D rotation.
Returns:
the Matrix3D.

rotationMatrix

public static Matrix3D rotationMatrix(Quaternion q)
Constructs a rotation Matrix3D for q.

Parameters:
q - the Quaternion being used to represent a 3D rotation.
Returns:
the Matrix3D.

identity

public static Matrix3D identity()
Provides an identity Matrix3D. This will return the same Matrix3D until MathUtil.setType(String) is called.

Returns:
the Matrix3D.