Class Matrix4f
- java.lang.Object
-
- WildMagic.LibFoundation.Mathematics.Matrix4f
-
- All Implemented Interfaces:
java.io.Serializable
public class Matrix4f extends java.lang.Object implements java.io.Serializable
Matrix operations are applied on the left. For example, given a matrix M and a vector V, matrix-times-vector is M*V. That is, V is treated as a column vector. Some graphics APIs use V*M where V is treated as a row vector. In this context the "M" matrix is really a transpose of the M as represented in Wild Magic. Similarly, to apply two matrix operations M0 and M1, in that order, you compute M1*M0 so that the transform of a vector is (M1*M0)*V = M1*(M0*V). Some graphics APIs use M0*M1, but again these matrices are the transpose of those as represented in Wild Magic. You must therefore be careful about how you interface the transformation code with graphics APIS.- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static Matrix4f
IDENTITY
Identity matrix:float
M00
Matrix data:float
M01
Matrix data:float
M02
Matrix data:float
M03
Matrix data:float
M10
float
M11
float
M12
float
M13
float
M20
float
M21
float
M22
float
M23
float
M30
float
M31
float
M32
float
M33
private static long
serialVersionUID
static Matrix4f
ZERO
Zero matrix:
-
Constructor Summary
Constructors Constructor Description Matrix4f()
Create the zero matrix.Matrix4f(boolean bZero)
If bZero is true, create the zero matrix.Matrix4f(float[] afEntry, boolean bRowMajor)
Create a matrix from an array of numbers.Matrix4f(float fM00, float fM01, float fM02, float fM03, float fM10, float fM11, float fM12, float fM13, float fM20, float fM21, float fM22, float fM23, float fM30, float fM31, float fM32, float fM33)
input Mrc is in row r, column c.Matrix4f(Matrix4f rkM)
copy constructor
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Matrix4f
adjoint()
Compute the adjoint of this matrix, setting this: this = Adjoint(this).Matrix4f
copy(Matrix4f rkM)
copy, overwrite this.float
determinant()
Return the determinant of this matrix.boolean
equals(java.lang.Object kObject)
float
get(int iRow, int iCol)
Get member accessvoid
getColumnMajor(float[] afCMajor)
Get member access.void
getData(float[] afData)
Get member access.Matrix4f
identity()
make this the identity matrixMatrix4f
inverse()
Invert a 4x4 using cofactors.static Matrix4f
inverse(Matrix4f kM)
Invert a 4x4 using cofactors.Matrix4f
makeObliqueProjection(Vector3f rkNormal, Vector3f rkPoint, Vector3f rkDirection)
projection matrices onto a specified plane The projection plane is Dot(N,X-P) = 0 where N is a 3-by-1 unit-length normal vector and P is a 3-by-1 point on the plane.Matrix4f
makePerspectiveProjection(Vector3f rkNormal, Vector3f rkPoint, Vector3f rkEye)
+- -+ M = | Dot(N,E-P)*I - E*N^T -(Dot(N,E-P)*I - E*N^T)*E | | -N^t Dot(N,E) | +- -+ where E is the eye point, P is a point on the plane, and N is a unit-length plane normal.Matrix4f
makeReflection(Vector3f rkNormal, Vector3f rkPoint)
reflection matrix through a specified plane +- -+ M = | I-2*N*N^T 2*Dot(N,P)*N | | 0^T 1 | +- -+ where P is a point on the plane and N is a unit-length plane normal.Matrix4f
makeZero()
make this the zero matrixMatrix4f
mult(Matrix4f kM)
Multiply this matrix to the input matrix: this = this * kMstatic Matrix4f
mult(Matrix4f kM1, Matrix4f kM2)
Multiply the two input matrices, setting this: this = kM1 * kM2Vector4f
mult(Vector4f kIn)
matrix times vector: kOut = this * kInvoid
mult(Vector4f kIn, Vector4f kOut)
matrix times vector: kOut = this * kInMatrix4f
multLeft(Matrix4f kM)
Multiply the two input matrices, setting this: this = kM1 * thisVector4f
multLeft(Vector4f kIn)
matrix times vector: v^T * thisvoid
multLeft(Vector4f kIn, Vector4f rkOut)
matrix times vector: v^T * thisVector4f
multRight(Vector4f kIn)
matrix times vector: kOut = this * kInvoid
multRight(Vector4f kIn, Vector4f kOut)
matrix times vector: kOut = this * kInfloat
qForm(Vector4f rkU, Vector4f rkV)
Calculate and return u^T*M*vMatrix4f
set(float fM00, float fM01, float fM02, float fM03, float fM10, float fM11, float fM12, float fM13, float fM20, float fM21, float fM22, float fM23, float fM30, float fM31, float fM32, float fM33)
input Mrc is in row r, column c.Matrix4f
set(int iRow, int iCol, float fValue)
Set member accessMatrix4f
timesTranspose(Matrix4f kM)
Multiply this matrix by transpose of the input matrix, setting this: this = this * M^Tjava.lang.String
toString()
Returns a string representation of the matrix values.Matrix4f
transpose()
Transpose this matrix, setting this, this = this^Tstatic Matrix4f
transpose(Matrix4f kM)
Transpose the input matrix, setting this, this = kM^TMatrix4f
transposeTimes(Matrix4f kM)
Transpose this matrix and multiply by input, setting this: this = this^T * Mstatic Matrix4f
transposeTimes(Matrix4f kM1, Matrix4f kM2)
Transpose M1 and multiply by M2, setting this: this = M1^T * M2
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
- See Also:
- Constant Field Values
-
ZERO
public static final Matrix4f ZERO
Zero matrix:
-
IDENTITY
public static final Matrix4f IDENTITY
Identity matrix:
-
M00
public float M00
Matrix data:
-
M01
public float M01
Matrix data:
-
M02
public float M02
Matrix data:
-
M03
public float M03
Matrix data:
-
M10
public float M10
-
M11
public float M11
-
M12
public float M12
-
M13
public float M13
-
M20
public float M20
-
M21
public float M21
-
M22
public float M22
-
M23
public float M23
-
M30
public float M30
-
M31
public float M31
-
M32
public float M32
-
M33
public float M33
-
-
Constructor Detail
-
Matrix4f
public Matrix4f()
Create the zero matrix.
-
Matrix4f
public Matrix4f(boolean bZero)
If bZero is true, create the zero matrix. Otherwise, create the identity matrix.- Parameters:
bZero
- when true create the zero matrix, othersize create identity.
-
Matrix4f
public Matrix4f(float fM00, float fM01, float fM02, float fM03, float fM10, float fM11, float fM12, float fM13, float fM20, float fM21, float fM22, float fM23, float fM30, float fM31, float fM32, float fM33)
input Mrc is in row r, column c.- Parameters:
fM00
- matrix[0] entryfM01
- matrix[1] entryfM02
- matrix[2] entryfM03
- matrix[3] entryfM10
- matrix[4] entryfM11
- matrix[5] entryfM12
- matrix[6] entryfM13
- matrix[7] entryfM20
- matrix[8] entryfM21
- matrix[9] entryfM22
- matrix[10] entryfM23
- matrix[11] entryfM30
- matrix[12] entryfM31
- matrix[13] entryfM32
- matrix[14] entryfM33
- matrix[15] entry
-
Matrix4f
public Matrix4f(float[] afEntry, boolean bRowMajor)
Create a matrix from an array of numbers. The input array is interpreted based on the Boolean input as true: entry[0..15]={m00,m01,m02,m03,m10,m11,m12,m13,m20,m21,m22, m23,m30,m31,m32,m33} [row major] false: entry[0..15]={m00,m10,m20,m30,m01,m11,m21,m31,m02,m12,m22, m32,m03,m13,m23,m33} [col major]- Parameters:
afEntry
- array of values to put in matrixbRowMajor
- when true copy in row major order.
-
Matrix4f
public Matrix4f(Matrix4f rkM)
copy constructor- Parameters:
rkM
- matrix to copy
-
-
Method Detail
-
adjoint
public Matrix4f adjoint()
Compute the adjoint of this matrix, setting this: this = Adjoint(this).
-
determinant
public float determinant()
Return the determinant of this matrix.- Returns:
- the determinant of this matrix.
-
equals
public boolean equals(java.lang.Object kObject)
- Overrides:
equals
in classjava.lang.Object
-
get
public final float get(int iRow, int iCol)
Get member access- Parameters:
iRow
- row to getiCol
- column to get- Returns:
- value at m_afEntry[iRow*4 + iCol];
-
getColumnMajor
public void getColumnMajor(float[] afCMajor)
Get member access. Copies matrix into input array in Column-Major order.- Parameters:
afCMajor
- copy matrix into array.
-
getData
public void getData(float[] afData)
Get member access. Copies matrix into input array.- Parameters:
afData
- copy matrix into array.
-
inverse
public Matrix4f inverse()
Invert a 4x4 using cofactors. This is faster than using a generic Gaussian elimination because of the loop overhead of such a method. this = this -1
-
inverse
public static Matrix4f inverse(Matrix4f kM)
Invert a 4x4 using cofactors. This is faster than using a generic Gaussian elimination because of the loop overhead of such a method. this = kM -1
-
identity
public Matrix4f identity()
make this the identity matrix
-
makeObliqueProjection
public Matrix4f makeObliqueProjection(Vector3f rkNormal, Vector3f rkPoint, Vector3f rkDirection)
projection matrices onto a specified plane The projection plane is Dot(N,X-P) = 0 where N is a 3-by-1 unit-length normal vector and P is a 3-by-1 point on the plane. The projection is oblique to the plane, in the direction of the 3-by-1 vector D. Necessarily Dot(N,D) is not zero for this projection to make sense. Given a 3-by-1 point U, compute the intersection of the line U+t*D with the plane to obtain t = -Dot(N,U-P)/Dot(N,D). Then projection(U) = P + [I - D*N^T/Dot(N,D)]*(U-P) A 4-by-4 homogeneous transformation representing the projection is +- -+ M = | D*N^T - Dot(N,D)*I -Dot(N,P)D | | 0^T -Dot(N,D) | +- -+ where M applies to [U^T 1]^T by M*[U^T 1]^T. The matrix is chosen so that M[3][3] > 0 whenever Dot(N,D) < 0 (projection is onto the "positive side" of the plane).- Parameters:
rkNormal
- normal vectorrkPoint
- pointrkDirection
- direction vector
-
makePerspectiveProjection
public Matrix4f makePerspectiveProjection(Vector3f rkNormal, Vector3f rkPoint, Vector3f rkEye)
+- -+ M = | Dot(N,E-P)*I - E*N^T -(Dot(N,E-P)*I - E*N^T)*E | | -N^t Dot(N,E) | +- -+ where E is the eye point, P is a point on the plane, and N is a unit-length plane normal.- Parameters:
rkNormal
- normal vectorrkPoint
- pointrkEye
- eye vector
-
makeReflection
public Matrix4f makeReflection(Vector3f rkNormal, Vector3f rkPoint)
reflection matrix through a specified plane +- -+ M = | I-2*N*N^T 2*Dot(N,P)*N | | 0^T 1 | +- -+ where P is a point on the plane and N is a unit-length plane normal.- Parameters:
rkNormal
- normal vectorrkPoint
- point
-
makeZero
public Matrix4f makeZero()
make this the zero matrix
-
mult
public Matrix4f mult(Matrix4f kM)
Multiply this matrix to the input matrix: this = this * kM- Parameters:
kM
- input matrix
-
mult
public static Matrix4f mult(Matrix4f kM1, Matrix4f kM2)
Multiply the two input matrices, setting this: this = kM1 * kM2- Parameters:
kM1
- first input matrixkM2
- second input matrix
-
mult
public void mult(Vector4f kIn, Vector4f kOut)
matrix times vector: kOut = this * kIn- Parameters:
kIn
- input vectorkOut
- output vector = this * v
-
mult
public Vector4f mult(Vector4f kIn)
matrix times vector: kOut = this * kIn- Parameters:
kIn
- input vectorkOut
- output vector = this * v
-
multLeft
public Matrix4f multLeft(Matrix4f kM)
Multiply the two input matrices, setting this: this = kM1 * this- Parameters:
kM
- first input matrix
-
multLeft
public void multLeft(Vector4f kIn, Vector4f rkOut)
matrix times vector: v^T * this- Parameters:
kIn
- vectorrkOut
- vector = kIn^T * this
-
multLeft
public Vector4f multLeft(Vector4f kIn)
matrix times vector: v^T * this- Parameters:
kIn
- vectorrkOut
- vector = kIn^T * this
-
multRight
public void multRight(Vector4f kIn, Vector4f kOut)
matrix times vector: kOut = this * kIn- Parameters:
kIn
- input vectorkOut
- output vector = this * v
-
multRight
public Vector4f multRight(Vector4f kIn)
matrix times vector: kOut = this * kIn- Parameters:
kIn
- input vectorkOut
- output vector = this * v
-
qForm
public float qForm(Vector4f rkU, Vector4f rkV)
Calculate and return u^T*M*v- Parameters:
rkU
- urkV
- v- Returns:
- u^T*M*v
-
set
public Matrix4f set(float fM00, float fM01, float fM02, float fM03, float fM10, float fM11, float fM12, float fM13, float fM20, float fM21, float fM22, float fM23, float fM30, float fM31, float fM32, float fM33)
input Mrc is in row r, column c.- Parameters:
fM00
- matrix[0] entryfM01
- matrix[1] entryfM02
- matrix[2] entryfM03
- matrix[3] entryfM10
- matrix[4] entryfM11
- matrix[5] entryfM12
- matrix[6] entryfM13
- matrix[7] entryfM20
- matrix[8] entryfM21
- matrix[9] entryfM22
- matrix[10] entryfM23
- matrix[11] entryfM30
- matrix[12] entryfM31
- matrix[13] entryfM32
- matrix[14] entryfM33
- matrix[15] entry
-
set
public Matrix4f set(int iRow, int iCol, float fValue)
Set member access- Parameters:
iRow
- row to setiCol
- column to setfValue
- new value
-
timesTranspose
public Matrix4f timesTranspose(Matrix4f kM)
Multiply this matrix by transpose of the input matrix, setting this: this = this * M^T- Parameters:
kM
- matrix
-
toString
public java.lang.String toString()
Returns a string representation of the matrix values.- Overrides:
toString
in classjava.lang.Object
- Returns:
- string representation of the matrix values.
-
transpose
public Matrix4f transpose()
Transpose this matrix, setting this, this = this^T
-
transpose
public static Matrix4f transpose(Matrix4f kM)
Transpose the input matrix, setting this, this = kM^T
-
transposeTimes
public Matrix4f transposeTimes(Matrix4f kM)
Transpose this matrix and multiply by input, setting this: this = this^T * M- Parameters:
kM
- matrix
-
-