com.jme.math
Class TransformMatrix

java.lang.Object
  extended by com.jme.math.TransformMatrix
All Implemented Interfaces:
Savable, java.io.Serializable, java.lang.Cloneable

public class TransformMatrix
extends java.lang.Object
implements java.io.Serializable, Savable, java.lang.Cloneable

TransformMatrix holds a rotation (Matrix3f) and translation (Vector3f) for point manipulation

Author:
Jack Lindamood, Joshua Slack
See Also:
Serialized Form

Constructor Summary
TransformMatrix()
          Constructor instantiates a new TransformMatrix that is set to the identity matrix by default.
TransformMatrix(Quaternion myRot, Vector3f myPos)
          Constructor instantiates a new TransformMatrix that has rotation and translation defined by its parameters
TransformMatrix(TransformMatrix mat)
          Constructor instantiates a new TransformMatrix that is set to the provided matrix.
 
Method Summary
 void applyToSpatial(Spatial spatial)
          Applies this TransformMatrix to the given spatial, by updating the spatial's local translation, rotation, scale.
 TransformMatrix clone()
           
 TransformMatrix combineWithParent(TransformMatrix parent)
          Combines this TransformMatrix with a parent TransformMatrix.
 boolean equals(java.lang.Object oIn)
           
 java.lang.Class<? extends TransformMatrix> getClassTag()
           
 Matrix3f getRotation(Matrix3f rotStore)
          Stores the rotational part of this matrix into the passed matrix.
 Quaternion getRotation(Quaternion rotStore)
          Stores the rotational part of this matrix into the passed Quaternion.
 Vector3f getScale(Vector3f storeS)
          Returns this TransformMatrix's scale factor
 Vector3f getTranslation(Vector3f tranStore)
          Stores the translational part of this matrix into the passed matrix.
 int hashCode()
           
 void interpolateTransforms(TransformMatrix start, TransformMatrix end, float delta)
          Sets this transform to an interpolation between the start and end transforms.
 void interpolateTransforms(TransformMatrix start, TransformMatrix end, float delta, Quaternion q1, Quaternion q2)
          Sets this transform to an interpolation between the start and end transforms.
 void inverse()
          inverse turns this matrix into it's own inverse
 void loadIdentity()
          loadIdentity sets this matrix to the identity matrix, namely all zeros with ones along the diagonal.
 void mult(float scalar)
          Multiplies every value in the matrix by a scalar
 TransformMatrix multLocal(TransformMatrix child, Vector3f tempStore)
          multLocal multiplies this matrix with another matrix and stores the result back in this, returning this.
 Vector3f multNormal(Vector3f vec)
          mult multiplies a normal about a transform matrix and stores the result back in vec.
 Vector3f multPoint(Vector3f vec)
          mult multiplies a vector about a transform matrix.
 void read(JMEImporter e)
           
 void set(Quaternion quaternion)
          set defines the values of the matrix based on a supplied Quaternion (which it does not modify).
 void set(Quaternion rotation, Vector3f translation)
          set changes this matrix's rotational and translational components to that represented by the given parameters, by copying.
 void set(TransformMatrix matrix)
          set copies the contents of a given matrix to this matrix.
 void setEulerRot(float x, float y, float z)
          Sets the rotational component of this transform to the matrix represented by an Euler rotation about x, y, then z.
 void setEulerRot(Vector3f eulerVec)
          setEulerRot is equivalent to setEulerRot(eulerVec.x,eulverVec.y,eulverVec.z){
 void setRotation(Matrix3f rot)
          Sets the rotation matrix to the given rotation matrix via a copy.
 void setRotationQuaternion(Quaternion quat)
          setRotationQuaternion builds a rotation from a Quaternion.
 void setScale(float x, float y, float z)
          Sets this TransformMatrix's scale to the given x,y,z
 void setScale(Vector3f scale)
          Sets this TransformMatrix's scale to the given scale (x,y,z), by copying.
 void setTranslation(float[] transArray)
          setTranslation will set the matrix's translation values.
 void setTranslation(float x, float y, float z)
          Sets the Transform's Translational component
 void setTranslation(Vector3f trans)
          setTranslation will copy the given Vector3f's values into this Matrix's translational component
 java.lang.String toString()
          toString returns the string representation of this object.
 void write(JMEExporter e)
           
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

TransformMatrix

public TransformMatrix()
Constructor instantiates a new TransformMatrix that is set to the identity matrix by default.


TransformMatrix

public TransformMatrix(TransformMatrix mat)
Constructor instantiates a new TransformMatrix that is set to the provided matrix. This constructor copies a given matrix. If the provided matrix is null, the constructor sets the matrix to the identity.

Parameters:
mat - the matrix to copy.

TransformMatrix

public TransformMatrix(Quaternion myRot,
                       Vector3f myPos)
Constructor instantiates a new TransformMatrix that has rotation and translation defined by its parameters

Parameters:
myRot - The given rotation, as a Quaternion
myPos - The given translation, as a Vector3f
Method Detail

set

public void set(TransformMatrix matrix)
set copies the contents of a given matrix to this matrix. If a null matrix is supplied, this matrix is set to the identity matrix.

Parameters:
matrix - the matrix to copy.

set

public void set(Quaternion quaternion)
set defines the values of the matrix based on a supplied Quaternion (which it does not modify). It should be noted that all previous values will be overridden.

Parameters:
quaternion - the quaternion to create a rotational matrix from.

loadIdentity

public void loadIdentity()
loadIdentity sets this matrix to the identity matrix, namely all zeros with ones along the diagonal.


mult

public void mult(float scalar)
Multiplies every value in the matrix by a scalar

Parameters:
scalar -

multLocal

public TransformMatrix multLocal(TransformMatrix child,
                                 Vector3f tempStore)
multLocal multiplies this matrix with another matrix and stores the result back in this, returning this. if null is passed, nothing happens This function changes this matrix to what the child would look like if this were applied as it's parent

Parameters:
child - The matrix to multiply by
tempStore - A temporary Vector3f object for this TransformMatrix to use during the calculation.
Returns:
this matrix after multiplication

interpolateTransforms

public void interpolateTransforms(TransformMatrix start,
                                  TransformMatrix end,
                                  float delta)
Sets this transform to an interpolation between the start and end transforms. Note that this function isn't very efficient as it has to create 2 new Quaternions to do the rotation interpolation

Parameters:
start - Begining transform (delta=0)
end - Ending transform (delta=1)
delta - Value between 0.0 and 1.0 to show which side the transform leans towards

interpolateTransforms

public void interpolateTransforms(TransformMatrix start,
                                  TransformMatrix end,
                                  float delta,
                                  Quaternion q1,
                                  Quaternion q2)
Sets this transform to an interpolation between the start and end transforms. Same as above but doesn't create 2 new Quaternions

Parameters:
start - Begining transform (delta=0)
end - Ending transform (delta=1)
delta - Value between 0.0 and 1.0 to show which side the transform leans towards
q1 - A temporary Quaternion
q2 - Another temporary Quaternion

multNormal

public Vector3f multNormal(Vector3f vec)
mult multiplies a normal about a transform matrix and stores the result back in vec. The resulting vector is returned with translational ignored.

Parameters:
vec - the rotation normal.
Returns:
The given Vector3f, after rotation

multPoint

public Vector3f multPoint(Vector3f vec)
mult multiplies a vector about a transform matrix. The resulting vector is saved in vec and returned.

Parameters:
vec - The point to rotate.
Returns:
The rotated vector.

setRotation

public void setRotation(Matrix3f rot)
Sets the rotation matrix to the given rotation matrix via a copy. If null is supplied, the identity is set

Parameters:
rot - The new rotation

setTranslation

public void setTranslation(float[] transArray)
setTranslation will set the matrix's translation values.

Parameters:
transArray - the new values for the translation.
Throws:
JmeException - if translation is null or not size 3.

setTranslation

public void setTranslation(Vector3f trans)
setTranslation will copy the given Vector3f's values into this Matrix's translational component

Parameters:
trans -

setTranslation

public void setTranslation(float x,
                           float y,
                           float z)
Sets the Transform's Translational component

Parameters:
x - New X translation
y - New Y translation
z - New Z translation

setEulerRot

public void setEulerRot(float x,
                        float y,
                        float z)
Sets the rotational component of this transform to the matrix represented by an Euler rotation about x, y, then z.

Parameters:
x - The X rotation, in radians
y - The Y rotation, in radians
z - The Z rotation, in radians

setRotationQuaternion

public void setRotationQuaternion(Quaternion quat)
setRotationQuaternion builds a rotation from a Quaternion.

Parameters:
quat - The quaternion to build the rotation from.
Throws:
JmeException - if quat is null.

getRotation

public Matrix3f getRotation(Matrix3f rotStore)
Stores the rotational part of this matrix into the passed matrix. Will create a new Matrix3f if given matrix is null. Returns the given matrix after it has been loaded with rotation values, to allow chaining

Parameters:
rotStore - The matrix to store rotation values
Returns:
The given matrix with updated values

getTranslation

public Vector3f getTranslation(Vector3f tranStore)
Stores the translational part of this matrix into the passed matrix. Will create a new Vector3f if given vector is null. Returns the given vector after it has been loaded with translation values, to allow chaining

Parameters:
tranStore - The vector to store translation values
Returns:
The given Vector with updated values

getRotation

public Quaternion getRotation(Quaternion rotStore)
Stores the rotational part of this matrix into the passed Quaternion. Will create a new Quaternion if given quaternion is null. Returns the given Quaternion after it has been loaded with rotation values, to allow chaining

Parameters:
rotStore - The Quat to store translation values
Returns:
The given Vector with updated values

toString

public java.lang.String toString()
toString returns the string representation of this object. It is simply a toString() call of the rotational matrix and the translational vector

Overrides:
toString in class java.lang.Object
Returns:
the string representation of this object.

inverse

public void inverse()
inverse turns this matrix into it's own inverse


setEulerRot

public void setEulerRot(Vector3f eulerVec)
setEulerRot is equivalent to setEulerRot(eulerVec.x,eulverVec.y,eulverVec.z){

Parameters:
eulerVec - A Vector3f representing the new rotation in Euler angles

set

public void set(Quaternion rotation,
                Vector3f translation)
set changes this matrix's rotational and translational components to that represented by the given parameters, by copying.

Parameters:
rotation - The new rotaiton
translation - The new translation

setScale

public void setScale(Vector3f scale)
Sets this TransformMatrix's scale to the given scale (x,y,z), by copying.

Parameters:
scale - The new scale

setScale

public void setScale(float x,
                     float y,
                     float z)
Sets this TransformMatrix's scale to the given x,y,z

Parameters:
x - The x scale
y - The y scale
z - The z scale

getScale

public Vector3f getScale(Vector3f storeS)
Returns this TransformMatrix's scale factor

Parameters:
storeS - The place to store the current scale factor
Returns:
The given scale factor

applyToSpatial

public void applyToSpatial(Spatial spatial)
Applies this TransformMatrix to the given spatial, by updating the spatial's local translation, rotation, scale.

Parameters:
spatial - The spatial to update

combineWithParent

public TransformMatrix combineWithParent(TransformMatrix parent)
Combines this TransformMatrix with a parent TransformMatrix.

Parameters:
parent - The parent matrix.
Returns:
This matrix, after it has been updated by it's parent.

write

public void write(JMEExporter e)
           throws java.io.IOException
Specified by:
write in interface Savable
Throws:
java.io.IOException

read

public void read(JMEImporter e)
          throws java.io.IOException
Specified by:
read in interface Savable
Throws:
java.io.IOException

getClassTag

public java.lang.Class<? extends TransformMatrix> getClassTag()
Specified by:
getClassTag in interface Savable

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

equals

public boolean equals(java.lang.Object oIn)
Overrides:
equals in class java.lang.Object

clone

public TransformMatrix clone()
Overrides:
clone in class java.lang.Object