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

cee.Mat4.constructor()
Mat4(): Mat4

Creates the matrix. Default is an identity matrix.

Returns: Mat4

Methods

cee.Mat4.equals()
equals(other: Mat4): boolean

Returns true if the matrices are equal

Parameters

other: Mat4

Returns: boolean

cee.Mat4.getAsArray()
getAsArray(): ArrayLike

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

cee.Mat4.getInverse()
getInverse(): Mat4

Returns this inverse of this matrix.

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

Returns: Mat4

cee.Mat4.getRowCol()
getRowCol(row: number, col: number): number

Returns the value at the given row and column

Parameters

row: number

col: number

Returns: number

cee.Mat4.isIdentity()
isIdentity(): boolean

Returns true if the matrix is an identity matrix

Returns: boolean

static cee.Mat4.fromArray()

static

fromArray(array: ArrayLike): 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

Returns: Mat4

static cee.Mat4.fromCoordSystemAxes()

static

fromCoordSystemAxes(xAxis: Vec3Like, yAxis: Vec3Like, zAxis: Vec3Like): Mat4

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

xAxis: Vec3Like

Orientation of x axis

yAxis: Vec3Like

Orientation of y axis

zAxis: Vec3Like

Orientation of z axis

Returns: Mat4

static cee.Mat4.fromElements()

static

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 cee.Mat4.fromRotation()

static

fromRotation(axis: Vec3Like, angle: number): Mat4

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

Parameters

axis: Vec3Like

angle: number

Returns: Mat4

static cee.Mat4.fromScaling()

static

fromScaling(scale: Vec3Like): Mat4

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

scale: Vec3Like

Returns: Mat4

static cee.Mat4.fromTranslation()

static

fromTranslation(trans: Vec3Like): Mat4

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

trans: Vec3Like

Returns: Mat4

static cee.Mat4.multiply()

static

multiply(matrices: Mat4[]): Mat4

Multiplies given matrices.

Parameters

matrices: Mat4[]

Returns: Mat4

static cee.Mat4.translatePostMultiply()

static

translatePostMultiply(M: Mat4, tv: Vec3Like): Mat4

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

M: Mat4

tv: Vec3Like

Returns: Mat4

static cee.Mat4.translatePreMultiply()

static

translatePreMultiply(M: Mat4, tv: Vec3Like): Mat4

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

M: Mat4

tv: Vec3Like

Returns: Mat4