public final class Matrix4f extends java.lang.Object implements Savable, java.lang.Cloneable, java.io.Serializable
Matrix4f
represents a single-precision 4x4 matrix for use as a
3-D coordinate transform or perspective transform. It provides convenience
methods for loading data from many sources.
The rightmost column (column 3) stores the translation vector. Element
numbering is (row,column), so m03 is the row 0, column 3, which is the X
translation. This means that the implicit storage order is column-major.
However, the get() and set() functions on float arrays default to row-major
order!Modifier and Type | Field and Description |
---|---|
static Matrix4f |
IDENTITY
an instance of the identity matrix (diagonals = 1, other elements = 0)
|
float |
m00
the element in row 0, column 0
|
float |
m01
the element in row 0, column 1
|
float |
m02
the element in row 0, column 2
|
float |
m03
the element in row 0, column 3 (the X translation)
|
float |
m10
the element in row 1, column 0
|
float |
m11
the element in row 1, column 1
|
float |
m12
the element in row 1, column 2
|
float |
m13
the element in row 1, column 3 (the Y translation)
|
float |
m20
the element in row 2, column 0
|
float |
m21
the element in row 2, column 1
|
float |
m22
the element in row 2, column 2
|
float |
m23
the element in row 2, column 3 (the Z translation)
|
float |
m30
the element in row 3, column 0
|
float |
m31
the element in row 3, column 1
|
float |
m32
the element in row 3, column 2
|
float |
m33
the element in row 3, column 3
|
static Matrix4f |
ZERO
an instance of the zero matrix (all elements = 0)
|
Constructor and Description |
---|
Matrix4f()
Create a
Matrix4f initialized to identity (diagonals = 1,
other elements = 0). |
Matrix4f(float[] array)
Create a
Matrix4f from the specified array. |
Matrix4f(float m00,
float m01,
float m02,
float m03,
float m10,
float m11,
float m12,
float m13,
float m20,
float m21,
float m22,
float m23,
float m30,
float m31,
float m32,
float m33)
Create a
Matrix4f with the specified element values. |
Matrix4f(Matrix4f mat)
Create a
Matrix4f that duplicates the specified matrix. |
Modifier and Type | Method and Description |
---|---|
Matrix4f |
add(Matrix4f mat)
Add the specified matrix.
|
void |
addLocal(Matrix4f mat)
Sum in place, with the specified matrix.
|
Matrix4f |
adjoint()
Generate the adjoint.
|
Matrix4f |
adjoint(Matrix4f store)
Generate the adjoint.
|
void |
angleRotation(Vector3f angles)
Load a rotation around three axes (x, y, z).
|
Matrix4f |
clone()
Create a copy.
|
void |
copy(Matrix4f matrix)
Copy all elements of the specified matrix to this matrix.
|
float |
determinant()
Calculate the determinant.
|
boolean |
equals(java.lang.Object o)
Test for equality with the specified object.
|
void |
fillFloatArray(float[] f,
boolean columnMajor)
Copy all elements to a float array.
|
java.nio.FloatBuffer |
fillFloatBuffer(java.nio.FloatBuffer fb)
Copy all elements to an existing FloatBuffer, starting at its current
position, in row-major order.
|
java.nio.FloatBuffer |
fillFloatBuffer(java.nio.FloatBuffer fb,
boolean columnMajor)
Copy all elements to an existing FloatBuffer, starting at its current
position.
|
void |
fromAngleAxis(float angle,
Vector3f axis)
Load a 3-D rotation specified by an angle and axis.
|
void |
fromAngleNormalAxis(float angle,
Vector3f axis)
Load a 3-D rotation specified by an angle and axis.
|
void |
fromFrame(Vector3f location,
Vector3f direction,
Vector3f up,
Vector3f left) |
void |
fromFrustum(float near,
float far,
float left,
float right,
float top,
float bottom,
boolean parallel)
Load a perspective-view transform with the specified clipping planes.
|
void |
get(float[] matrix)
Copy all elements to a float array, in row-major order.
|
void |
get(float[] matrix,
boolean rowMajor)
Copy all elements to a float array.
|
float |
get(int i,
int j)
Retrieve the element at the specified position.
|
float[] |
getColumn(int i)
Copy the specified column to a new float array.
|
float[] |
getColumn(int i,
float[] store)
Copy the specified column to a float array.
|
int |
hashCode()
hashCode returns the hash code value as an integer and is
supported for the benefit of hashing based collection classes such as
Hashtable, HashMap, HashSet etc. |
void |
inverseRotateVect(Vector3f vec)
Inverse rotate the specified Vector3f using the rotation component of
this 3-D coordinate transform.
|
void |
inverseTranslateVect(float[] vec)
Inverse translate the specified vector using the translation component of
this 3-D coordinate transform.
|
void |
inverseTranslateVect(Vector3f data)
Inverse translate the specified Vector3f using the translation component
of this 3-D coordinate transform.
|
Matrix4f |
invert()
Generate the inverse.
|
Matrix4f |
invert(Matrix4f store)
Generate the inverse.
|
Matrix4f |
invertLocal()
Invert in place.
|
boolean |
isIdentity()
Test for exact identity.
|
void |
loadIdentity()
Load identity (diagonals = 1, other elements = 0).
|
Matrix4f |
mult(float scalar)
Multiply by the specified scalar.
|
float[] |
mult(float[] vec4f)
Multiply the specified float array by this matrix.
|
Matrix4f |
mult(float scalar,
Matrix4f store)
Multiply by the specified scalar.
|
Matrix4f |
mult(Matrix4f in2)
Right-multiply by the specified matrix.
|
Matrix4f |
mult(Matrix4f in2,
Matrix4f store)
Right-multiply by the specified matrix.
|
Quaternion |
mult(Quaternion vec,
Quaternion store)
Multiply the specified Quaternion by this matrix.
|
Vector3f |
mult(Vector3f vec)
Apply this 3-D coordinate transform to the specified Vector3f.
|
Vector3f |
mult(Vector3f vec,
Vector3f store)
Apply this 3-D coordinate transform to the specified Vector3f.
|
Vector4f |
mult(Vector4f vec)
Multiply the specified Vector4f by this matrix.
|
Vector4f |
mult(Vector4f vec,
Vector4f store)
Multiply the specified Vector4f by this matrix.
|
float[] |
multAcross(float[] vec4f)
Multiply the specified float array by the transform of this matrix.
|
Vector3f |
multAcross(Vector3f vec,
Vector3f store)
Apply the transform of this 3-D coordinate transform to the specified
Vector3f.
|
Vector4f |
multAcross(Vector4f vec)
Multiply the specified Vector4f by the transform of this matrix.
|
Vector4f |
multAcross(Vector4f vec,
Vector4f store)
Multiply the specified Vector4f by the transform of this matrix.
|
void |
multLocal(float scalar)
Multiply in place, by the specified scalar.
|
Matrix4f |
multLocal(Matrix4f in2)
Right-multiply in place, by the specified matrix.
|
void |
multLocal(Quaternion rotation) |
Vector3f |
multNormal(Vector3f vec,
Vector3f store)
Rotate and scale the specified vector, but don't translate it.
|
Vector3f |
multNormalAcross(Vector3f vec,
Vector3f store)
Rotate and scale the specified vector by the transpose, but don't
translate it.
|
float |
multProj(Vector3f vec,
Vector3f store)
Apply this perspective transform to the specified Vector3f.
|
void |
read(JmeImporter importer)
De-serialize from the specified importer, for example when loading from a
J3O file.
|
Matrix4f |
readFloatBuffer(java.nio.FloatBuffer fb)
Load from the specified FloatBuffer, in row-major order.
|
Matrix4f |
readFloatBuffer(java.nio.FloatBuffer fb,
boolean columnMajor)
Load from the specified FloatBuffer.
|
void |
rotateVect(Vector3f vec)
Rotate the specified Vector3f using the rotation component of this 3-D
coordinate transform.
|
void |
scale(Vector3f scale)
Scale by the specified Vector3f.
|
void |
set(float[] matrix)
Load all elements from the specified array.
|
void |
set(float[][] matrix)
Load all elements from the specified 4x4 array.
|
void |
set(float[] matrix,
boolean rowMajor)
Load all elements from the specified array.
|
void |
set(float m00,
float m01,
float m02,
float m03,
float m10,
float m11,
float m12,
float m13,
float m20,
float m21,
float m22,
float m23,
float m30,
float m31,
float m32,
float m33)
Load the specified element values.
|
void |
set(int i,
int j,
float value)
Store the specified value at the specified position.
|
Matrix4f |
set(Matrix4f matrix)
Copy all elements of the specified matrix to this matrix.
|
void |
setColumn(int i,
float[] column)
Load the specified column from the specified array.
|
void |
setInverseRotationDegrees(float[] angles)
Load an inverted rotation from Euler angles in degrees.
|
void |
setInverseRotationRadians(float[] angles)
Load an inverted rotation from Euler angles in radians.
|
void |
setInverseTranslation(float[] translation)
Alter the inverse-translation component of this 3-D coordinate transform.
|
void |
setRotationQuaternion(Quaternion quat)
Load a rotation from a
Quaternion . |
void |
setScale(float x,
float y,
float z)
Alter the scale component of this 3-D coordinate transform.
|
void |
setScale(Vector3f scale)
Alter the scale component of this 3-D coordinate transform.
|
void |
setTransform(Vector3f position,
Vector3f scale,
Matrix3f rotMat)
Load with the specified coordinate transform.
|
void |
setTranslation(float[] translation)
Alter the translation component of this 3-D coordinate transform.
|
void |
setTranslation(float x,
float y,
float z)
Alter the translation component of this 3-D coordinate transform.
|
void |
setTranslation(Vector3f translation)
Alter the translation component of this 3-D coordinate transform.
|
java.nio.FloatBuffer |
toFloatBuffer()
Copy all elements to a new, direct FloatBuffer.
|
java.nio.FloatBuffer |
toFloatBuffer(boolean columnMajor)
Copy all elements to a new, direct FloatBuffer.
|
Matrix3f |
toRotationMatrix()
Determine the rotation component of this 3-D coordinate transform.
|
void |
toRotationMatrix(Matrix3f mat)
Determine the rotation component of this 3-D coordinate transform.
|
Quaternion |
toRotationQuat()
Determine the rotation component of this 3-D coordinate transform.
|
Quaternion |
toRotationQuat(Quaternion q)
Determine the rotation component of this 3-D coordinate transform.
|
Vector3f |
toScaleVector()
Determine the scale component of this 3-D coordinate transform.
|
Vector3f |
toScaleVector(Vector3f store)
Determine the scale component of this 3-D coordinate transform.
|
java.lang.String |
toString()
Represent as a String.
|
Vector3f |
toTranslationVector()
Determine the translation component of this 3-D coordinate transform.
|
Vector3f |
toTranslationVector(Vector3f vector)
Determine the translation component of this 3-D coordinate transform.
|
void |
translateVect(Vector3f data)
Translate the specified Vector3f using the translation component of this
3-D coordinate transform.
|
Matrix4f |
transpose()
Generate the transpose.
|
Matrix4f |
transposeLocal()
Transpose in place.
|
void |
write(JmeExporter e)
Serialize to the specified exporter, for example when saving to a J3O
file.
|
Matrix4f |
zero()
Set all elements to zero.
|
public float m00
public float m01
public float m02
public float m03
public float m10
public float m11
public float m12
public float m13
public float m20
public float m21
public float m22
public float m23
public float m30
public float m31
public float m32
public float m33
public static final Matrix4f ZERO
public static final Matrix4f IDENTITY
public Matrix4f()
Matrix4f
initialized to identity (diagonals = 1,
other elements = 0).public Matrix4f(float m00, float m01, float m02, float m03, float m10, float m11, float m12, float m13, float m20, float m21, float m22, float m23, float m30, float m31, float m32, float m33)
Matrix4f
with the specified element values.m00
- the desired value for row 0, column 0m01
- the desired value for row 0, column 1m02
- the desired value for row 0, column 2m03
- the desired value for row 0, column 3m10
- the desired value for row 1, column 0m11
- the desired value for row 1, column 1m12
- the desired value for row 1, column 2m13
- the desired value for row 1, column 3m20
- the desired value for row 2, column 0m21
- the desired value for row 2, column 1m22
- the desired value for row 2, column 2m23
- the desired value for row 2, column 3m30
- the desired value for row 3, column 0m31
- the desired value for row 3, column 1m32
- the desired value for row 3, column 2m33
- the desired value for row 3, column 3public Matrix4f(float[] array)
Matrix4f
from the specified array.array
- the source array: 16 floats in column-major order
(translation in elements 12, 13, and 14)public Matrix4f(Matrix4f mat)
Matrix4f
that duplicates the specified matrix. If
null is specified, the new matrix is initialized to identity (diagonals =
1, other elements = 0).mat
- the source matrix (unaffected, may be null)public void copy(Matrix4f matrix)
matrix
- the source matrix (may be null, unaffected)public void get(float[] matrix)
matrix
- the destination array (not null, length=16)public void get(float[] matrix, boolean rowMajor)
matrix
- the destination array (not null, length=16)rowMajor
- true to store in row-major order, false to store in
column-major orderpublic float get(int i, int j)
i
- the row index of the element to retrieve (0, 1, 2, or 3)j
- the column index of the element to retrieve (0, 1, 2, or 3)java.lang.IllegalArgumentException
- if either index is invalid.public float[] getColumn(int i)
i
- the index of the column to copy (0, 1, 2, or 3)public float[] getColumn(int i, float[] store)
i
- the index of the column to copy (0, 1, 2, or 3)store
- storage for the result (modified) or null to create a new
arraypublic void setColumn(int i, float[] column)
i
- the index of the column to fill (0, 1, 2, or 3)column
- the source array (unaffected) or nullpublic void set(int i, int j, float value)
i
- the row index of the element to set (0, 1, 2, or 3)j
- the column index of the element to set (0, 1, 2, or 3)value
- the value for element (i, j)java.lang.IllegalArgumentException
- if either index is invalid.public void set(float[][] matrix)
matrix
- the source array (not null, unaffected)java.lang.IllegalArgumentException
- if the source array isn't 4x4.public void set(float m00, float m01, float m02, float m03, float m10, float m11, float m12, float m13, float m20, float m21, float m22, float m23, float m30, float m31, float m32, float m33)
m00
- the desired value for row 0, column 0m01
- the desired value for row 0, column 1m02
- the desired value for row 0, column 2m03
- the desired value for row 0, column 3m10
- the desired value for row 1, column 0m11
- the desired value for row 1, column 1m12
- the desired value for row 1, column 2m13
- the desired value for row 1, column 3m20
- the desired value for row 2, column 0m21
- the desired value for row 2, column 1m22
- the desired value for row 2, column 2m23
- the desired value for row 2, column 3m30
- the desired value for row 3, column 0m31
- the desired value for row 3, column 1m32
- the desired value for row 3, column 2m33
- the desired value for row 3, column 3public Matrix4f set(Matrix4f matrix)
matrix
- the source matrix (not null, unaffected)public void set(float[] matrix)
matrix
- the source array, in row-major order (not null, length=16,
unaffected)public void set(float[] matrix, boolean rowMajor)
matrix
- the source array (not null, length=16, unaffected)rowMajor
- true if the source array is in row-major order, false if
it's in column-major orderpublic Matrix4f transpose()
public Matrix4f transposeLocal()
public java.nio.FloatBuffer toFloatBuffer()
public java.nio.FloatBuffer toFloatBuffer(boolean columnMajor)
columnMajor
- true to store in column-major order, false to store in
row-major orderpublic java.nio.FloatBuffer fillFloatBuffer(java.nio.FloatBuffer fb)
fb
- the destination buffer (not null, must have space remaining for
16 floats)public java.nio.FloatBuffer fillFloatBuffer(java.nio.FloatBuffer fb, boolean columnMajor)
fb
- the destination buffer (not null, must have space remaining for
16 floats)columnMajor
- true to store in column-major order, false to store in
row-major orderpublic void fillFloatArray(float[] f, boolean columnMajor)
f
- the destination array (not null, length≥16, modified)columnMajor
- true → column-major order, false → row-major
orderpublic Matrix4f readFloatBuffer(java.nio.FloatBuffer fb)
fb
- the source buffer, must have 16 floats remaining to getpublic Matrix4f readFloatBuffer(java.nio.FloatBuffer fb, boolean columnMajor)
fb
- the source buffer, must have 16 floats remaining to getcolumnMajor
- if true, the buffer contains column-major data,
otherwise it contains row-major data.public void loadIdentity()
public void fromFrustum(float near, float far, float left, float right, float top, float bottom, boolean parallel)
near
- the coordinate of the near planefar
- the coordinate of the far planeleft
- the coordinate of the left planeright
- the coordinate of the right planetop
- the coordinate of the top planebottom
- the coordinate of the bottom planeparallel
- true → parallel sides, false → perspectivepublic void fromAngleAxis(float angle, Vector3f axis)
fromAngleNormalAxis(float, com.jme3.math.Vector3f)
instead
because it's more efficient.angle
- the angle to rotate (in radians)axis
- the axis of rotation (not null)public void fromAngleNormalAxis(float angle, Vector3f axis)
angle
- the angle to rotate (in radians)axis
- the axis of rotation (not null, already normalized)public void multLocal(float scalar)
scalar
- the scale factor to apply to all elementspublic Matrix4f mult(float scalar)
scalar
- the scale factor to apply to all elementspublic Matrix4f mult(float scalar, Matrix4f store)
scalar
- the scale factor to apply to all elementsstore
- storage for the result (modified) or null to create a new
matrixpublic Matrix4f mult(Matrix4f in2)
in2
- the right factor (not null, unaffected)public Matrix4f mult(Matrix4f in2, Matrix4f store)
in2
- the right factor (not null)store
- storage for the result (modified) or null to create a new
matrix. It is safe for in2 and store to be the same object.public Matrix4f multLocal(Matrix4f in2)
in2
- the right factor (not null)public Vector3f mult(Vector3f vec)
vec
- the vector to transform (not null)public Vector3f mult(Vector3f vec, Vector3f store)
vec
- the vector to transform (not null)store
- storage for the result (modified) or null to create a new
vectorpublic Vector4f mult(Vector4f vec)
vec
- the vector to multiply (unaffected) or nullpublic Vector4f mult(Vector4f vec, Vector4f store)
vec
- the vector to multiply (unaffected) or nullstore
- storage for the result (modified) or null to create a new
vectorpublic Vector4f multAcross(Vector4f vec)
vec
- the vector to multiply (unaffected) or nullpublic Vector4f multAcross(Vector4f vec, Vector4f store)
vec
- the vector to multiply (unaffected) or nullstore
- storage for the result (modified) or null to create a new
vectorpublic Vector3f multNormal(Vector3f vec, Vector3f store)
vec
- the vector to transform (not null, unaffected)store
- storage for the result (modified) or null to create a new
vectorpublic Vector3f multNormalAcross(Vector3f vec, Vector3f store)
vec
- the vector to transform (not null, unaffected)store
- storage for the result (modified) or null to create a new
vectorpublic float multProj(Vector3f vec, Vector3f store)
vec
- the vector to transform (not null, unaffected)store
- storage for the result (not null, modified)public Vector3f multAcross(Vector3f vec, Vector3f store)
vec
- the vector to transform (unaffected) or nullstore
- storage for the result (modified) or null to create a new
vectorpublic Quaternion mult(Quaternion vec, Quaternion store)
vec
- the Quaternion to multiply (unaffected) or nullstore
- storage for the result (modified) or null to create a new
Quaternionpublic float[] mult(float[] vec4f)
vec4f
- the array to multiply or nullpublic float[] multAcross(float[] vec4f)
vec4f
- the array to multiply or nullpublic Matrix4f invert()
public Matrix4f invert(Matrix4f store)
store
- storage for the result (modified) or null to create a new
matrixjava.lang.ArithmeticException
- if cannot be invertedpublic Matrix4f invertLocal()
public Matrix4f adjoint()
public void setTransform(Vector3f position, Vector3f scale, Matrix3f rotMat)
position
- the desired translation (not null, unaffected)scale
- the desired scale factors (not null, unaffected)rotMat
- the desired rotation (not null, unaffected)public Matrix4f adjoint(Matrix4f store)
store
- storage for the result (modified) or null to create a new
matrixpublic float determinant()
public Matrix4f zero()
public Matrix4f add(Matrix4f mat)
mat
- the matrix to add (not null)public void addLocal(Matrix4f mat)
mat
- the matrix to add (not null)public Vector3f toTranslationVector()
public Vector3f toTranslationVector(Vector3f vector)
vector
- storage for the result (not null, modified)public Quaternion toRotationQuat()
public Quaternion toRotationQuat(Quaternion q)
q
- storage for the result (not null, modified)public Matrix3f toRotationMatrix()
public void toRotationMatrix(Matrix3f mat)
mat
- storage for the result (not null, modified)public Vector3f toScaleVector()
public Vector3f toScaleVector(Vector3f store)
store
- storage for the result (not null, modified)public void setScale(float x, float y, float z)
x
- the desired scale factor for the X axisy
- the desired scale factor for the Y axisz
- the desired scale factor for the Z axispublic void setScale(Vector3f scale)
scale
- the desired scale factors (not null, unaffected)public void setTranslation(float[] translation)
translation
- the desired translation (not null, length=3,
unaffected)java.lang.IllegalArgumentException
- if translation doesn't have length=3.public void setTranslation(float x, float y, float z)
x
- the desired X-axis offsety
- the desired Y-axis offsetz
- the desired Z-axis offsetpublic void setTranslation(Vector3f translation)
translation
- the desired translation (not null, unaffected)public void setInverseTranslation(float[] translation)
translation
- the desired inverse translation (not null, length=3,
unaffected)java.lang.IllegalArgumentException
- if translation doesn't have length=3.public void angleRotation(Vector3f angles)
Vector3f
object.angles
- the desired rotation angles for each axis (in degrees)public void setRotationQuaternion(Quaternion quat)
Quaternion
.quat
- the desired rotation (not null, unaffected)java.lang.NullPointerException
- if quat is null.public void setInverseRotationRadians(float[] angles)
angles
- the desired Euler angles (in radians, not null, length=3)java.lang.IllegalArgumentException
- if angles doesn't have length=3.public void setInverseRotationDegrees(float[] angles)
angles
- the desired Euler angles (in degrees, not null, length=3)java.lang.IllegalArgumentException
- if angles doesn't have length=3.public void inverseTranslateVect(float[] vec)
vec
- the vector to translate (not null, length=3, modified)java.lang.IllegalArgumentException
- if vec doesn't have length=3.public void inverseTranslateVect(Vector3f data)
data
- the Vector3f to translate (not null, modified)public void translateVect(Vector3f data)
data
- the Vector3f to translate (not null, modified)public void inverseRotateVect(Vector3f vec)
vec
- the Vector3f to inverse rotate (not null, modified)public void rotateVect(Vector3f vec)
vec
- the Vector3f to rotate (not null, modified)public java.lang.String toString()
Matrix4f [ 1.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0 1.0 ]
toString
in class java.lang.Object
public int hashCode()
hashCode
returns the hash code value as an integer and is
supported for the benefit of hashing based collection classes such as
Hashtable, HashMap, HashSet etc.hashCode
in class java.lang.Object
Object.hashCode()
public boolean equals(java.lang.Object o)
equals
in class java.lang.Object
o
- the object to compare, or nullpublic void write(JmeExporter e) throws java.io.IOException
public void read(JmeImporter importer) throws java.io.IOException
public boolean isIdentity()
public void scale(Vector3f scale)
scale
- the scale factors to applypublic void multLocal(Quaternion rotation)
public Matrix4f clone()
clone
in class java.lang.Object