Class Matrix4

java.lang.Object
graphic.Matrix4

public class Matrix4 extends Object
Column-major 4x4 matrix, used for 3D computations (homogeneous coordinates).
Author:
Andrea Zoppi
  • Field Details

  • Constructor Details

    • Matrix4

      public Matrix4()
    • Matrix4

      public Matrix4(float scalar)
      Diagonal constructor.
      Parameters:
      scalar - Scalar value to put on diagonal.
    • Matrix4

      public Matrix4(Matrix4 m)
      Copy constructor.
      Parameters:
      m - Matrix to be copied.
    • Matrix4

      public Matrix4(float[] a)
      Array constructor.
      Parameters:
      a - Array to be converted into a matrix.
    • Matrix4

      public Matrix4(Vector4 position, Vector4 left, Vector4 up, Vector4 forward)
      Created a matrix given the position and the individual axes.
      Parameters:
      position - Position vector.
      left - Left vector.
      up - Up vector.
      forward - Forward vector.
  • Method Details

    • get

      public float get(int r, int c)
      Gets a matrix value.
      Parameters:
      r - Row number.
      c - Column number.
      Returns:
      Value at (row, column).
    • set

      public void set(int r, int c, float value)
      Sets a matrix value.
      Parameters:
      r - Row number.
      c - Column number.
      value - Value at (row, column).
    • set

      public void set(float allValues)
      Sets all matrix values to the given value.
      Parameters:
      allValues - Value to put in all cells.
    • set

      public void set(Matrix4 m)
      Copies all values from an existing matrix.
      Parameters:
      m - Matrix to be copied.
    • set

      public void set(float[] a)
      Sets all values from a given matrix in column-major vector array form.
      Parameters:
      a - Array to be converted into a matrix.
    • getRow

      public Vector4 getRow(int r)
      Gets a single row vector.
      Parameters:
      r - Row number.
      Returns:
      The copied row vector.
    • getColumn

      public Vector4 getColumn(int c)
      Gets a single column vector.
      Parameters:
      c - Column number.
      Returns:
      The copied column vector.
    • setRow

      public void setRow(int r, Vector4 v)
      Sets a single row vector.
      Parameters:
      r - Row number.
      v - Vector to be copied onto the row.
    • setColumn

      public void setColumn(int c, Vector4 v)
      Sets a single column vector.
      Parameters:
      c - Column number.
      v - Vector to be copied onto the column.
    • setIdentity

      public void setIdentity()
      Sets the matrix to an identity matrix.
    • tr

      public Matrix4 tr()
      Transposed version of the matrix.
      Returns:
      A transposed copy of the matrix.
    • trSelf

      public void trSelf()
      Self-transposes the matrix.
    • det

      public float det()
      Computes the determinant of the matrix.
      Returns:
      The matrix determinant.
    • inv

      public Matrix4 inv()
      Computes an inverted copy of the matrix.
      Returns:
      The inverted copy of the matrix.
    • invSelf

      public void invSelf()
      Self-inverts the matrix.
    • add

      public Matrix4 add(Matrix4 m)
      Adds a matrix to this one.
      Parameters:
      m - Matrix to be added.
      Returns:
      The sum of the matrices.
    • addSelf

      public void addSelf(Matrix4 m)
      Adds a matrix to itself.
      Parameters:
      m - Matrix to be added.
    • sub

      public Matrix4 sub(Matrix4 m)
      Subtracts a mtrix to this one.
      Parameters:
      m - Matrix to be subtracted
      Returns:
      The difference between the matrices.
    • subSelf

      public void subSelf(Matrix4 m)
      Subtracts a matrix to itself.
      Parameters:
      m - Matrix to be subtracted.
    • mult

      public Matrix4 mult(float scalar)
      Multiplied copy of the matrix by a scalar value.
      Parameters:
      scalar - Scalar value to be multiplied.
      Returns:
      The multiplied matrix.
    • mult

      public Matrix4 mult(Matrix4 m)
      Multiplies the matrix by another matrix.
      Parameters:
      m - Matrix to be multiplied.
      Returns:
      The multiplied matrix.
    • mult

      public Vector4 mult(Vector4 v)
      Multiplies the matrix by a vector.
      Parameters:
      v - Vector to be multiplied.
      Returns:
      The resultant vector (column).
    • multSelf

      public void multSelf(float scalar)
      Multiplies itself by a scalar value.
      Parameters:
      scalar - Scalar value to multiply by.
    • multSelf

      public void multSelf(Matrix4 m)
      Multiplied itself by another matrix.
      Parameters:
      m - Matrix to be multiplied by.
    • div

      public Matrix4 div(float scalar)
    • divSelf

      public void divSelf(float scalar)
    • trans

      public Matrix4 trans(float dx, float dy, float dz)
    • trans

      public Matrix4 trans(Vector4 dv)
    • transSelf

      public void transSelf(float dx, float dy, float dz)
    • transSelf

      public void transSelf(Vector4 dv)
    • toArray

      public float[] toArray()
    • clone

      public Matrix4 clone()
      Overrides:
      clone in class Object
    • toString

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

      public static Matrix4 createIdentity()
    • createTranslation

      public static Matrix4 createTranslation(float dx, float dy, float dz)
    • createTranslationOnly

      public static Matrix4 createTranslationOnly(float dx, float dy, float dz)
    • createRotationXYZ

      public static Matrix4 createRotationXYZ(float rx, float ry, float rz)
    • createRotationZXY

      public static Matrix4 createRotationZXY(float rx, float ry, float rz)
    • createRotationX

      public static Matrix4 createRotationX(float rad)
    • createRotationY

      public static Matrix4 createRotationY(float rad)
    • createRotationZ

      public static Matrix4 createRotationZ(float rad)
    • createDiagonal

      public static Matrix4 createDiagonal(float allValues)
    • createDiagonal

      public static Matrix4 createDiagonal(float d00, float d11, float d22, float d33)
    • createScale

      public static Matrix4 createScale(float xyzScale)
    • createScale

      public static Matrix4 createScale(float sx, float sy, float sz)