Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Mat4

An immutable 4x4 matrix

Matrices are stored internally as a one dimensional array for performance reasons.

The mapping of matrix elements to indices of this internal array is as follows:

  | m00  m01  m02  m03 |     | 0  4   8  12 |
  | m10  m11  m12  m13 |     | 1  5   9  13 |
  | m20  m21  m22  m23 |     | 2  6  10  14 |
  | m30  m31  m32  m33 |     | 3  7  11  15 |

This is consistent with the way matrices are represented in WebGL. To exemplify, translation values are stored in elements 12,13,14; see figure below

  | 1  0  0 Tx |
  | 0  1  0 Ty |
  | 0  0  1 Tz |
  | 0  0  0  1 |

From the OpenGL red book (page 68) v' = M*v

  | X'|   | 1  0  0 Tx |   | X |
  | Y'|   | 0  1  0 Ty |   | Y |
  | Z'| = | 0  0  1 Tz | * | Z |
  | 1 |   | 0  0  0  1 |   | 1 |

Note that this class is immutable.

Hierarchy

  • Mat4

Index

Constructors

constructor

  • Creates the matrix. Default is an identity matrix.

    Returns Mat4

Methods

equals

  • equals(other: Mat4): boolean
  • Returns true if the matrices are equal

    Parameters

    Returns boolean

getAsArray

  • getAsArray(): ArrayLike<number>
  • Returns a reference to the internal array storing the matrix values.

    The array will be ordered as follows:

      | m00  m01  m02  m03 |     | 0  4   8  12 |
      | m10  m11  m12  m13 |     | 1  5   9  13 |
      | m20  m21  m22  m23 |     | 2  6  10  14 |
      | m30  m31  m32  m33 |     | 3  7  11  15 |
    

    Returns ArrayLike<number>

getInverse

  • getInverse(): Mat4
  • Returns this inverse of this matrix.

    If this matrix is not invertible, returns a zero matrix.

    Returns Mat4

getRowCol

  • getRowCol(row: number, col: number): number
  • Returns the value at the given row and column

    Parameters

    • row: number
    • col: number

    Returns number

isIdentity

  • isIdentity(): boolean
  • Returns true if the matrix is an identity matrix

    Returns boolean

Static fromArray

  • fromArray(array: ArrayLike<number>): Mat4
  • Returns a matrix initialized with the values in the passed array

    The array must be ordered as follows:

      | m00  m01  m02  m03 |     | 0  4   8  12 |
      | m10  m11  m12  m13 |     | 1  5   9  13 |
      | m20  m21  m22  m23 |     | 2  6  10  14 |
      | m30  m31  m32  m33 |     | 3  7  11  15 |
    

    Parameters

    • array: ArrayLike<number>

    Returns Mat4

Static fromCoordSystemAxes

  • Returns a rotation matrix that will align the global X, Y and Z axes with the specified axes.

    Note that at least one axis must be specified and all specified axes must be normalized. If two or three axes are specified, they must be orthogonal to each other.

    Parameters

    Returns Mat4

Static fromElements

  • fromElements(m00: number, m01: number, m02: number, m03: number, m10: number, m11: number, m12: number, m13: number, m20: number, m21: number, m22: number, m23: number, m30: number, m31: number, m32: number, m33: number): Mat4
  • Returns a transformation matrix containing the given element values

      | m00  m01  m02  m03 |
      | m10  m11  m12  m13 |
      | m20  m21  m22  m23 |
      | m30  m31  m32  m33 |
    

    Parameters

    • m00: number
    • m01: number
    • m02: number
    • m03: number
    • m10: number
    • m11: number
    • m12: number
    • m13: number
    • m20: number
    • m21: number
    • m22: number
    • m23: number
    • m30: number
    • m31: number
    • m32: number
    • m33: number

    Returns Mat4

Static fromRotation

  • Returns a transformation matrix containing only rotation, specified as a rotation around the given axis

    Parameters

    Returns Mat4

Static fromScaling

  • Returns a transformation matrix containing only the given scaling

      | Sx 0  0  0 |
      | 0  Sy 0  0 |
      | 0  0  Sz 0 |
      | 0  0  0  1 |
    

    Parameters

    Returns Mat4

Static fromTranslation

  • Returns a transformation matrix containing only the given translation

    Will set m03 to x, m13 to y, and m23 to z, resulting in the following matrix

      | 1  0  0 Tx |
      | 0  1  0 Ty |
      | 0  0  1 Tz |
      | 0  0  0  1 |
    

    Parameters

    Returns Mat4

Static multiply

  • Multiplies given matrices.

    Parameters

    • Rest ...matrices: Mat4[]

    Returns Mat4

Static translatePostMultiply

  • Adds translation to the given matrix M by post-multiplying it with a matrix containing the given translation tv.

    This has the effect of performing the multiplication M' = M x T

    Parameters

    Returns Mat4

Static translatePreMultiply

  • Adds translation to the given matrix M by pre-multiplying it with a matrix containing the given translation tv.

    This has the effect of performing the multiplication M' = T x M

    Parameters

    Returns Mat4

Generated using TypeDoc