Package com.jme3.math

Class Matrix4f

java.lang.Object
com.jme3.math.Matrix4f
All Implemented Interfaces:
Cloneable

public final class Matrix4f extends Object implements Cloneable
A 4x4 matrix composed of 16 single-precision elements, used to represent linear or perspective transformations of 3-D coordinates.

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.

Methods with names ending in "Local" modify the current instance. They are used to avoid creating garbage.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    float
    The element in row 0, column 0.
    float
    The element in row 0, column 1.
    float
    The element in row 0, column 2.
    float
    The element in row 0, column 3 (the X translation).
    float
    The element in row 1, column 0.
    float
    The element in row 1, column 1.
    float
    The element in row 1, column 2.
    float
    The element in row 1, column 3 (the Y translation).
    float
    The element in row 2, column 0.
    float
    The element in row 2, column 1.
    float
    The element in row 2, column 2.
    float
    The element in row 2, column 3 (the Z translation).
    float
    The element in row 3, column 0.
    float
    The element in row 3, column 1.
    float
    The element in row 3, column 2.
    float
    The element in row 3, column 3.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Instantiates an identity matrix (diagonals = 1, other elements = 0).
  • Method Summary

    Modifier and Type
    Method
    Description
    Creates a copy.
    boolean
    Tests for exact equality with the argument, distinguishing -0 from 0.
    int
    Returns a hash code.
    Inverts in place.
    void
    Configures as an identity matrix (diagonals = 1, other elements = 0).
    void
    multLocal(float scalar)
    Multiplies in place by the scalar argument.
    void
    setScale(float x, float y, float z)
    Alters the scale component of the coordinate transform.
    void
    Alters the scale component of the coordinate transform.
    void
    setTranslation(Vector3f translation)
    Alters the translation component of the coordinate transform.
    void
    Determines the rotation component of the coordinate transform.
    Returns the rotation component of the coordinate transform.
    Determines the scale component of the coordinate transform.
    Returns a string representation of the matrix, which is unaffected.
    Returns the translation component of the coordinate transform.
    Sets all elements to zero.

    Methods inherited from class java.lang.Object

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

    • m00

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

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

      public float m02
      The element in row 0, column 2.
    • m03

      public float m03
      The element in row 0, column 3 (the X translation).
    • m10

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

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

      public float m12
      The element in row 1, column 2.
    • m13

      public float m13
      The element in row 1, column 3 (the Y translation).
    • m20

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

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

      public float m22
      The element in row 2, column 2.
    • m23

      public float m23
      The element in row 2, column 3 (the Z translation).
    • m30

      public float m30
      The element in row 3, column 0.
    • m31

      public float m31
      The element in row 3, column 1.
    • m32

      public float m32
      The element in row 3, column 2.
    • m33

      public float m33
      The element in row 3, column 3.
  • Constructor Details

    • Matrix4f

      public Matrix4f()
      Instantiates an identity matrix (diagonals = 1, other elements = 0).
  • Method Details

    • loadIdentity

      public void loadIdentity()
      Configures as an identity matrix (diagonals = 1, other elements = 0).
    • multLocal

      public void multLocal(float scalar)
      Multiplies in place by the scalar argument.
      Parameters:
      scalar - the scaling factor to apply to all elements
    • invertLocal

      public Matrix4f invertLocal()
      Inverts in place. If the current instance is singular, the matrix is zeroed.
      Returns:
      the (inverted) current instance (for chaining)
    • zero

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

      public Vector3f toTranslationVector(Vector3f vector)
      Returns the translation component of the coordinate transform.
      Parameters:
      vector - storage for the result (not null, modified)
      Returns:
      the translation component (in vector) for chaining
    • toRotationQuat

      public Quaternion toRotationQuat(Quaternion q)
      Returns the rotation component of the coordinate transform.

      Assumes (but does not verify) that the transform consists entirely of translation, rotation, and positive scaling -- no reflection or shear.

      Parameters:
      q - storage for the result (not null, modified)
      Returns:
      the rotation component (in q) for chaining
    • toRotationMatrix

      public void toRotationMatrix(Matrix3f mat)
      Determines the rotation component of the coordinate transform.

      If the transform includes scaling or reflection or shear, the result might not be a valid rotation matrix.

      Parameters:
      mat - storage for the result (not null, modified)
    • toScaleVector

      public Vector3f toScaleVector(Vector3f store)
      Determines the scale component of the coordinate transform.

      All components of the result will be non-negative, even if the coordinate transform includes reflection.

      Parameters:
      store - storage for the result (not null, modified)
      Returns:
      the scale factors (in store) for chaining
    • setScale

      public void setScale(float x, float y, float z)
      Alters the scale component of the coordinate transform.
      Parameters:
      x - the desired scale factor for the X axis
      y - the desired scale factor for the Y axis
      z - the desired scale factor for the Z axis
    • setScale

      public void setScale(Vector3f scale)
      Alters the scale component of the coordinate transform.
      Parameters:
      scale - the desired scale factors (not null, unaffected)
    • setTranslation

      public void setTranslation(Vector3f translation)
      Alters the translation component of the coordinate transform.
      Parameters:
      translation - the desired translation (not null, unaffected)
    • toString

      public String toString()
      Returns a string representation of the matrix, which is unaffected. For example, the identity matrix is represented by:
       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
       ]
       
      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 Matrix4f clone()
      Creates a copy. The current instance is unaffected.
      Overrides:
      clone in class Object
      Returns:
      a new instance with the same element values