Package arc.math.geom

Class Mat3D

java.lang.Object
arc.math.geom.Mat3D

public class Mat3D extends Object
Encapsulates a column major 4 by 4 matrix. Like the Vec3 class it allows the chaining of methods by returning a reference to itself. For example:
 Mat3D mat = new Mat3D().trn(position).mul(camera.combined);
 
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
    XX: Typically the unrotated X component for scaling, also the cosine of the angle when rotated on the Y and/or Z axis.
    static final int
    XY: Typically the negative sine of the angle when rotated on the Z axis.
    static final int
    XZ: Typically the sine of the angle when rotated on the Y axis.
    static final int
    XW: Typically the translation of the X component.
    static final int
    YX: Typically the sine of the angle when rotated on the Z axis.
    static final int
    YY: Typically the unrotated Y component for scaling, also the cosine of the angle when rotated on the X and/or Z axis.
    static final int
    YZ: Typically the negative sine of the angle when rotated on the X axis.
    static final int
    YW: Typically the translation of the Y component.
    static final int
    ZX: Typically the negative sine of the angle when rotated on the Y axis.
    static final int
    ZY: Typical the sine of the angle when rotated on the X axis.
    static final int
    ZZ: Typically the unrotated Z component for scaling, also the cosine of the angle when rotated on the X and/or Y axis.
    static final int
    ZW: Typically the translation of the Z component.
    static final int
    WX: Typically the value zero.
    static final int
    WY: Typically the value zero.
    static final int
    WZ: Typically the value zero.
    static final int
    WW: Typically the value one.
    final float[]
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructs an identity matrix
    Mat3D(float[] values)
    Constructs a matrix from the given float array.
    Mat3D(Mat3D matrix)
    Constructs a matrix from the given matrix.
    Mat3D(Quat quat)
    Constructs a rotation matrix from the given Quat.
    Mat3D(Vec3 position, Quat rotation, Vec3 scale)
    Construct a matrix from the given translation, rotation and scale.
  • Method Summary

    Modifier and Type
    Method
    Description
    avg(Mat3D[] t)
    Averages the given transforms and stores the result in this matrix.
    avg(Mat3D[] t, float[] w)
    Averages the given transforms with the given weights and stores the result in this matrix.
    avg(Mat3D other, float w)
    Averages the given transform with this one and stores the result in this matrix.
    cpy()
     
    float
    det()
     
    static float
    det(float[] val)
    Computes the determinante of the given matrix.
    float
     
    void
    extract4x3Matrix(float[] dst)
    Copies the 4x3 upper-left sub-matrix into float array.
    getRotation(Quat rotation)
    Gets the rotation of this matrix.
    getRotation(Quat rotation, boolean normalizeAxes)
    Gets the rotation of this matrix.
    getScale(Vec3 scale)
     
    float
     
    float
     
    float
     
    float
     
    float
     
    float
     
    getTranslation(Vec3 position)
     
    float[]
     
    boolean
     
    idt()
    Sets the matrix to an identity matrix.
    inv()
    Inverts the matrix.
    static boolean
    inv(float[] val)
    Computes the inverse of the given matrix.
    lerp(Mat3D matrix, float alpha)
    Linearly interpolates between this matrix and the given matrix mixing by alpha
    static void
    mul(float[] mata, float[] matb)
    Multiplies the matrix mata with matrix matb, storing the result in mata.
    mul(Mat3D matrix)
    Postmultiplies this matrix with the given matrix, storing the result in this matrix.
    mulLeft(Mat3D matrix)
    Premultiplies this matrix with the given matrix, storing the result in this matrix.
    static void
    mulVec(float[] mat, float[] vec)
    Multiplies the vector with the given matrix.
    static void
    prj(float[] mat, float[] vec)
    Multiplies the vector with the given matrix, performing a division by w.
    static void
    prj(float[] mat, float[] vecs, int offset, int numVecs, int stride)
    Multiplies the vectors with the given matrix, performing a division by w.
    static Vec3
    prj(Vec3 v, Mat3D matrix)
    Multiplies this vector by the given matrix dividing by w, assuming the fourth (w) component of the vector is 1.
    static void
    rot(float[] mat, float[] vec)
    Multiplies the vector with the top most 3x3 sub-matrix of the given matrix.
    static Vec3
    rot(Vec3 v, Mat3D matrix)
    Multiplies this vector by the first three columns of the matrix, essentially only applying rotation and scaling.
    rotate(float axisX, float axisY, float axisZ, float degrees)
    Postmultiplies this matrix with a (counter-clockwise) rotation matrix.
    rotate(Quat rotation)
    Postmultiplies this matrix with a (counter-clockwise) rotation matrix.
    rotate(Vec3 axis, float degrees)
    Postmultiplies this matrix with a (counter-clockwise) rotation matrix.
    rotate(Vec3 v1, Vec3 v2)
    Postmultiplies this matrix by the rotation between two vectors.
    rotateRad(float axisX, float axisY, float axisZ, float radians)
    Postmultiplies this matrix with a (counter-clockwise) rotation matrix.
    rotateRad(Vec3 axis, float radians)
    Postmultiplies this matrix with a (counter-clockwise) rotation matrix.
    scale(float scaleX, float scaleY, float scaleZ)
    Postmultiplies this matrix with a scale matrix.
    scale(Vec3 vec)
     
    scl(float scale)
     
    scl(float x, float y, float z)
     
    scl(Vec3 scale)
     
    set(float[] values)
    Sets the matrix to the given matrix as a float array.
    set(float quaternionX, float quaternionY, float quaternionZ, float quaternionW)
    Sets the matrix to a rotation matrix representing the quaternion.
    set(float translationX, float translationY, float translationZ, float quaternionX, float quaternionY, float quaternionZ, float quaternionW)
    Sets the matrix to a rotation matrix representing the translation and quaternion.
    set(float translationX, float translationY, float translationZ, float quaternionX, float quaternionY, float quaternionZ, float quaternionW, float scaleX, float scaleY, float scaleZ)
    Sets the matrix to a rotation matrix representing the translation and quaternion.
    set(Affine2 affine)
    Sets this matrix to the given affine matrix.
    set(Mat3D matrix)
    Sets the matrix to the given matrix.
    set(Quat quat)
    Sets the matrix to a rotation matrix representing the quaternion.
    set(Vec3 position, Quat orientation)
    Set this matrix to the specified translation and rotation.
    set(Vec3 position, Quat orientation, Vec3 scale)
    Set this matrix to the specified translation, rotation and scale.
    set(Vec3 xAxis, Vec3 yAxis, Vec3 zAxis, Vec3 pos)
    Sets the four columns of the matrix which correspond to the x-, y- and z-axis of the vector space this matrix creates as well as the 4th column representing the translation of any point that is multiplied by this matrix.
    set(Mat mat)
    Sets this matrix to the given 3x3 matrix.
    Assumes that this matrix is a 2D affine transformation, copying only the relevant components.
    Assumes that both matrices are 2D affine transformations, copying only the relevant components.
    setFromEulerAngles(float yaw, float pitch, float roll)
    Sets this matrix to a rotation matrix from the given euler angles.
    setFromEulerAnglesRad(float yaw, float pitch, float roll)
    Sets this matrix to a rotation matrix from the given euler angles.
    setToLookAt(Vec3 direction, Vec3 up)
    Sets the matrix to a look at matrix with a direction and an up vector.
    setToLookAt(Vec3 position, Vec3 target, Vec3 up)
    Sets this matrix to a look at matrix with the given position, target and up vector.
    setToOrtho(float left, float right, float bottom, float top, float near, float far)
    Sets the matrix to an orthographic projection like glOrtho (http://www.opengl.org/sdk/docs/man/xhtml/glOrtho.xml) following the OpenGL equivalent
    setToOrtho2D(float x, float y, float width, float height)
    Sets this matrix to an orthographic projection matrix with the origin at (x,y) extending by width and height.
    setToOrtho2D(float x, float y, float width, float height, float near, float far)
    Sets this matrix to an orthographic projection matrix with the origin at (x,y) extending by width and height, having a near and far plane.
    setToProjection(float near, float far, float fovy, float aspectRatio)
    Sets the matrix to a projection matrix with a near- and far plane, a field of view in degrees and an aspect ratio.
    setToProjection(float left, float right, float bottom, float top, float near, float far)
    Sets the matrix to a projection matrix with a near/far plane, and left, bottom, right and top specifying the points on the near plane that are mapped to the lower left and upper right corners of the viewport.
    setToRotation(float axisX, float axisY, float axisZ, float degrees)
    Sets the matrix to a rotation matrix around the given axis.
    setToRotation(float x1, float y1, float z1, float x2, float y2, float z2)
    Set the matrix to a rotation matrix between two vectors.
    setToRotation(Vec3 axis, float degrees)
    Sets the matrix to a rotation matrix around the given axis.
    Set the matrix to a rotation matrix between two vectors.
    setToRotationRad(float axisX, float axisY, float axisZ, float radians)
    Sets the matrix to a rotation matrix around the given axis.
    setToRotationRad(Vec3 axis, float radians)
    Sets the matrix to a rotation matrix around the given axis.
    setToScaling(float x, float y, float z)
    Sets this matrix to a scaling matrix
    Sets this matrix to a scaling matrix
    setToTranslation(float x, float y, float z)
    Sets this matrix to a translation matrix, overwriting it first by an identity matrix and then setting the 4th column to the translation vector.
    Sets this matrix to a translation matrix, overwriting it first by an identity matrix and then setting the 4th column to the translation vector.
    setToTranslationAndScaling(float translationX, float translationY, float translationZ, float scalingX, float scalingY, float scalingZ)
    Sets this matrix to a translation and scaling matrix by first overwriting it with an identity and then setting the translation vector in the 4th column and the scaling vector in the diagonal.
    setToTranslationAndScaling(Vec3 translation, Vec3 scaling)
    Sets this matrix to a translation and scaling matrix by first overwriting it with an identity and then setting the translation vector in the 4th column and the scaling vector in the diagonal.
    setToWorld(Vec3 position, Vec3 forward, Vec3 up)
     
    setTranslation(float x, float y, float z)
    Sets the 4th column to the translation vector.
    Sets the 4th column to the translation vector.
    removes the translational part and transposes the matrix.
     
    tra()
    Transposes the matrix.
    translate(float x, float y, float z)
    Postmultiplies this matrix by a translation matrix.
    translate(Vec3 translation)
    Postmultiplies this matrix by a translation matrix.
    trn(float x, float y, float z)
    Adds a translational component to the matrix in the 4th column.
    trn(Vec3 vector)
    Adds a translational component to the matrix in the 4th column.
    static Vec3
    unrotate(Vec3 v, Mat3D matrix)
    Multiplies this vector by the transpose of the first three columns of the matrix.
    static Vec3
    untransform(Vec3 v, Mat3D matrix)
    Translates this vector in the direction opposite to the translation of the matrix and the multiplies this vector by the transpose of the first three columns of the matrix.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

    • M00

      public static final int M00
      XX: Typically the unrotated X component for scaling, also the cosine of the angle when rotated on the Y and/or Z axis. On Vec3 multiplication this value is multiplied with the source X component and added to the target X component.
      See Also:
    • M01

      public static final int M01
      XY: Typically the negative sine of the angle when rotated on the Z axis. On Vec3 multiplication this value is multiplied with the source Y component and added to the target X component.
      See Also:
    • M02

      public static final int M02
      XZ: Typically the sine of the angle when rotated on the Y axis. On Vec3 multiplication this value is multiplied with the source Z component and added to the target X component.
      See Also:
    • M03

      public static final int M03
      XW: Typically the translation of the X component. On Vec3 multiplication this value is added to the target X component.
      See Also:
    • M10

      public static final int M10
      YX: Typically the sine of the angle when rotated on the Z axis. On Vec3 multiplication this value is multiplied with the source X component and added to the target Y component.
      See Also:
    • M11

      public static final int M11
      YY: Typically the unrotated Y component for scaling, also the cosine of the angle when rotated on the X and/or Z axis. On Vec3 multiplication this value is multiplied with the source Y component and added to the target Y component.
      See Also:
    • M12

      public static final int M12
      YZ: Typically the negative sine of the angle when rotated on the X axis. On Vec3 multiplication this value is multiplied with the source Z component and added to the target Y component.
      See Also:
    • M13

      public static final int M13
      YW: Typically the translation of the Y component. On Vec3 multiplication this value is added to the target Y component.
      See Also:
    • M20

      public static final int M20
      ZX: Typically the negative sine of the angle when rotated on the Y axis. On Vec3 multiplication this value is multiplied with the source X component and added to the target Z component.
      See Also:
    • M21

      public static final int M21
      ZY: Typical the sine of the angle when rotated on the X axis. On Vec3 multiplication this value is multiplied with the source Y component and added to the target Z component.
      See Also:
    • M22

      public static final int M22
      ZZ: Typically the unrotated Z component for scaling, also the cosine of the angle when rotated on the X and/or Y axis. On Vec3 multiplication this value is multiplied with the source Z component and added to the target Z component.
      See Also:
    • M23

      public static final int M23
      ZW: Typically the translation of the Z component. On Vec3 multiplication this value is added to the target Z component.
      See Also:
    • M30

      public static final int M30
      WX: Typically the value zero. On Vec3 multiplication this value is ignored.
      See Also:
    • M31

      public static final int M31
      WY: Typically the value zero. On Vec3 multiplication this value is ignored.
      See Also:
    • M32

      public static final int M32
      WZ: Typically the value zero. On Vec3 multiplication this value is ignored.
      See Also:
    • M33

      public static final int M33
      WW: Typically the value one. On Vec3 multiplication this value is ignored.
      See Also:
    • val

      public final float[] val
  • Constructor Details

    • Mat3D

      public Mat3D()
      Constructs an identity matrix
    • Mat3D

      public Mat3D(Mat3D matrix)
      Constructs a matrix from the given matrix.
      Parameters:
      matrix - The matrix to copy. (This matrix is not modified)
    • Mat3D

      public Mat3D(float[] values)
      Constructs a matrix from the given float array. The array must have at least 16 elements; the first 16 will be copied.
      Parameters:
      values - The float array to copy. Remember that this matrix is in column major order. (The float array is not modified)
    • Mat3D

      public Mat3D(Quat quat)
      Constructs a rotation matrix from the given Quat.
      Parameters:
      quat - The quaternion to be copied. (The quaternion is not modified)
    • Mat3D

      public Mat3D(Vec3 position, Quat rotation, Vec3 scale)
      Construct a matrix from the given translation, rotation and scale.
      Parameters:
      position - The translation
      rotation - The rotation, must be normalized
      scale - The scale
  • Method Details

    • set

      public Mat3D set(Mat3D matrix)
      Sets the matrix to the given matrix.
      Parameters:
      matrix - The matrix that is to be copied. (The given matrix is not modified)
      Returns:
      This matrix for the purpose of chaining methods together.
    • set

      public Mat3D set(float[] values)
      Sets the matrix to the given matrix as a float array. The float array must have at least 16 elements; the first 16 will be copied.
      Parameters:
      values - The matrix, in float form, that is to be copied. Remember that this matrix is in column major order.
      Returns:
      This matrix for the purpose of chaining methods together.
    • set

      public Mat3D set(Quat quat)
      Sets the matrix to a rotation matrix representing the quaternion.
      Parameters:
      quat - The quaternion that is to be used to set this matrix.
      Returns:
      This matrix for the purpose of chaining methods together.
    • set

      public Mat3D set(float quaternionX, float quaternionY, float quaternionZ, float quaternionW)
      Sets the matrix to a rotation matrix representing the quaternion.
      Parameters:
      quaternionX - The X component of the quaternion that is to be used to set this matrix.
      quaternionY - The Y component of the quaternion that is to be used to set this matrix.
      quaternionZ - The Z component of the quaternion that is to be used to set this matrix.
      quaternionW - The W component of the quaternion that is to be used to set this matrix.
      Returns:
      This matrix for the purpose of chaining methods together.
    • set

      public Mat3D set(Vec3 position, Quat orientation)
      Set this matrix to the specified translation and rotation.
      Parameters:
      position - The translation
      orientation - The rotation, must be normalized
      Returns:
      This matrix for chaining
    • set

      public Mat3D set(float translationX, float translationY, float translationZ, float quaternionX, float quaternionY, float quaternionZ, float quaternionW)
      Sets the matrix to a rotation matrix representing the translation and quaternion.
      Parameters:
      translationX - The X component of the translation that is to be used to set this matrix.
      translationY - The Y component of the translation that is to be used to set this matrix.
      translationZ - The Z component of the translation that is to be used to set this matrix.
      quaternionX - The X component of the quaternion that is to be used to set this matrix.
      quaternionY - The Y component of the quaternion that is to be used to set this matrix.
      quaternionZ - The Z component of the quaternion that is to be used to set this matrix.
      quaternionW - The W component of the quaternion that is to be used to set this matrix.
      Returns:
      This matrix for the purpose of chaining methods together.
    • set

      public Mat3D set(Vec3 position, Quat orientation, Vec3 scale)
      Set this matrix to the specified translation, rotation and scale.
      Parameters:
      position - The translation
      orientation - The rotation, must be normalized
      scale - The scale
      Returns:
      This matrix for chaining
    • set

      public Mat3D set(float translationX, float translationY, float translationZ, float quaternionX, float quaternionY, float quaternionZ, float quaternionW, float scaleX, float scaleY, float scaleZ)
      Sets the matrix to a rotation matrix representing the translation and quaternion.
      Parameters:
      translationX - The X component of the translation that is to be used to set this matrix.
      translationY - The Y component of the translation that is to be used to set this matrix.
      translationZ - The Z component of the translation that is to be used to set this matrix.
      quaternionX - The X component of the quaternion that is to be used to set this matrix.
      quaternionY - The Y component of the quaternion that is to be used to set this matrix.
      quaternionZ - The Z component of the quaternion that is to be used to set this matrix.
      quaternionW - The W component of the quaternion that is to be used to set this matrix.
      scaleX - The X component of the scaling that is to be used to set this matrix.
      scaleY - The Y component of the scaling that is to be used to set this matrix.
      scaleZ - The Z component of the scaling that is to be used to set this matrix.
      Returns:
      This matrix for the purpose of chaining methods together.
    • set

      public Mat3D set(Vec3 xAxis, Vec3 yAxis, Vec3 zAxis, Vec3 pos)
      Sets the four columns of the matrix which correspond to the x-, y- and z-axis of the vector space this matrix creates as well as the 4th column representing the translation of any point that is multiplied by this matrix.
      Parameters:
      xAxis - The x-axis.
      yAxis - The y-axis.
      zAxis - The z-axis.
      pos - The translation vector.
    • cpy

      public Mat3D cpy()
      Returns:
      a copy of this matrix
    • trn

      public Mat3D trn(Vec3 vector)
      Adds a translational component to the matrix in the 4th column. The other columns are untouched.
      Parameters:
      vector - The translation vector to add to the current matrix. (This vector is not modified)
      Returns:
      This matrix for the purpose of chaining methods together.
    • trn

      public Mat3D trn(float x, float y, float z)
      Adds a translational component to the matrix in the 4th column. The other columns are untouched.
      Parameters:
      x - The x-component of the translation vector.
      y - The y-component of the translation vector.
      z - The z-component of the translation vector.
      Returns:
      This matrix for the purpose of chaining methods together.
    • getValues

      public float[] getValues()
      Returns:
      the backing float array
    • mul

      public Mat3D mul(Mat3D matrix)
      Postmultiplies this matrix with the given matrix, storing the result in this matrix. For example:
       A.mul(B) results in A := AB.
       
      Parameters:
      matrix - The other matrix to multiply by.
      Returns:
      This matrix for the purpose of chaining operations together.
    • mulLeft

      public Mat3D mulLeft(Mat3D matrix)
      Premultiplies this matrix with the given matrix, storing the result in this matrix. For example:
       A.mulLeft(B) results in A := BA.
       
      Parameters:
      matrix - The other matrix to multiply by.
      Returns:
      This matrix for the purpose of chaining operations together.
    • tra

      public Mat3D tra()
      Transposes the matrix.
      Returns:
      This matrix for the purpose of chaining methods together.
    • idt

      public Mat3D idt()
      Sets the matrix to an identity matrix.
      Returns:
      This matrix for the purpose of chaining methods together.
    • inv

      public Mat3D inv()
      Inverts the matrix. Stores the result in this matrix.
      Returns:
      This matrix for the purpose of chaining methods together.
      Throws:
      RuntimeException - if the matrix is singular (not invertible)
    • det

      public float det()
      Returns:
      The determinant of this matrix
    • det3x3

      public float det3x3()
      Returns:
      The determinant of the 3x3 upper left matrix
    • setToProjection

      public Mat3D setToProjection(float near, float far, float fovy, float aspectRatio)
      Sets the matrix to a projection matrix with a near- and far plane, a field of view in degrees and an aspect ratio. Note that the field of view specified is the angle in degrees for the height, the field of view for the width will be calculated according to the aspect ratio.
      Parameters:
      near - The near plane
      far - The far plane
      fovy - The field of view of the height in degrees
      aspectRatio - The "width over height" aspect ratio
      Returns:
      This matrix for the purpose of chaining methods together.
    • setToProjection

      public Mat3D setToProjection(float left, float right, float bottom, float top, float near, float far)
      Sets the matrix to a projection matrix with a near/far plane, and left, bottom, right and top specifying the points on the near plane that are mapped to the lower left and upper right corners of the viewport. This allows to create projection matrix with off-center vanishing point.
      Parameters:
      near - The near plane
      far - The far plane
      Returns:
      This matrix for the purpose of chaining methods together.
    • setToOrtho2D

      public Mat3D setToOrtho2D(float x, float y, float width, float height)
      Sets this matrix to an orthographic projection matrix with the origin at (x,y) extending by width and height. The near plane is set to 0, the far plane is set to 1.
      Parameters:
      x - The x-coordinate of the origin
      y - The y-coordinate of the origin
      width - The width
      height - The height
      Returns:
      This matrix for the purpose of chaining methods together.
    • setToOrtho2D

      public Mat3D setToOrtho2D(float x, float y, float width, float height, float near, float far)
      Sets this matrix to an orthographic projection matrix with the origin at (x,y) extending by width and height, having a near and far plane.
      Parameters:
      x - The x-coordinate of the origin
      y - The y-coordinate of the origin
      width - The width
      height - The height
      near - The near plane
      far - The far plane
      Returns:
      This matrix for the purpose of chaining methods together.
    • setToOrtho

      public Mat3D setToOrtho(float left, float right, float bottom, float top, float near, float far)
      Sets the matrix to an orthographic projection like glOrtho (http://www.opengl.org/sdk/docs/man/xhtml/glOrtho.xml) following the OpenGL equivalent
      Parameters:
      left - The left clipping plane
      right - The right clipping plane
      bottom - The bottom clipping plane
      top - The top clipping plane
      near - The near clipping plane
      far - The far clipping plane
      Returns:
      This matrix for the purpose of chaining methods together.
    • setTranslation

      public Mat3D setTranslation(Vec3 vector)
      Sets the 4th column to the translation vector.
      Parameters:
      vector - The translation vector
      Returns:
      This matrix for the purpose of chaining methods together.
    • setTranslation

      public Mat3D setTranslation(float x, float y, float z)
      Sets the 4th column to the translation vector.
      Parameters:
      x - The X coordinate of the translation vector
      y - The Y coordinate of the translation vector
      z - The Z coordinate of the translation vector
      Returns:
      This matrix for the purpose of chaining methods together.
    • setToTranslation

      public Mat3D setToTranslation(Vec3 vector)
      Sets this matrix to a translation matrix, overwriting it first by an identity matrix and then setting the 4th column to the translation vector.
      Parameters:
      vector - The translation vector
      Returns:
      This matrix for the purpose of chaining methods together.
    • setToTranslation

      public Mat3D setToTranslation(float x, float y, float z)
      Sets this matrix to a translation matrix, overwriting it first by an identity matrix and then setting the 4th column to the translation vector.
      Parameters:
      x - The x-component of the translation vector.
      y - The y-component of the translation vector.
      z - The z-component of the translation vector.
      Returns:
      This matrix for the purpose of chaining methods together.
    • setToTranslationAndScaling

      public Mat3D setToTranslationAndScaling(Vec3 translation, Vec3 scaling)
      Sets this matrix to a translation and scaling matrix by first overwriting it with an identity and then setting the translation vector in the 4th column and the scaling vector in the diagonal.
      Parameters:
      translation - The translation vector
      scaling - The scaling vector
      Returns:
      This matrix for the purpose of chaining methods together.
    • setToTranslationAndScaling

      public Mat3D setToTranslationAndScaling(float translationX, float translationY, float translationZ, float scalingX, float scalingY, float scalingZ)
      Sets this matrix to a translation and scaling matrix by first overwriting it with an identity and then setting the translation vector in the 4th column and the scaling vector in the diagonal.
      Parameters:
      translationX - The x-component of the translation vector
      translationY - The y-component of the translation vector
      translationZ - The z-component of the translation vector
      scalingX - The x-component of the scaling vector
      scalingY - The x-component of the scaling vector
      scalingZ - The x-component of the scaling vector
      Returns:
      This matrix for the purpose of chaining methods together.
    • setToRotation

      public Mat3D setToRotation(Vec3 axis, float degrees)
      Sets the matrix to a rotation matrix around the given axis.
      Parameters:
      axis - The axis
      degrees - The angle in degrees
      Returns:
      This matrix for the purpose of chaining methods together.
    • setToRotationRad

      public Mat3D setToRotationRad(Vec3 axis, float radians)
      Sets the matrix to a rotation matrix around the given axis.
      Parameters:
      axis - The axis
      radians - The angle in radians
      Returns:
      This matrix for the purpose of chaining methods together.
    • setToRotation

      public Mat3D setToRotation(float axisX, float axisY, float axisZ, float degrees)
      Sets the matrix to a rotation matrix around the given axis.
      Parameters:
      axisX - The x-component of the axis
      axisY - The y-component of the axis
      axisZ - The z-component of the axis
      degrees - The angle in degrees
      Returns:
      This matrix for the purpose of chaining methods together.
    • setToRotationRad

      public Mat3D setToRotationRad(float axisX, float axisY, float axisZ, float radians)
      Sets the matrix to a rotation matrix around the given axis.
      Parameters:
      axisX - The x-component of the axis
      axisY - The y-component of the axis
      axisZ - The z-component of the axis
      radians - The angle in radians
      Returns:
      This matrix for the purpose of chaining methods together.
    • setToRotation

      public Mat3D setToRotation(Vec3 v1, Vec3 v2)
      Set the matrix to a rotation matrix between two vectors.
      Parameters:
      v1 - The base vector
      v2 - The target vector
      Returns:
      This matrix for the purpose of chaining methods together
    • setToRotation

      public Mat3D setToRotation(float x1, float y1, float z1, float x2, float y2, float z2)
      Set the matrix to a rotation matrix between two vectors.
      Parameters:
      x1 - The base vectors x value
      y1 - The base vectors y value
      z1 - The base vectors z value
      x2 - The target vector x value
      y2 - The target vector y value
      z2 - The target vector z value
      Returns:
      This matrix for the purpose of chaining methods together
    • setFromEulerAngles

      public Mat3D setFromEulerAngles(float yaw, float pitch, float roll)
      Sets this matrix to a rotation matrix from the given euler angles.
      Parameters:
      yaw - the yaw in degrees
      pitch - the pitch in degrees
      roll - the roll in degrees
      Returns:
      This matrix
    • setFromEulerAnglesRad

      public Mat3D setFromEulerAnglesRad(float yaw, float pitch, float roll)
      Sets this matrix to a rotation matrix from the given euler angles.
      Parameters:
      yaw - the yaw in radians
      pitch - the pitch in radians
      roll - the roll in radians
      Returns:
      This matrix
    • setToScaling

      public Mat3D setToScaling(Vec3 vector)
      Sets this matrix to a scaling matrix
      Parameters:
      vector - The scaling vector
      Returns:
      This matrix for chaining.
    • setToScaling

      public Mat3D setToScaling(float x, float y, float z)
      Sets this matrix to a scaling matrix
      Parameters:
      x - The x-component of the scaling vector
      y - The y-component of the scaling vector
      z - The z-component of the scaling vector
      Returns:
      This matrix for chaining.
    • setToLookAt

      public Mat3D setToLookAt(Vec3 direction, Vec3 up)
      Sets the matrix to a look at matrix with a direction and an up vector. Multiply with a translation matrix to get a camera model view matrix.
      Parameters:
      direction - The direction vector
      up - The up vector
      Returns:
      This matrix for the purpose of chaining methods together.
    • setToLookAt

      public Mat3D setToLookAt(Vec3 position, Vec3 target, Vec3 up)
      Sets this matrix to a look at matrix with the given position, target and up vector.
      Parameters:
      position - the position
      target - the target
      up - the up vector
      Returns:
      This matrix
    • setToWorld

      public Mat3D setToWorld(Vec3 position, Vec3 forward, Vec3 up)
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • lerp

      public Mat3D lerp(Mat3D matrix, float alpha)
      Linearly interpolates between this matrix and the given matrix mixing by alpha
      Parameters:
      matrix - the matrix
      alpha - the alpha value in the range [0,1]
      Returns:
      This matrix for the purpose of chaining methods together.
    • avg

      public Mat3D avg(Mat3D other, float w)
      Averages the given transform with this one and stores the result in this matrix. Translations and scales are lerped while rotations are slerped.
      Parameters:
      other - The other transform
      w - Weight of this transform; weight of the other transform is (1 - w)
      Returns:
      This matrix for chaining
    • avg

      public Mat3D avg(Mat3D[] t)
      Averages the given transforms and stores the result in this matrix. Translations and scales are lerped while rotations are slerped. Does not destroy the data contained in t.
      Parameters:
      t - List of transforms
      Returns:
      This matrix for chaining
    • avg

      public Mat3D avg(Mat3D[] t, float[] w)
      Averages the given transforms with the given weights and stores the result in this matrix. Translations and scales are lerped while rotations are slerped. Does not destroy the data contained in t or w; Sum of w_i must be equal to 1, or unexpected results will occur.
      Parameters:
      t - List of transforms
      w - List of weights
      Returns:
      This matrix for chaining
    • set

      public Mat3D set(Mat mat)
      Sets this matrix to the given 3x3 matrix. The third column of this matrix is set to (0,0,1,0).
      Parameters:
      mat - the matrix
    • set

      public Mat3D set(Affine2 affine)
      Sets this matrix to the given affine matrix. The values are mapped as follows:
            [  M00  M01   0   M02  ]
            [  M10  M11   0   M12  ]
            [   0    0    1    0   ]
            [   0    0    0    1   ]
       
      Parameters:
      affine - the affine matrix
      Returns:
      This matrix for chaining
    • setAsAffine

      public Mat3D setAsAffine(Affine2 affine)
      Assumes that this matrix is a 2D affine transformation, copying only the relevant components. The values are mapped as follows:
            [  M00  M01   _   M02  ]
            [  M10  M11   _   M12  ]
            [   _    _    _    _   ]
            [   _    _    _    _   ]
       
      Parameters:
      affine - the source matrix
      Returns:
      This matrix for chaining
    • setAsAffine

      public Mat3D setAsAffine(Mat3D mat)
      Assumes that both matrices are 2D affine transformations, copying only the relevant components. The copied values are:
            [  M00  M01   _   M03  ]
            [  M10  M11   _   M13  ]
            [   _    _    _    _   ]
            [   _    _    _    _   ]
       
      Parameters:
      mat - the source matrix
      Returns:
      This matrix for chaining
    • scl

      public Mat3D scl(Vec3 scale)
    • scl

      public Mat3D scl(float x, float y, float z)
    • scl

      public Mat3D scl(float scale)
    • getTranslation

      public Vec3 getTranslation(Vec3 position)
    • getRotation

      public Quat getRotation(Quat rotation, boolean normalizeAxes)
      Gets the rotation of this matrix.
      Parameters:
      rotation - The Quat to receive the rotation
      normalizeAxes - True to normalize the axes, necessary when the matrix might also include scaling.
      Returns:
      The provided Quat for chaining.
    • getRotation

      public Quat getRotation(Quat rotation)
      Gets the rotation of this matrix.
      Parameters:
      rotation - The Quat to receive the rotation
      Returns:
      The provided Quat for chaining.
    • getScaleXSquared

      public float getScaleXSquared()
      Returns:
      the squared scale factor on the X axis
    • getScaleYSquared

      public float getScaleYSquared()
      Returns:
      the squared scale factor on the Y axis
    • getScaleZSquared

      public float getScaleZSquared()
      Returns:
      the squared scale factor on the Z axis
    • getScaleX

      public float getScaleX()
      Returns:
      the scale factor on the X axis (non-negative)
    • getScaleY

      public float getScaleY()
      Returns:
      the scale factor on the Y axis (non-negative)
    • getScaleZ

      public float getScaleZ()
      Returns:
      the scale factor on the X axis (non-negative)
    • getScale

      public Vec3 getScale(Vec3 scale)
      Parameters:
      scale - The vector which will receive the (non-negative) scale components on each axis.
      Returns:
      The provided vector for chaining.
    • toNormalMatrix

      public Mat3D toNormalMatrix()
      removes the translational part and transposes the matrix.
    • mul

      public static void mul(float[] mata, float[] matb)
      Multiplies the matrix mata with matrix matb, storing the result in mata. The arrays are assumed to hold 4x4 column major matrices as you can get from val. This is the same as mul(Mat3D).
      Parameters:
      mata - the first matrix.
      matb - the second matrix.
    • mulVec

      public static void mulVec(float[] mat, float[] vec)
      Multiplies the vector with the given matrix. The matrix array is assumed to hold a 4x4 column major matrix as you can get from val. The vector array is assumed to hold a 3-component vector, with x being the first element, y being the second and z being the last component. The result is stored in the vector array. This is the same as Vec3#mul(Mat3).
      Parameters:
      mat - the matrix
      vec - the vector.
    • prj

      public static void prj(float[] mat, float[] vec)
      Multiplies the vector with the given matrix, performing a division by w. The matrix array is assumed to hold a 4x4 column major matrix as you can get from val. The vector array is assumed to hold a 3-component vector, with x being the first element, y being the second and z being the last component. The result is stored in the vector array. This is the same as Vec3#prj(Mat3).
      Parameters:
      mat - the matrix
      vec - the vector.
    • prj

      public static void prj(float[] mat, float[] vecs, int offset, int numVecs, int stride)
      Multiplies the vectors with the given matrix, performing a division by w. The matrix array is assumed to hold a 4x4 column major matrix as you can get from val. The vectors array is assumed to hold 3-component vectors. Offset specifies the offset into the array where the x-component of the first vector is located. The numVecs parameter specifies the number of vectors stored in the vectors array. The stride parameter specifies the number of floats between subsequent vectors and must be >= 3.
      Parameters:
      mat - the matrix
      vecs - the vectors
      offset - the offset into the vectors array
      numVecs - the number of vectors
      stride - the stride between vectors in floats
    • rot

      public static void rot(float[] mat, float[] vec)
      Multiplies the vector with the top most 3x3 sub-matrix of the given matrix. The matrix array is assumed to hold a 4x4 column major matrix as you can get from val. The vector array is assumed to hold a 3-component vector, with x being the first element, y being the second and z being the last component. The result is stored in the vector array. This is the same as Vec3#rot(Mat3).
      Parameters:
      mat - the matrix
      vec - the vector.
    • inv

      public static boolean inv(float[] val)
      Computes the inverse of the given matrix. The matrix array is assumed to hold a 4x4 column major matrix as you can get from val.
      Parameters:
      val - the matrix values.
      Returns:
      false in case the inverse could not be calculated, true otherwise.
    • det

      public static float det(float[] val)
      Computes the determinante of the given matrix. The matrix array is assumed to hold a 4x4 column major matrix as you can get from val.
      Parameters:
      val - the matrix values.
      Returns:
      the determinante.
    • translate

      public Mat3D translate(Vec3 translation)
      Postmultiplies this matrix by a translation matrix. Postmultiplication is also used by OpenGL ES' glTranslate/glRotate/glScale
      Returns:
      This matrix for the purpose of chaining methods together.
    • translate

      public Mat3D translate(float x, float y, float z)
      Postmultiplies this matrix by a translation matrix. Postmultiplication is also used by OpenGL ES' 1.x glTranslate/glRotate/glScale.
      Parameters:
      x - Translation in the x-axis.
      y - Translation in the y-axis.
      z - Translation in the z-axis.
      Returns:
      This matrix for the purpose of chaining methods together.
    • rotate

      public Mat3D rotate(Vec3 axis, float degrees)
      Postmultiplies this matrix with a (counter-clockwise) rotation matrix. Postmultiplication is also used by OpenGL ES' 1.x glTranslate/glRotate/glScale.
      Parameters:
      axis - The vector axis to rotate around.
      degrees - The angle in degrees.
      Returns:
      This matrix for the purpose of chaining methods together.
    • rotateRad

      public Mat3D rotateRad(Vec3 axis, float radians)
      Postmultiplies this matrix with a (counter-clockwise) rotation matrix. Postmultiplication is also used by OpenGL ES' 1.x glTranslate/glRotate/glScale.
      Parameters:
      axis - The vector axis to rotate around.
      radians - The angle in radians.
      Returns:
      This matrix for the purpose of chaining methods together.
    • rotate

      public Mat3D rotate(float axisX, float axisY, float axisZ, float degrees)
      Postmultiplies this matrix with a (counter-clockwise) rotation matrix. Postmultiplication is also used by OpenGL ES' 1.x glTranslate/glRotate/glScale
      Parameters:
      axisX - The x-axis component of the vector to rotate around.
      axisY - The y-axis component of the vector to rotate around.
      axisZ - The z-axis component of the vector to rotate around.
      degrees - The angle in degrees
      Returns:
      This matrix for the purpose of chaining methods together.
    • rotateRad

      public Mat3D rotateRad(float axisX, float axisY, float axisZ, float radians)
      Postmultiplies this matrix with a (counter-clockwise) rotation matrix. Postmultiplication is also used by OpenGL ES' 1.x glTranslate/glRotate/glScale
      Parameters:
      axisX - The x-axis component of the vector to rotate around.
      axisY - The y-axis component of the vector to rotate around.
      axisZ - The z-axis component of the vector to rotate around.
      radians - The angle in radians
      Returns:
      This matrix for the purpose of chaining methods together.
    • rotate

      public Mat3D rotate(Quat rotation)
      Postmultiplies this matrix with a (counter-clockwise) rotation matrix. Postmultiplication is also used by OpenGL ES' 1.x glTranslate/glRotate/glScale.
      Returns:
      This matrix for the purpose of chaining methods together.
    • rotate

      public Mat3D rotate(Vec3 v1, Vec3 v2)
      Postmultiplies this matrix by the rotation between two vectors.
      Parameters:
      v1 - The base vector
      v2 - The target vector
      Returns:
      This matrix for the purpose of chaining methods together
    • scale

      public Mat3D scale(Vec3 vec)
    • scale

      public Mat3D scale(float scaleX, float scaleY, float scaleZ)
      Postmultiplies this matrix with a scale matrix. Postmultiplication is also used by OpenGL ES' 1.x glTranslate/glRotate/glScale.
      Parameters:
      scaleX - The scale in the x-axis.
      scaleY - The scale in the y-axis.
      scaleZ - The scale in the z-axis.
      Returns:
      This matrix for the purpose of chaining methods together.
    • extract4x3Matrix

      public void extract4x3Matrix(float[] dst)
      Copies the 4x3 upper-left sub-matrix into float array. The destination array is supposed to be a column major matrix.
      Parameters:
      dst - the destination matrix
    • hasRotationOrScaling

      public boolean hasRotationOrScaling()
      Returns:
      True if this matrix has any rotation or scaling, false otherwise
    • prj

      public static Vec3 prj(Vec3 v, Mat3D matrix)
      Multiplies this vector by the given matrix dividing by w, assuming the fourth (w) component of the vector is 1. This is mostly used to project/unproject vectors via a perspective projection matrix.
      Parameters:
      matrix - The matrix.
      Returns:
      This vector for chaining
    • rot

      public static Vec3 rot(Vec3 v, Mat3D matrix)
      Multiplies this vector by the first three columns of the matrix, essentially only applying rotation and scaling.
      Parameters:
      matrix - The matrix
      Returns:
      This vector for chaining
    • unrotate

      public static Vec3 unrotate(Vec3 v, Mat3D matrix)
      Multiplies this vector by the transpose of the first three columns of the matrix. Note: only works for translation and rotation, does not work for scaling. For those, use rot(Vec3, Mat3D) with inv().
      Parameters:
      matrix - The transformation matrix
      Returns:
      The vector for chaining
    • untransform

      public static Vec3 untransform(Vec3 v, Mat3D matrix)
      Translates this vector in the direction opposite to the translation of the matrix and the multiplies this vector by the transpose of the first three columns of the matrix. Note: only works for translation and rotation, does not work for scaling. For those, use mul(Mat3D) with inv().
      Parameters:
      matrix - The transformation matrix
      Returns:
      The vector for chaining