Package com.jme3.math

Class Matrix3f

java.lang.Object
com.jme3.math.Matrix3f
All Implemented Interfaces:
Serializable, Cloneable

public final class Matrix3f extends Object implements Cloneable, Serializable
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

    Fields
    Modifier and Type
    Field
    Description
    static 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

    Constructors
    Constructor
    Description
    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.
  • Method Summary

    Modifier and Type
    Method
    Description
    Creates a copy.
    float
    Returns the determinant.
    boolean
    Tests for exact equality with the argument, distinguishing -0 from 0.
    void
    fromAxes(Vector3f uAxis, Vector3f vAxis, Vector3f wAxis)
    Configures from the specified column vectors.
    float
    get(int i, int j)
    Returns the element at the specified position.
    int
    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).
    mult(Matrix3f mat, Matrix3f product)
    Multiplies with the specified matrix and returns the product in a 3rd matrix.
    mult(Vector3f vec, Vector3f product)
    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.
    set(Matrix3f matrix)
    Copies the matrix argument.
    set(Quaternion quaternion)
    Configures as a rotation matrix equivalent to the argument.
    Returns a string representation of the matrix, which is unaffected.
    Sets all elements to zero.

    Methods inherited from class java.lang.Object

    finalize, getClass, notify, notifyAll, wait, wait, wait
  • Field Details

    • m00

      protected float m00
      The element in row 0, column 0.
    • m01

      protected float m01
      The element in row 0, column 1.
    • m02

      protected float m02
      The element in row 0, column 2.
    • m10

      protected float m10
      The element in row 1, column 0.
    • m11

      protected float m11
      The element in row 1, column 1.
    • m12

      protected float m12
      The element in row 1, column 2.
    • m20

      protected float m20
      The element in row 2, column 0.
    • m21

      protected float m21
      The element in row 2, column 1.
    • m22

      protected float m22
      The element in row 2, column 2.
    • ZERO

      public static final Matrix3f ZERO
      Shared instance of the all-zero matrix. Do not modify!
    • IDENTITY

      public static final Matrix3f 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 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
  • Method Details

    • set

      public Matrix3f set(Matrix3f matrix)
      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

      public Matrix3f set(int i, int j, float value)
      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

      public void fromAxes(Vector3f uAxis, Vector3f vAxis, Vector3f wAxis)
      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

      public Matrix3f set(Quaternion quaternion)
      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

      public Matrix3f mult(Matrix3f mat, Matrix3f product)
      Multiplies with the specified matrix and returns the product in a 3rd matrix. The current instance is unaffected unless it's 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.

      Parameters:
      mat - the right factor (not null, unaffected unless it's product)
      product - storage for the product, or null for a new Matrix3f
      Returns:
      this times mat (either product or a new Matrix3f)
    • mult

      public Vector3f mult(Vector3f vec, Vector3f product)
      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 and product to 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 product or a new Vector3f
    • multLocal

      public Matrix3f multLocal(float scale)
      Multiplies by the scalar argument and returns the (modified) current instance.
      Parameters:
      scale - the scaling factor
      Returns:
      the (modified) current instance (for chaining)
    • invert

      public Matrix3f invert(Matrix3f store)
      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 and store 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

      public Matrix3f zero()
      Sets all elements to zero.
      Returns:
      the (modified) current instance (for chaining)
    • toString

      public String 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
       ]
       
      Overrides:
      toString in class Object
      Returns:
      the string representation (not null, not empty)
    • 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.
      Overrides:
      hashCode in class Object
      Returns:
      a 32-bit value for use in hashing
      See Also:
    • equals

      public boolean equals(Object o)
      Tests for exact equality with the argument, distinguishing -0 from 0. If o is null, false is returned. Either way, the current instance is unaffected.
      Overrides:
      equals in class Object
      Parameters:
      o - the object to compare (may be null, unaffected)
      Returns:
      true if this and o have identical values, otherwise false
    • clone

      public Matrix3f clone()
      Creates a copy. The current instance is unaffected.
      Overrides:
      clone in class Object
      Returns:
      a new instance, equivalent to the current one