Package com.jme3.math
Class Matrix3f
java.lang.Object
com.jme3.math.Matrix3f
- All Implemented Interfaces:
Serializable
,Cloneable
A 3x3 matrix composed of 9 single-precision elements, used to represent
linear transformations of 3-D coordinates, such as rotations, reflections,
and scaling.
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.
- See Also:
-
Field Summary
Modifier and TypeFieldDescriptionstatic final Matrix3f
Shared instance of the identity matrix (diagonals = 1, other elements = 0).protected float
The element in row 0, column 0.protected float
The element in row 0, column 1.protected float
The element in row 0, column 2.protected float
The element in row 1, column 0.protected float
The element in row 1, column 1.protected float
The element in row 1, column 2.protected float
The element in row 2, column 0.protected float
The element in row 2, column 1.protected float
The element in row 2, column 2.static final Matrix3f
Shared instance of the all-zero matrix. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionclone()
Creates a copy.float
Returns the determinant.boolean
Tests for exact equality with the argument, distinguishing -0 from 0.void
Configures from the specified column vectors.float
get
(int i, int j) Returns the element at the specified position.int
hashCode()
Returns a hash code.Returns the multiplicative inverse in the specified storage.boolean
Tests for exact identity.void
Configures as an identity matrix (diagonals = 1, other elements = 0).Multiplies with the specified matrix and returns the product in a 3rd matrix.Applies the linear transformation to specified vector and stores the result in another vector.multLocal
(float scale) Multiplies by the scalar argument and returns the (modified) current instance.set
(int i, int j, float value) Sets the specified element.Copies the matrix argument.set
(Quaternion quaternion) Configures as a rotation matrix equivalent to the argument.toString()
Returns a string representation of the matrix, which is unaffected.zero()
Sets all elements to zero.
-
Field Details
-
m00
protected float m00The element in row 0, column 0. -
m01
protected float m01The element in row 0, column 1. -
m02
protected float m02The element in row 0, column 2. -
m10
protected float m10The element in row 1, column 0. -
m11
protected float m11The element in row 1, column 1. -
m12
protected float m12The element in row 1, column 2. -
m20
protected float m20The element in row 2, column 0. -
m21
protected float m21The element in row 2, column 1. -
m22
protected float m22The element in row 2, column 2. -
ZERO
Shared instance of the all-zero matrix. Do not modify! -
IDENTITY
Shared instance of the identity matrix (diagonals = 1, other elements = 0). Do not modify!
-
-
Constructor Details
-
Matrix3f
public Matrix3f()Instantiates an identity matrix (diagonals = 1, other elements = 0). -
Matrix3f
public 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.- Parameters:
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 2
-
-
Method Details
-
set
Copies the matrix argument. If the argument is null, the current instance is set to identity (diagonals = 1, other elements = 0).- Parameters:
matrix
- the matrix to copy (unaffected) or null for identity- Returns:
- the (modified) current instance (for chaining)
-
get
public float get(int i, int j) Returns the element at the specified position. The matrix is unaffected.- Parameters:
i
- the row index (0, 1, or 2)j
- the column index (0, 1, or 2)- Returns:
- the value of the element at (i, j)
- Throws:
IllegalArgumentException
- if either index isn't 0, 1, or 2
-
set
Sets the specified element.- Parameters:
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)- Returns:
- the (modified) current instance (for chaining)
- Throws:
IllegalArgumentException
- if either index isn't 0, 1, or 2
-
fromAxes
Configures from the specified column vectors. If the vectors form an orthonormal basis, the result will be a pure rotation matrix.- Parameters:
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)
-
set
Configures as a rotation matrix equivalent to the argument.- Parameters:
quaternion
- the input quaternion (not null, unaffected)- Returns:
- the (modified) current instance (for chaining)
-
loadIdentity
public void loadIdentity()Configures as an identity matrix (diagonals = 1, other elements = 0). -
isIdentity
public boolean isIdentity()Tests for exact identity. The matrix is unaffected.- Returns:
- true if all diagonals = 1 and all other elements = 0 or -0, otherwise false
-
mult
Multiplies with the specified matrix and returns the product in a 3rd matrix. The current instance is unaffected unless it'sproduct
.Note that matrix multiplication is noncommutative, so generally q * p != p * q.
It is safe for
mat
andproduct
to be the same object.- Parameters:
mat
- the right factor (not null, unaffected unless it'sproduct
)product
- storage for the product, or null for a new Matrix3f- Returns:
this
timesmat
(eitherproduct
or a new Matrix3f)
-
mult
Applies the linear transformation to specified vector and stores the result in another vector. The matrix is unaffected.This can also be described as multiplying the matrix by a column vector.
It is safe for
vec
andproduct
to be the same object.- Parameters:
vec
- the coordinates to transform (not null, unaffected unless it'sproduct
)product
- storage for the result, or null for a new Vector3f- Returns:
- either
product
or a new Vector3f
-
multLocal
Multiplies by the scalar argument and returns the (modified) current instance.- Parameters:
scale
- the scaling factor- Returns:
- the (modified) current instance (for chaining)
-
invert
Returns the multiplicative inverse in the specified storage. If the current instance is singular, an all-zero matrix is returned. In either case, the current instance is unaffected.If
this
andstore
are the same object, the result is undefined.- Parameters:
store
- storage for the result, or null for a new Matrix3f- Returns:
- either
store
or a new Matrix3f
-
determinant
public float determinant()Returns the determinant. The matrix is unaffected.- Returns:
- the determinant
-
zero
Sets all elements to zero.- Returns:
- the (modified) current instance (for chaining)
-
toString
Returns a string representation of the matrix, which is unaffected. For example, the identity matrix is represented by:Matrix3f [ 1.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 1.0 ]
-
hashCode
public int hashCode()Returns a hash code. If two matrices have identical values, they will have the same hash code. The matrix is unaffected. -
equals
Tests for exact equality with the argument, distinguishing -0 from 0. Ifo
is null, false is returned. Either way, the current instance is unaffected. -
clone
Creates a copy. The current instance is unaffected.
-