All Implemented Interfaces:
ConstJoltPhysicsObject, Mat44Arg, AutoCloseable, Comparable<JoltPhysicsObject>

public final class Mat44 extends JoltPhysicsObject implements Mat44Arg
A 4x4 matrix composed of 16 single-precision elements, used to represent transformations of 3-D coordinates.
  • Constructor Details

    • Mat44

      public Mat44()
      Instantiate an uninitialized matrix.
    • Mat44

      public Mat44(float... elementArray)
      Instantiate a matrix with the specified elements.
      Parameters:
      elementArray - in column-major order (not null)
    • Mat44

      public Mat44(Mat44Arg original)
      Instantiate a copy of the specified matrix.
      Parameters:
      original - the matrix to duplicate (not null, unaffected)
    • Mat44

      public Mat44(RMat44Arg rMatrix)
      Instantiate from a location-transform matrix.
      Parameters:
      rMatrix - the matrix to copy (not null, unaffected)
    • Mat44

      public Mat44(Vec4Arg c1, Vec4Arg c2, Vec4Arg c3, Vec4Arg c4)
      Instantiate a matrix with the specified columns.
      Parameters:
      c1 - the desired first/leftmost column (not null, unaffected)
      c2 - the desired 2nd column (not null, unaffected)
      c3 - the desired 3rd column (not null, unaffected)
      c4 - the desired 4th/rightmost column (not null, unaffected)
  • Method Details

    • leftMultiplyInPlace

      public void leftMultiplyInPlace(Mat44Arg leftFactor)
      Left-multiply the current matrix by the argument.
      Parameters:
      leftFactor - the left factor (not null, unaffected)
    • loadIdentity

      public void loadIdentity()
      Set the current matrix to identity.
    • product

      public static Mat44 product(Mat44Arg... mArray)
      Return the product of the specified matrices.
      Parameters:
      mArray - an array of input matrices (not null, unaffected)
      Returns:
      a new matrix
    • rightMultiplyInPlace

      public void rightMultiplyInPlace(Mat44Arg rightFactor)
      Right-multiply the current matrix by the argument.
      Parameters:
      rightFactor - the right factor (not null, unaffected)
    • set

      public void set(Mat44Arg source)
      Copy all elements of the argument to the current matrix.
      Parameters:
      source - the matrix to copy (not null, unaffected)
    • setAxisX

      public void setAxisX(Vec3Arg vec)
      Set the first column to the specified vector.
      Parameters:
      vec - the vector to use (not null, unaffected)
    • setAxisY

      public void setAxisY(Vec3Arg vec)
      Set the 2nd column to the specified vector.
      Parameters:
      vec - the vector to use (not null, unaffected)
    • setAxisZ

      public void setAxisZ(Vec3Arg vec)
      Set the 3rd column to the specified vector.
      Parameters:
      vec - the vector to use (not null, unaffected)
    • setDiagonal3

      public void setDiagonal3(Vec3Arg vec)
      Set the diagonal to the specified vector.
      Parameters:
      vec - the vector to use (not null, unaffected)
    • setElement

      public void setElement(int row, int column, float value)
      Alter the specified element.
      Parameters:
      row - the zero-origin index of the row (≥0, <4)
      column - the zero-origin index of the column (≥0, <4)
      value - the desired value
    • setTranslation

      public void setTranslation(Vec3Arg offset)
      Alter the translation component.
      Parameters:
      offset - the desired translation (not null, unaffected)
    • sIdentity

      public static Mat44 sIdentity()
      Create an identity matrix.
      Returns:
      a new matrix
    • sRotation

      public static Mat44 sRotation(QuatArg rotation)
      Create a rotation matrix from the specified quaternion.
      Parameters:
      rotation - the rotation quaternion to use (not null, unaffected)
      Returns:
      a new matrix
    • sRotation

      public static Mat44 sRotation(Vec3Arg axis, float angle)
      Create a matrix for the specified rotation.
      Parameters:
      axis - the rotation axis (not null, unaffected)
      angle - the desired rotation angle (in radians)
      Returns:
      a new matrix
    • sRotationTranslation

      public static Mat44 sRotationTranslation(QuatArg rotation, Vec3Arg offset)
      Create a translation-and-rotation matrix.
      Parameters:
      rotation - the amount to rotate (not null, unaffected)
      offset - the amount to translate (not null, unaffected)
      Returns:
      a new matrix
    • sRotationX

      public static Mat44 sRotationX(float angle)
      Create a matrix for the specified X-axis rotation.
      Parameters:
      angle - the rotation angle (in radians)
      Returns:
      a new matrix
    • sRotationY

      public static Mat44 sRotationY(float angle)
      Create a matrix for the specified Y-axis rotation.
      Parameters:
      angle - the rotation angle (in radians)
      Returns:
      a new matrix
    • sRotationZ

      public static Mat44 sRotationZ(float angle)
      Create a matrix for the specified Z-axis rotation.
      Parameters:
      angle - the rotation angle (in radians)
      Returns:
      a new matrix
    • sScale

      public static Mat44 sScale(float factor)
      Create a uniform scaling matrix.
      Parameters:
      factor - the amount to scale each axis
      Returns:
      a new matrix
    • sScale

      public static Mat44 sScale(Float3 factors)
      Create a pure scaling matrix.
      Parameters:
      factors - the amount to scale each axis (not null, unaffected)
      Returns:
      a new matrix
    • sScale

      public static Mat44 sScale(Vec3Arg factors)
      Create a pure scaling matrix.
      Parameters:
      factors - the amount to scale each axis (not null, unaffected)
      Returns:
      a new matrix
    • sTranslation

      public static Mat44 sTranslation(Vec3Arg offset)
      Create a pure translation matrix.
      Parameters:
      offset - the amount to translate (not null, unaffected)
      Returns:
      a new matrix
    • sZero

      public static Mat44 sZero()
      Create an all-zero matrix.
      Returns:
      a new matrix
    • getAxisX

      public Vec3 getAxisX()
      Copy the first column to a Vec3. The matrix is unaffected.
      Specified by:
      getAxisX in interface Mat44Arg
      Returns:
      a new vector
    • getAxisY

      public Vec3 getAxisY()
      Copy the 2nd column to a Vec3. The matrix is unaffected.
      Specified by:
      getAxisY in interface Mat44Arg
      Returns:
      a new vector
    • getAxisZ

      public Vec3 getAxisZ()
      Copy the 3rd column to a Vec3. The matrix is unaffected.
      Specified by:
      getAxisZ in interface Mat44Arg
      Returns:
      a new vector
    • getDiagonal3

      public Vec3 getDiagonal3()
      Copy the diagonal elements to a Vec3. The matrix is unaffected.
      Specified by:
      getDiagonal3 in interface Mat44Arg
      Returns:
      a new vector
    • getElement

      public float getElement(int row, int column)
      Return the specified element. The matrix is unaffected.
      Specified by:
      getElement in interface Mat44Arg
      Parameters:
      row - the zero-origin index of the row (≥0, <4)
      column - the zero-origin index of the column (≥0, <4)
      Returns:
      the element's value
    • getQuaternion

      public Quat getQuaternion()
      Convert the rotation to a Quat. The matrix is unaffected.
      Specified by:
      getQuaternion in interface Mat44Arg
      Returns:
      a new rotation quaternion
    • getTranslation

      public Vec3 getTranslation()
      Copy the translation component. The matrix is unaffected.
      Specified by:
      getTranslation in interface Mat44Arg
      Returns:
      a new vector
    • inversed

      public Mat44 inversed()
      Return the inverse of the current matrix, which is unaffected.
      Specified by:
      inversed in interface Mat44Arg
      Returns:
      a new matrix
    • inversed3x3

      public Mat44 inversed3x3()
      Return the inverse of the 3x3 portion. The current matrix is unaffected.
      Specified by:
      inversed3x3 in interface Mat44Arg
      Returns:
      a new matrix
    • inversedRotationTranslation

      public Mat44 inversedRotationTranslation()
      Return the inverse of the current matrix, assuming the current matrix consists entirely of rotation and translation. The current matrix is unaffected.
      Specified by:
      inversedRotationTranslation in interface Mat44Arg
      Returns:
      a new matrix
    • isEqual

      public boolean isEqual(Mat44Arg m2)
      Test whether the current matrix is equal to the argument. The current matrix is unaffected.
      Specified by:
      isEqual in interface Mat44Arg
      Parameters:
      m2 - the 2nd matrix to test (not null, unaffected)
      Returns:
      true if equal, false if unequal
    • isIdentity

      public boolean isIdentity()
      Test whether the current matrix is an identity matrix. The matrix is unaffected.
      Specified by:
      isIdentity in interface Mat44Arg
      Returns:
      true if exactly equal, otherwise false
    • multiply

      public Mat44 multiply(Mat44Arg right)
      Multiply the current matrix by the argument. The current matrix is unaffected.
      Specified by:
      multiply in interface Mat44Arg
      Parameters:
      right - the right factor (not null, unaffected)
      Returns:
      a new matrix
    • multiply3x3

      public Mat44 multiply3x3(Mat44Arg right)
      Multiply the current 3x3 matrix by the specified 3x3 matrix. The current matrix is unaffected.
      Specified by:
      multiply3x3 in interface Mat44Arg
      Parameters:
      right - the right factor (not null, unaffected)
      Returns:
      a new matrix
    • multiply3x3

      public Vec3 multiply3x3(Vec3Arg vec3Arg)
      Multiply the 3x3 matrix by the specified column vector. The matrix is unaffected.
      Specified by:
      multiply3x3 in interface Mat44Arg
      Parameters:
      vec3Arg - the right factor (not null, unaffected)
      Returns:
      a new vector
    • multiply3x3Transposed

      public Vec3 multiply3x3Transposed(Vec3Arg vec3Arg)
      Multiply the transpose of the 3x3 matrix by the specified column vector. The matrix is unaffected.
      Specified by:
      multiply3x3Transposed in interface Mat44Arg
      Parameters:
      vec3Arg - the right factor (not null, unaffected)
      Returns:
      a new vector
    • multiply3x4

      public Vec3 multiply3x4(Vec3Arg vec3Arg)
      Multiply the 3x4 matrix by the specified column vector, with the 4th component of the right factor implied to be one. The matrix is unaffected.
      Specified by:
      multiply3x4 in interface Mat44Arg
      Parameters:
      vec3Arg - the right factor (not null, unaffected)
      Returns:
      a new vector
    • postTranslated

      public Mat44 postTranslated(Vec3Arg vec3)
      Post multiply by the specified translation vector. The current matrix is unaffected.
      Specified by:
      postTranslated in interface Mat44Arg
      Parameters:
      vec3 - the left factor (not null, unaffected)
      Returns:
      a new matrix
    • putColumnMajor

      public void putColumnMajor(FloatBuffer storeBuffer)
      Write all 16 components to the specified buffer in column-major order and advance the buffer's position by 16. The matrix is unaffected.
      Specified by:
      putColumnMajor in interface Mat44Arg
      Parameters:
      storeBuffer - the destination buffer (not null)
    • toString

      public String toString()
      Return a string representation of the matrix, which is unaffected. For example, an identity matrix is represented by:
       Mat44[
        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 JoltPhysicsObject
      Returns:
      the string representation (not null, not empty)