Class Matrix3f
- All Implemented Interfaces:
- Savable,- Serializable,- Cloneable
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 SummaryFieldsModifier and TypeFieldDescriptionstatic final Matrix3fShared instance of the identity matrix (diagonals = 1, other elements = 0).protected floatThe element in row 0, column 0.protected floatThe element in row 0, column 1.protected floatThe element in row 0, column 2.protected floatThe element in row 1, column 0.protected floatThe element in row 1, column 1.protected floatThe element in row 1, column 2.protected floatThe element in row 2, column 0.protected floatThe element in row 2, column 1.protected floatThe element in row 2, column 2.static final Matrix3fShared instance of the all-zero matrix.
- 
Constructor SummaryConstructorsConstructorDescriptionMatrix3f()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.Instantiates a copy of the matrix argument.
- 
Method SummaryModifier and TypeMethodDescriptionvoidReplaces all 9 elements with their absolute values.adjoint()Returns the adjoint as a new matrix.Returns the adjoint in the specified storage.clone()Creates a copy.floatReturns the determinant.booleanTests for exact equality with the argument, distinguishing -0 from 0.voidfillFloatArray(float[] f, boolean columnMajor) Copies the matrix to the 1st 9 elements of the specified array.fillFloatBuffer(FloatBuffer fb, boolean columnMajor) Copies the matrix to the specified FloatBuffer, starting at its current position.voidfromAngleAxis(float angle, Vector3f axis) Sets all 9 elements to form a pure rotation matrix with the specified rotation angle and axis of rotation.voidfromAngleNormalAxis(float angle, Vector3f axis) Sets all 9 elements to form a rotation matrix with the specified rotation angle and normalized axis of rotation.voidConfigures from the specified column vectors.voidfromStartEndVectors(Vector3f start, Vector3f end) Configures a rotation matrix that rotates the specified start direction to the specified end direction.voidget(float[] data, boolean rowMajor) Copies the matrix to the specified array.floatget(int i, int j) Returns the element at the specified position.getColumn(int i) Returns the specified column.Returns the specified column.getRow(int i) Returns the specified row.Returns the specified row.inthashCode()Returns a hash code.invert()Returns the multiplicative inverse as a new matrix.Returns the multiplicative inverse in the specified storage.Inverts the matrix and returns the (modified) current instance.booleanTests for exact identity.voidConfigures as an identity matrix (diagonals = 1, other elements = 0).Multiplies with the argument matrix and returns the product as a new instance.Multiplies with the specified matrix and returns the product in a 3rd matrix.Applies the linear transformation to the vector argument and returns the result as a new vector.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.Multiplies by the matrix argument and returns the (modified) current instance.Applies the linear transformation to the vector argument and returns the (modified) argument.Normalizes the matrix and returns the result in the argument.Normalizes the matrix and returns the (modified) current instance.voidread(JmeImporter importer) De-serializes from the specified importer, for example when loading from a J3O file.voidScales each column by the corresponding element of the argument.set(float[] matrix) Copies all 9 elements from the array argument, in row-major order.set(float[][] matrix) Copies all 9 elements from the specified 2-dimensional array.set(float[] matrix, boolean rowMajor) Copies all 9 elements from the specified array.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.Sets the specified column.Sets the specified row.Copies the matrix to a new FloatBuffer.toString()Returns a string representation of the matrix, which is unaffected.Transposes the matrix and returns the (modified) current instance.Transposes the matrix and returns the (modified) current instance.Returns the transpose as a new instance.voidwrite(JmeExporter e) Serializes to the specified exporter, for example when saving to a J3O file.zero()Sets all elements to zero.
- 
Field Details- 
m00protected float m00The element in row 0, column 0.
- 
m01protected float m01The element in row 0, column 1.
- 
m02protected float m02The element in row 0, column 2.
- 
m10protected float m10The element in row 1, column 0.
- 
m11protected float m11The element in row 1, column 1.
- 
m12protected float m12The element in row 1, column 2.
- 
m20protected float m20The element in row 2, column 0.
- 
m21protected float m21The element in row 2, column 1.
- 
m22protected float m22The element in row 2, column 2.
- 
ZEROShared instance of the all-zero matrix. Do not modify!
- 
IDENTITYShared instance of the identity matrix (diagonals = 1, other elements = 0). Do not modify!
 
- 
- 
Constructor Details- 
Matrix3fpublic Matrix3f()Instantiates an identity matrix (diagonals = 1, other elements = 0).
- 
Matrix3fpublic 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 0
- m01- the desired value for row 0, column 1
- m02- the desired value for row 0, column 2
- m10- the desired value for row 1, column 0
- m11- the desired value for row 1, column 1
- m12- the desired value for row 1, column 2
- m20- the desired value for row 2, column 0
- m21- the desired value for row 2, column 1
- m22- the desired value for row 2, column 2
 
