Matrix4()

Class representing a 4x4 matrix. The elements of the matrix are stored in column-major order.

new Matrix4()

Constructs a new 4x4 identity matrix.

Author:

Members

elements :Array.<Number>

The elements of the matrix in column-major order.

Methods

clone() → {Matrix4}

Creates a new matrix and copies all values from this matrix.

Returns:
Matrix4 -

A new matrix.

compose(position, rotation, scale) → {Matrix4}

Composes a matrix from the given position, quaternion and scale.

Parameters:
Name Type Description
position Vector3

A vector representing a position in 3D space.

rotation Quaternion

A quaternion representing a rotation.

scale Vector3

A vector representing a 3D scaling.

Returns:
Matrix4 -

A reference to this matrix.

copy(m) → {Matrix4}

Copies all values from the given matrix to this matrix.

Parameters:
Name Type Description
m Matrix4

The matrix to copy.

Returns:
Matrix4 -

A reference to this matrix.

equals(m) → {Boolean}

Returns true if the given matrix is deep equal with this matrix.

Parameters:
Name Type Description
m Matrix4

The matrix to test.

Returns:
Boolean -

The result of the equality test.

extractBasis(xAxis, yAxis, zAxis) → {Matrix4}

Extracts the basis vectors and stores them to the given vectors.

Parameters:
Name Type Description
xAxis Vector3

The first result vector for the x-axis.

yAxis Vector3

The second result vector for the y-axis.

zAxis Vector3

The third result vector for the z-axis.

Returns:
Matrix4 -

A reference to this matrix.

fromArray(array, offset) → {Matrix4}

Sets the elements of this matrix from an array.

Parameters:
Name Type Default Description
array Array.<Number>

An array.

offset Number 0

An optional offset.

Returns:
Matrix4 -

A reference to this matrix.

fromMatrix3(m) → {Matrix4}

Sets the upper-left 3x3 portion of this matrix by the given 3x3 matrix. Other parts of the matrix are equal to the identiy matrix.

Parameters:
Name Type Description
m Matrix3

A 3x3 matrix.

Returns:
Matrix4 -

A reference to this matrix.

fromQuaternion(q) → {Matrix4}

Uses the given quaternion to transform the upper left 3x3 part to a rotation matrix. Other parts of the matrix are equal to the identiy matrix.

Parameters:
Name Type Description
q Quaternion

A quaternion representing a rotation.

Returns:
Matrix4 -

A reference to this matrix.

getInverse(m) → {Matrix4}

Computes the inverse of this matrix and stored the result in the given matrix.

You can not invert a matrix with a determinant of zero. If you attempt this, the method returns a zero matrix instead.

Parameters:
Name Type Description
m Matrix4

The result matrix.

Returns:
Matrix4 -

The result matrix.

getMaxScale() → {Number}

Computes the maximum scale value for all three axis.

Returns:
Number -

The maximum scale value.

identity() → {Matrix4}

Transforms this matrix to an identity matrix.

Returns:
Matrix4 -

A reference to this matrix.

makeBasis(xAxis, yAxis, zAxis) → {Matrix4}

Makes a basis from the given vectors.

Parameters:
Name Type Description
xAxis Vector3

The first basis vector for the x-axis.

yAxis Vector3

The second basis vector for the y-axis.

zAxis Vector3

The third basis vector for the z-axis.

Returns:
Matrix4 -

A reference to this matrix.

multiply(m) → {Matrix4}

Multiplies this matrix with the given matrix.

Parameters:
Name Type Description
m Matrix4

The matrix to multiply.

Returns:
Matrix4 -

A reference to this matrix.

multiplyMatrices(a, b) → {Matrix4}

Multiplies two given matrices and stores the result in this matrix.

Parameters:
Name Type Description
a Matrix4

The first matrix of the operation.

b Matrix4

The second matrix of the operation.

Returns:
Matrix4 -

A reference to this matrix.

multiplyScalar(s) → {Matrix4}

Multiplies the given scalar with this matrix.

Parameters:
Name Type Description
s Number

The scalar to multiply.

Returns:
Matrix4 -

A reference to this matrix.

premultiply(m) → {Matrix4}

Multiplies this matrix with the given matrix. So the order of the multiplication is switched compared to Matrix4#multiply.

Parameters:
Name Type Description
m Matrix4

The matrix to multiply.

Returns:
Matrix4 -

A reference to this matrix.

scale(v) → {Matrix4}

Scales this matrix by the given 3D vector.

Parameters:
Name Type Description
v Vector3

A 3D vector representing a scaling.

Returns:
Matrix4 -

A reference to this matrix.

set(n11, n12, n13, n14, n21, n22, n23, n24, n31, n32, n33, n34, n41, n42, n43, n44) → {Matrix4}

Sets the given values to this matrix. The arguments are in row-major order.

Parameters:
Name Type Description
n11 Number

An element of the matrix.

n12 Number

An element of the matrix.

n13 Number

An element of the matrix.

n14 Number

An element of the matrix.

n21 Number

An element of the matrix.

n22 Number

An element of the matrix.

n23 Number

An element of the matrix.

n24 Number

An element of the matrix.

n31 Number

An element of the matrix.

n32 Number

An element of the matrix.

n33 Number

An element of the matrix.

n34 Number

An element of the matrix.

n41 Number

An element of the matrix.

n42 Number

An element of the matrix.

n43 Number

An element of the matrix.

n44 Number

An element of the matrix.

Returns:
Matrix4 -

A reference to this matrix.

setPosition(v) → {Matrix4}

Sets the translation part of the 4x4 matrix to the given position vector.

Parameters:
Name Type Description
v Vector3

A 3D vector representing a position.

Returns:
Matrix4 -

A reference to this matrix.

toArray(array, offset) → {Array.<Number>}

Copies all elements of this matrix to the given array.

Parameters:
Name Type Default Description
array Array.<Number>

An array.

offset Number 0

An optional offset.

Returns:
Array.<Number> -

The array with the elements of the matrix.

transpose() → {Matrix4}

Transposes this matrix.

Returns:
Matrix4 -

A reference to this matrix.