public final class Matrix3f extends java.lang.Object implements Savable, java.lang.Cloneable, java.io.Serializable
Element numbering is (row, column), so m01 is the element in row 0, column 1.
For pure rotations, the Quaternion
class provides a
more efficient representation.
With one exception, the methods with names ending in "Local" modify the current instance. They are used to avoid creating garbage.
Modifier and Type | Field and Description |
---|---|
static Matrix3f |
IDENTITY
Shared instance of the identity matrix (diagonals = 1, other elements =
0).
|
protected float |
m00
The element in row 0, column 0.
|
protected float |
m01
The element in row 0, column 1.
|
protected float |
m02
The element in row 0, column 2.
|
protected float |
m10
The element in row 1, column 0.
|
protected float |
m11
The element in row 1, column 1.
|
protected float |
m12
The element in row 1, column 2.
|
protected float |
m20
The element in row 2, column 0.
|
protected float |
m21
The element in row 2, column 1.
|
protected float |
m22
The element in row 2, column 2.
|
static Matrix3f |
ZERO
Shared instance of the all-zero matrix.
|
Constructor and Description |
---|
Matrix3f()
Instantiates an identity matrix (diagonals = 1, other elements = 0).
|
Matrix3f(float m00,
float m01,
float m02,
float m10,
float m11,
float m12,
float m20,
float m21,
float m22)
Instantiates a matrix with specified elements.
|
Matrix3f(Matrix3f mat)
Instantiates a copy of the matrix argument.
|
Modifier and Type | Method and Description |
---|---|
void |
absoluteLocal()
Replaces all 9 elements with their absolute values.
|
Matrix3f |
adjoint()
Returns the adjoint as a new matrix.
|
Matrix3f |
adjoint(Matrix3f store)
Returns the adjoint in the specified storage.
|
Matrix3f |
clone()
Creates a copy.
|
float |
determinant()
Returns the determinant.
|
boolean |
equals(java.lang.Object o)
Tests for exact equality with the argument, distinguishing -0 from 0.
|
void |
fillFloatArray(float[] f,
boolean columnMajor)
Copies the matrix to the 1st 9 elements of the specified array.
|
java.nio.FloatBuffer |
fillFloatBuffer(java.nio.FloatBuffer fb,
boolean columnMajor)
Copies the matrix to the specified FloatBuffer, starting at its current
position.
|
void |
fromAngleAxis(float angle,
Vector3f axis)
Sets all 9 elements to form a pure rotation matrix with the specified
rotation angle and axis of rotation.
|
void |
fromAngleNormalAxis(float angle,
Vector3f axis)
Sets all 9 elements to form a rotation matrix with the specified rotation
angle and normalized axis of rotation.
|
void |
fromAxes(Vector3f uAxis,
Vector3f vAxis,
Vector3f wAxis)
Configures from the specified column vectors.
|
void |
fromStartEndVectors(Vector3f start,
Vector3f end)
Configures a rotation matrix that rotates the specified start direction
to the specified end direction.
|
void |
get(float[] data,
boolean rowMajor)
Copies the matrix to the specified array.
|
float |
get(int i,
int j)
Returns the element at the specified position.
|
Vector3f |
getColumn(int i)
Returns the specified column.
|
Vector3f |
getColumn(int i,
Vector3f store)
Returns the specified column.
|
Vector3f |
getRow(int i)
Returns the specified row.
|
Vector3f |
getRow(int i,
Vector3f store)
Returns the specified row.
|
int |
hashCode()
Returns a hash code.
|
Matrix3f |
invert()
Returns the multiplicative inverse as a new matrix.
|
Matrix3f |
invert(Matrix3f store)
Returns the multiplicative inverse in the specified storage.
|
Matrix3f |
invertLocal()
Inverts the matrix and returns the (modified) current instance.
|
boolean |
isIdentity()
Tests for exact identity.
|
void |
loadIdentity()
Configures as an identity matrix (diagonals = 1, other elements = 0).
|
Matrix3f |
mult(Matrix3f mat)
Multiplies with the argument matrix and returns the product as a new
instance.
|
Matrix3f |
mult(Matrix3f mat,
Matrix3f product)
Multiplies with the specified matrix and returns the product in a 3rd
matrix.
|
Vector3f |
mult(Vector3f vec)
Applies the linear transformation to the vector argument and returns the
result as a new vector.
|
Vector3f |
mult(Vector3f vec,
Vector3f product)
Applies the linear transformation to specified vector and stores the
result in another vector.
|
Matrix3f |
multLocal(float scale)
Multiplies by the scalar argument and returns the (modified) current
instance.
|
Matrix3f |
multLocal(Matrix3f mat)
Multiplies by the matrix argument and returns the (modified) current
instance.
|
Vector3f |
multLocal(Vector3f vec)
Applies the linear transformation to the vector argument and returns the
(modified) argument.
|
Matrix3f |
normalize(Matrix3f store)
Normalizes the matrix and returns the result in the argument.
|
Matrix3f |
normalizeLocal()
Normalizes the matrix and returns the (modified) current instance.
|
void |
read(JmeImporter importer)
De-serializes from the specified importer, for example when loading from a
J3O file.
|
void |
scale(Vector3f scale)
Scales each column by the corresponding element of the argument.
|
Matrix3f |
set(float[] matrix)
Copies all 9 elements from the array argument, in row-major order.
|
Matrix3f |
set(float[][] matrix)
Copies all 9 elements from the specified 2-dimensional array.
|
Matrix3f |
set(float[] matrix,
boolean rowMajor)
Copies all 9 elements from the specified array.
|
Matrix3f |
set(int i,
int j,
float value)
Sets the specified element.
|
Matrix3f |
set(Matrix3f matrix)
Copies the matrix argument.
|
Matrix3f |
set(Quaternion quaternion)
Configures as a rotation matrix equivalent to the argument.
|
Matrix3f |
setColumn(int i,
Vector3f column)
Sets the specified column.
|
Matrix3f |
setRow(int i,
Vector3f row)
Sets the specified row.
|
java.nio.FloatBuffer |
toFloatBuffer()
Copies the matrix to a new FloatBuffer.
|
java.lang.String |
toString()
Returns a string representation of the matrix, which is unaffected.
|
Matrix3f |
transpose()
Transposes the matrix and returns the (modified) current instance.
|
Matrix3f |
transposeLocal()
Transposes the matrix and returns the (modified) current instance.
|
Matrix3f |
transposeNew()
Returns the transpose as a new instance.
|
void |
write(JmeExporter e)
Serializes to the specified exporter, for example when saving to a J3O
file.
|
Matrix3f |
zero()
Sets all elements to zero.
|
protected float m00
protected float m01
protected float m02
protected float m10
protected float m11
protected float m12
protected float m20
protected float m21
protected float m22
public static final Matrix3f ZERO
public static final Matrix3f IDENTITY
public Matrix3f()
public Matrix3f(float m00, float m01, float m02, float m10, float m11, float m12, float m20, float m21, float m22)
m00
- the desired value for row 0, column 0m01
- the desired value for row 0, column 1m02
- the desired value for row 0, column 2m10
- the desired value for row 1, column 0m11
- the desired value for row 1, column 1m12
- the desired value for row 1, column 2m20
- the desired value for row 2, column 0m21
- the desired value for row 2, column 1m22
- the desired value for row 2, column 2public Matrix3f(Matrix3f mat)
mat
- the matrix to copy (unaffected) or null for identitypublic void absoluteLocal()
public Matrix3f set(Matrix3f matrix)
matrix
- the matrix to copy (unaffected) or null for identitypublic float get(int i, int j)
i
- the row index (0, 1, or 2)j
- the column index (0, 1, or 2)java.lang.IllegalArgumentException
- if either index isn't 0, 1, or 2public void get(float[] data, boolean rowMajor)
If the array has 16 elements, then the matrix is treated as if it contained the 1st 3 rows and 1st 3 columns of a 4x4 matrix.
data
- storage for the elements (not null, length=9 or 16)rowMajor
- true to store the elements in row-major order (m00, m01,
...) or false to store them in column-major order (m00, m10, ...)java.lang.IndexOutOfBoundsException
- if data
doesn't have 9 or 16
elementsfillFloatArray(float[], boolean)
public Matrix3f normalize(Matrix3f store)
store
.store
- storage for the result, or null for a new Matrix3fstore
or a new Matrix3fpublic Matrix3f normalizeLocal()
public Vector3f getColumn(int i)
If the matrix is a pure rotation, each column contains one of the basis vectors.
i
- the column index (0, 1, or 2)java.lang.IllegalArgumentException
- if i
isn't 0, 1, or 2Quaternion.getRotationColumn(int)
public Vector3f getColumn(int i, Vector3f store)
If the matrix is a pure rotation, each column contains one of the basis vectors.
i
- the column index (0, 1, or 2)store
- storage for the result, or null for a new Vector3fstore
or a new Vector3fjava.lang.IllegalArgumentException
- if i
isn't 0, 1, or 2Quaternion.getRotationColumn(int, com.jme3.math.Vector3f)
public Vector3f getRow(int i)
i
- the row index (0, 1, or 2)java.lang.IllegalArgumentException
- if i
isn't 0, 1, or 2public Vector3f getRow(int i, Vector3f store)
i
- the row index (0, 1, or 2)store
- storage for the result, or null for a new Vector3fstore
or a new Vector3fjava.lang.IllegalArgumentException
- if i
isn't 0, 1, or 2public java.nio.FloatBuffer toFloatBuffer()
public java.nio.FloatBuffer fillFloatBuffer(java.nio.FloatBuffer fb, boolean columnMajor)
fb
- storage for the elements (not null, must have space to put 9
more floats)columnMajor
- true to store the elements in column-major order (m00,
m10, ...) or false to store them in row-major order (m00, m01, ...)fb
, its position advanced by 9public void fillFloatArray(float[] f, boolean columnMajor)
f
- storage for the elements (not null, length≥9)columnMajor
- true to store the elements in column-major order (m00,
m10, ...) or false to store them in row-major order (m00, m01, ...)get(float[], boolean)
public Matrix3f setColumn(int i, Vector3f column)
i
- which column to set (0, 1, or 2)column
- the desired element values (unaffected) or null for nonejava.lang.IllegalArgumentException
- if i
isn't 0, 1, or 2public Matrix3f setRow(int i, Vector3f row)
i
- which row to set (0, 1, or 2)row
- the desired element values (unaffected) or null for nonejava.lang.IllegalArgumentException
- if i
isn't 0, 1, or 2public Matrix3f set(int i, int j, float value)
i
- the row index (0, 1, or 2)j
- the column index (0, 1, or 2)value
- desired value for the element at (i, j)java.lang.IllegalArgumentException
- if either index isn't 0, 1, or 2public Matrix3f set(float[][] matrix)
matrix
- the input array (not null, length=3, the first element
having length=3, the other elements having length≥3, unaffected)java.lang.IllegalArgumentException
- if the array is the wrong sizepublic void fromAxes(Vector3f uAxis, Vector3f vAxis, Vector3f wAxis)
uAxis
- the desired value for column 0 (not null, unaffected)vAxis
- the desired value for column 1 (not null, unaffected)wAxis
- the desired value for column 2 (not null, unaffected)Quaternion.fromAxes(com.jme3.math.Vector3f[])
public Matrix3f set(float[] matrix)
matrix
- the input array (not null, length=9, unaffected)java.lang.IllegalArgumentException
- if the array has length != 9public Matrix3f set(float[] matrix, boolean rowMajor)
matrix
- the input array (not null, length=9, unaffected)rowMajor
- true to read the elements in row-major order (m00, m01,
...) or false to read them in column-major order (m00, m10, ...)java.lang.IllegalArgumentException
- if the array has length != 9public Matrix3f set(Quaternion quaternion)
quaternion
- the input quaternion (not null, unaffected)public void loadIdentity()
public boolean isIdentity()
IDENTITY
, otherwise falsepublic void fromAngleAxis(float angle, Vector3f axis)
fromAngleNormalAxis(float, com.jme3.math.Vector3f)
if the axis
is known to be normalized.angle
- the desired rotation angle (in radians)axis
- the desired axis of rotation (not null, unaffected)public void fromAngleNormalAxis(float angle, Vector3f axis)
fromAngleAxis(float, com.jme3.math.Vector3f)
instead.angle
- the desired rotation angle (in radians)axis
- the desired axis of rotation (not null, length=1, unaffected)public Matrix3f mult(Matrix3f mat)
Note that matrix multiplication is noncommutative, so generally q * p != p * q.
mat
- the right factor (not null, unaffected)this
times mat
(a new Matrix3f)public Matrix3f mult(Matrix3f mat, Matrix3f product)
product
.
Note that matrix multiplication is noncommutative, so generally q * p != p * q.
It is safe for mat
and product
to be the same object.
mat
- the right factor (not null, unaffected unless it's product
)product
- storage for the product, or null for a new Matrix3fthis
times mat
(either product
or a new
Matrix3f)public Vector3f mult(Vector3f vec)
This can also be described as multiplying the matrix by a column vector.
vec
- the coordinates to transform (not null, unaffected)public Vector3f mult(Vector3f vec, Vector3f product)
This can also be described as multiplying the matrix by a column vector.
It is safe for vec
and product
to be the same object.
vec
- the coordinates to transform (not null, unaffected unless it's
product
)product
- storage for the result, or null for a new Vector3fproduct
or a new Vector3fpublic Matrix3f multLocal(float scale)
scale
- the scaling factorpublic Vector3f multLocal(Vector3f vec)
Despite the name, the current instance is unaffected.
vec
- the vector to transform (modified if not null)vec
or nullpublic Matrix3f multLocal(Matrix3f mat)
Note that matrix multiplication is noncommutative, so generally q * p != p * q.
mat
- the right factor (not null, unaffected unless it's
this
)public Matrix3f transposeLocal()
public Matrix3f invert()
public Matrix3f invert(Matrix3f store)
If this
and store
are the same object, the result is
undefined. Use invertLocal()
instead.
store
- storage for the result, or null for a new Matrix3fstore
or a new Matrix3fpublic Matrix3f invertLocal()
public Matrix3f adjoint()
public Matrix3f adjoint(Matrix3f store)
If this
and store
are the same object, the result is
undefined.
store
- storage for the result, or null for a new Matrix3fstore
or a new Matrix3fpublic float determinant()
public Matrix3f zero()
public Matrix3f transpose()
This method is inconsistent with JME naming conventions, but has been
preserved for backwards compatibility. To preserve the current instance,
transposeNew()
.
TODO deprecate in favor of transposeLocal()
public Matrix3f transposeNew()
public java.lang.String toString()
Matrix3f [ 1.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 1.0 ]
toString
in class java.lang.Object
public int hashCode()
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 (may be null, unaffected)public void write(JmeExporter e) throws java.io.IOException
public void read(JmeImporter importer) throws java.io.IOException
public void fromStartEndVectors(Vector3f start, Vector3f end)
See Tomas Möller, John F. Hughes "Efficiently Building a Matrix to Rotate One Vector to Another" Journal of Graphics Tools, 4(4):1-4, 1999.
start
- the start direction (not null, length=1, unaffected)end
- the end direction (not null, length=1, unaffected)public void scale(Vector3f scale)
scale
- the scale factors: X scales column 0, Y scales column 1, Z
scales column 2 (not null, unaffected)public Matrix3f clone()
clone
in class java.lang.Object