Mat4

class cee.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.

Constructors


Constructors

constructor

cee.Mat4.constructor()

Creates the matrix. Default is an identity matrix.

Return type

cee.Mat4

Methods

equals

cee.Mat4.equals(other)

Returns true if the matrices are equal

Arguments
Return type

boolean

getAsArray

cee.Mat4.getAsArray()

Returns a reference to the internal array storing the matrix values.

Return type

ArrayLike[number]

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 |

getInverse

cee.Mat4.getInverse()

Returns this inverse of this matrix.

Return type

cee.Mat4

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

getRowCol

cee.Mat4.getRowCol(row, col)

Returns the value at the given row and column

Arguments
  • row (number) –

  • col (number) –

Return type

number

isIdentity

cee.Mat4.isIdentity()

Returns true if the matrix is an identity matrix

Return type

boolean

fromArray

cee.Mat4.fromArray(array)

Returns a matrix initialized with the values in the passed array

Arguments
  • array (ArrayLike[number]) –

Return type

cee.Mat4

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 |

fromCoordSystemAxes

cee.Mat4.fromCoordSystemAxes(xAxis, yAxis, zAxis)

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

Arguments
Return type

cee.Mat4

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.

fromElements

cee.Mat4.fromElements(m00, m01, m02, m03, m10, m11, m12, m13, m20, m21, m22, m23, m30, m31, m32, m33)

Returns a transformation matrix containing the given element values

Arguments
  • 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) –

Return type

cee.Mat4

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

fromRotation

cee.Mat4.fromRotation(axis, angle)

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

Arguments
Return type

cee.Mat4

fromScaling

cee.Mat4.fromScaling(scale)

Returns a transformation matrix containing only the given scaling

Arguments
Return type

cee.Mat4

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

fromTranslation

cee.Mat4.fromTranslation(trans)

Returns a transformation matrix containing only the given translation

Arguments
Return type

cee.Mat4

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 |

multiply

cee.Mat4.multiply(matrices)

Multiplies given matrices.

Arguments
  • matrices ([cee.Mat4]) –

Return type

cee.Mat4

translatePostMultiply

cee.Mat4.translatePostMultiply(M, tv)

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

Arguments
Return type

cee.Mat4

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

translatePreMultiply

cee.Mat4.translatePreMultiply(M, tv)

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

Arguments
Return type

cee.Mat4

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