shout3d.math
Class MatUtil

java.lang.Object
  |
  +--shout3d.math.MatUtil

public class MatUtil
extends java.lang.Object

Matrix and rotation Utility Methods


Constructor Summary
MatUtil()
           
 
Method Summary
static void axisToQuat(float[] fromAA, float[] toQuat)
          convert an axis/angle rotation into a quaternion rotation.
static void axisToQuat(float[] fromAA, int fromOffset, float[] toQuat, int toOffset)
          Input is two arrays which may be longer than 4 floats.
static void composeQuats(float[] q1, float[] q2, float[] composedQuat)
          Creates a third quaternion that is equivalent to the first followed by the second
static float dot(float[] v1, float[] v2)
          Calculates the dot product of two 3-vectors or 4-vectors
static float[] getMatrixAlongPath(Node[] path, boolean bottomToTop)
          Gets the matrix equivalent to concatenating all the matrices along the given path.
static void multDirMatrix(float[] mtx, float[] v)
          Transforms a direction by a 4x4 matrix.
static float[] multMatrix44byMatrix44(float[] mat1, float[] mat2)
          Multiplies two 4x4 matrices, stores the result in the first, and returns that first matrix.
static void multVecMatrix(float[] mtx, float[] v)
          Transforms a point by a 4x4 matrix
static float normalize(float[] v)
          Normalizes the given vector.
static void quatToAxis(float[] fromQuat, float[] toAA)
          convert a quaternion rotation into an axis/angle rotation.
static float[] setToIdentityMatrix44(float[] mtx)
          Set a 4x4 matrix to be an identity matrix
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MatUtil

public MatUtil()
Method Detail

setToIdentityMatrix44

public static final float[] setToIdentityMatrix44(float[] mtx)
Set a 4x4 matrix to be an identity matrix
Parameters:
mtx - the transformation matrix

multVecMatrix

public static final void multVecMatrix(float[] mtx,
                                       float[] v)
Transforms a point by a 4x4 matrix
Parameters:
mtx - the transformation matrix
v - the point to transform, answer returned in the point

multDirMatrix

public static final void multDirMatrix(float[] mtx,
                                       float[] v)
Transforms a direction by a 4x4 matrix. Skips the addition of the 4th row, which translates Does NOT normalize the result
Parameters:
mtx - the transformation matrix
v - the direction to transform, answer returned in the point

normalize

public static final float normalize(float[] v)
Normalizes the given vector. Returns the length prior to being normalized.
Parameters:
v - the vector to normalize
Returns:
the length of the vector prior to normalization.

dot

public static final float dot(float[] v1,
                              float[] v2)
Calculates the dot product of two 3-vectors or 4-vectors
Parameters:
v1 - the first vector
v2 - the second vector
Returns:
the dot product

quatToAxis

public static final void quatToAxis(float[] fromQuat,
                                    float[] toAA)
convert a quaternion rotation into an axis/angle rotation. The axis is stored in the 1st three elements, the angle in the fourth Okay to send the same reference in both arguments
Parameters:
fromQuat - the quaternion to convert
toAA - the result axis/angle rotation

axisToQuat

public static final void axisToQuat(float[] fromAA,
                                    float[] toQuat)
convert an axis/angle rotation into a quaternion rotation. The axis is stored in the 1st three elements, the angle in the fourth Okay to send the same reference in both arguments
Parameters:
fromAA - the axis/angle to convert
toQuat - the result quaternion rotation

axisToQuat

public static final void axisToQuat(float[] fromAA,
                                    int fromOffset,
                                    float[] toQuat,
                                    int toOffset)
Input is two arrays which may be longer than 4 floats. fromOffset is location of first of the 4 numbers within fromAA. toOffset is location of first of the 4 numbers wihtin toQuat. Otherwise, behaves same as axisToQuat(fromAA, toQuat)
Parameters:
fromAA - the array in which axis/angle are located.
fromOffset - offset of first index to use within fromAA
toQuat - the array in which the quaternion info is to be placed
toOffset - offset of the first index to fill within toQuat

composeQuats

public static final void composeQuats(float[] q1,
                                      float[] q2,
                                      float[] composedQuat)
Creates a third quaternion that is equivalent to the first followed by the second
Parameters:
q1 - the first quaternion to compose
q2 - the second quaternion to compose
composedQuat - the result of composing q1 and q2

multMatrix44byMatrix44

public static final float[] multMatrix44byMatrix44(float[] mat1,
                                                   float[] mat2)
Multiplies two 4x4 matrices, stores the result in the first, and returns that first matrix. return( mat1 = [mat1][mat2]

getMatrixAlongPath

public static float[] getMatrixAlongPath(Node[] path,
                                         boolean bottomToTop)
Gets the matrix equivalent to concatenating all the matrices along the given path. If bottomToTop is true, then the matrix will transform from the local space at the end of the path to the space at the top of the path. If bottomToTop is false, then the matrix will transform from the space at the top of the path to the local space of the node at the bottom of the path.
Parameters:
the - path along which to calculate the matrix
bottomToTop - whether the matrix transforms from bottom space to top space or vice versa
Returns:
the matrix along the path.