- 
Matrix3fInstantiates a copy of the matrix argument. If the argument is null, an identity matrix is produced.- Parameters:
- mat- the matrix to copy (unaffected) or null for identity
 
 
- 
- 
Method Details- 
absoluteLocalpublic void absoluteLocal()Replaces all 9 elements with their absolute values.
- 
setCopies 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)
 
- 
getpublic 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
 
- 
getpublic void get(float[] data, boolean rowMajor) Copies the matrix to the specified array. The matrix is unaffected.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. - Parameters:
- 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, ...)
- Throws:
- IndexOutOfBoundsException- if- datadoesn't have 9 or 16 elements
- See Also:
 
- 
normalizeNormalizes the matrix and returns the result in the argument. The current instance is unaffected, unless it'sstore.- Parameters:
- store- storage for the result, or null for a new Matrix3f
- Returns:
- either storeor a new Matrix3f
 
- 
normalizeLocalNormalizes the matrix and returns the (modified) current instance.- Returns:
- the (modified) current instance (for chaining)
 
- 
getColumnReturns the specified column. The matrix is unaffected.If the matrix is a pure rotation, each column contains one of the basis vectors. - Parameters:
- i- the column index (0, 1, or 2)
- Returns:
- a new Vector3f
- Throws:
- IllegalArgumentException- if- iisn't 0, 1, or 2
- See Also:
 
- 
getColumnReturns the specified column. The matrix is unaffected.If the matrix is a pure rotation, each column contains one of the basis vectors. - Parameters:
- i- the column index (0, 1, or 2)
- store- storage for the result, or null for a new Vector3f
- Returns:
- either storeor a new Vector3f
- Throws:
- IllegalArgumentException- if- iisn't 0, 1, or 2
- See Also:
 
- 
getRowReturns the specified row. The matrix is unaffected.- Parameters:
- i- the row index (0, 1, or 2)
- Returns:
- a new Vector3f
- Throws:
- IllegalArgumentException- if- iisn't 0, 1, or 2
 
- 
getRowReturns the specified row. The matrix is unaffected.- Parameters:
- i- the row index (0, 1, or 2)
- store- storage for the result, or null for a new Vector3f
- Returns:
- either storeor a new Vector3f
- Throws:
- IllegalArgumentException- if- iisn't 0, 1, or 2
 
- 
toFloatBufferCopies the matrix to a new FloatBuffer. The matrix is unaffected.- Returns:
- a new, rewound FloatBuffer containing all 9 elements in row-major order (m00, m01, ...)
 
- 
fillFloatBufferCopies the matrix to the specified FloatBuffer, starting at its current position. The matrix is unaffected.- Parameters:
- 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, ...)
- Returns:
- fb, its position advanced by 9
 
- 
fillFloatArraypublic void fillFloatArray(float[] f, boolean columnMajor) Copies the matrix to the 1st 9 elements of the specified array. The matrix is unaffected.- Parameters:
- 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, ...)
- See Also:
 
- 
setColumnSets the specified column.- Parameters:
- i- which column to set (0, 1, or 2)
- column- the desired element values (unaffected) or null for none
- Returns:
- the (modified) current instance (for chaining)
- Throws:
- IllegalArgumentException- if- iisn't 0, 1, or 2
 
- 
setRowSets the specified row.- Parameters:
- i- which row to set (0, 1, or 2)
- row- the desired element values (unaffected) or null for none
- Returns:
- the (modified) current instance (for chaining)
- Throws:
- IllegalArgumentException- if- iisn't 0, 1, or 2
 
- 
setSets 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
 
- 
setCopies all 9 elements from the specified 2-dimensional array.- Parameters:
- matrix- the input array (not null, length=3, the first element having length=3, the other elements having length≥3, unaffected)
- Returns:
- the (modified) current instance (for chaining)
- Throws:
- IllegalArgumentException- if the array is the wrong size
 
- 
fromAxesConfigures 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)
- See Also:
 
- 
setCopies all 9 elements from the array argument, in row-major order.- Parameters:
- matrix- the input array (not null, length=9, unaffected)
- Returns:
- the (modified) current instance (for chaining)
- Throws:
- IllegalArgumentException- if the array has length != 9
 
- 
setCopies all 9 elements from the specified array.- Parameters:
- 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, ...)
- Returns:
- the (modified) current instance (for chaining)
- Throws:
- IllegalArgumentException- if the array has length != 9
 
- 
setConfigures as a rotation matrix equivalent to the argument.- Parameters:
- quaternion- the input quaternion (not null, unaffected)
- Returns:
- the (modified) current instance (for chaining)
 
- 
loadIdentitypublic void loadIdentity()Configures as an identity matrix (diagonals = 1, other elements = 0).
- 
isIdentitypublic 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
 
- 
fromAngleAxisSets all 9 elements to form a pure rotation matrix with the specified rotation angle and axis of rotation. This method creates garbage, so usefromAngleNormalAxis(float, com.jme3.math.Vector3f)if the axis is known to be normalized.- Parameters:
- angle- the desired rotation angle (in radians)
- axis- the desired axis of rotation (not null, unaffected)
 
- 
fromAngleNormalAxisSets all 9 elements to form a rotation matrix with the specified rotation angle and normalized axis of rotation. If the axis might not be normalized, usefromAngleAxis(float, com.jme3.math.Vector3f)instead.- Parameters:
- angle- the desired rotation angle (in radians)
- axis- the desired axis of rotation (not null, length=1, unaffected)
 
- 
multMultiplies with the argument matrix and returns the product as a new instance. The current instance is unaffected.Note that matrix multiplication is noncommutative, so generally q * p != p * q. - Parameters:
- mat- the right factor (not null, unaffected)
- Returns:
- thistimes- mat(a new Matrix3f)
 
- 
multMultiplies 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 matandproductto be the same object.- Parameters:
- mat- the right factor (not null, unaffected unless it's- product)
- product- storage for the product, or null for a new Matrix3f
- Returns:
- thistimes- mat(either- productor a new Matrix3f)
 
- 
multApplies the linear transformation to the vector argument and returns the result as a new vector. The matrix is unaffected.This can also be described as multiplying the matrix by a column vector. - Parameters:
- vec- the coordinates to transform (not null, unaffected)
- Returns:
- a new Vector3f
 
- 
multApplies 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 vecandproductto be the same object.- Parameters:
- vec- the coordinates to transform (not null, unaffected unless it's- product)
- product- storage for the result, or null for a new Vector3f
- Returns:
- either productor a new Vector3f
 
- 
multLocalMultiplies by the scalar argument and returns the (modified) current instance.- Parameters:
- scale- the scaling factor
- Returns:
- the (modified) current instance (for chaining)
 
- 
multLocalApplies the linear transformation to the vector argument and returns the (modified) argument. If the argument is null, null is returned.Despite the name, the current instance is unaffected. - Parameters:
- vec- the vector to transform (modified if not null)
- Returns:
- vecor null
 
- 
multLocalMultiplies by the matrix argument and returns the (modified) current instance.Note that matrix multiplication is noncommutative, so generally q * p != p * q. - Parameters:
- mat- the right factor (not null, unaffected unless it's- this)
- Returns:
- the (modified) current instance
 
- 
transposeLocalTransposes the matrix and returns the (modified) current instance.- Returns:
- the (modified) current instance
 
- 
invertReturns the multiplicative inverse as a new matrix. If the current instance is singular, an all-zero matrix is returned. In either case, the current instance is unaffected.- Returns:
- a new Matrix3f
 
- 
invertReturns 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 thisandstoreare the same object, the result is undefined. UseinvertLocal()instead.- Parameters:
- store- storage for the result, or null for a new Matrix3f
- Returns:
- either storeor a new Matrix3f
 
- 
invertLocalInverts the matrix and returns the (modified) current instance. If the current instance is singular, all elements will be set to zero.- Returns:
- the (modified) current instance (for chaining)
 
- 
adjointReturns the adjoint as a new matrix. The current instance is unaffected.- Returns:
- a new Matrix3f
 
- 
adjointReturns the adjoint in the specified storage. The current instance is unaffected.If thisandstoreare the same object, the result is undefined.- Parameters:
- store- storage for the result, or null for a new Matrix3f
- Returns:
- either storeor a new Matrix3f
 
- 
determinantpublic float determinant()Returns the determinant. The matrix is unaffected.- Returns:
- the determinant
 
- 
zeroSets all elements to zero.- Returns:
- the (modified) current instance (for chaining)
 
- 
transposeTransposes the matrix and returns the (modified) current instance.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() - Returns:
- the (modified) current instance (for chaining)
 
- 
transposeNewReturns the transpose as a new instance. The current instance is unaffected.- Returns:
- a new Matrix3f
 
- 
toStringReturns 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 ] 
- 
hashCodepublic int hashCode()Returns a hash code. If two matrices have identical values, they will have the same hash code. The matrix is unaffected.
- 
equalsTests for exact equality with the argument, distinguishing -0 from 0. Ifois null, false is returned. Either way, the current instance is unaffected.
- 
writeSerializes to the specified exporter, for example when saving to a J3O file. The current instance is unaffected.- Specified by:
- writein interface- Savable
- Parameters:
- e- the exporter to use (not null)
- Throws:
- IOException- from the exporter
 
- 
readDe-serializes from the specified importer, for example when loading from a J3O file.- Specified by:
- readin interface- Savable
- Parameters:
- importer- the importer to use (not null)
- Throws:
- IOException- from the importer
 
- 
fromStartEndVectorsConfigures a rotation matrix that rotates the specified start direction to the specified end direction.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. - Parameters:
- start- the start direction (not null, length=1, unaffected)
- end- the end direction (not null, length=1, unaffected)
 
- 
scaleScales each column by the corresponding element of the argument.- Parameters:
- scale- the scale factors: X scales column 0, Y scales column 1, Z scales column 2 (not null, unaffected)
 
- 
cloneCreates a copy. The current instance is unaffected.
 
-