Matrix4

A 4x4 matrix, stored as a column-major order array.

Constructor

new L3D.Matrix4(…arguments)

Creates a new matrix.

// Creates an identity matrix.
new Matrix4()

// Creates a clone of the given matrix.
new Matrix4(Matrix4)

// Creates a Matrix4 from the given array.
new Matrix4(Array[16])

// Creates a zero matrix.
new Matarix4(0)

// Create a matrix from 16 individual elements in column major order
new Matrix4(m00, m01, m02, m03,
            m10, m11, m12, m13,
            m20, m21, m22, m23,
            m30, m31, m32, m33)
Parameters
arguments* *

Variable arguments for constructor overloading.

Extends

  • Float32Array

Properties

static Identity Matrix4

An identity Matrix4.

static Zero Matrix4

A Matrix4 filled with zeros.

Methods

clone()Matrix4

Make a copy of this matrix.

Returns
Matrix4

determinant() → number

Calculate the determinant of the matrix.

Returns
number

getColumn(index, out)Vector4

Get a column from the matrix.

Parameters
index number
out Vector4
Returns
Vector4

getColumn3(index, out)Vector3

Get a column from the matrix.

Parameters
index number
out Vector3
Returns
Vector3

getEulerAngles(out)Vector3

Extract the euler rotation angles, in degrees, from the matrix.

Parameters
out Vector3

Optional output storage for the results.

Returns
Vector3

getMatrix3(out)Matrix3

Gets the upper 3x3 portion of this matrix.

Parameters
out Matrix3
Returns
Matrix3

The Matrix3 containing the upper 3x3 portion of this matrix.

getQuaternion(out)Quaternion

Extract the rotation quaternion from the matrix.

Parameters
out Quaternion
Returns
Quaternion

getRow(index, out)Vector4

Get a row from the matrix.

Parameters
index number
out Vector4
Returns
Vector4

getRow3(index, out)Vector3

Get a row from the matrix.

Parameters
index number
out Vector3
Returns
Vector3

getScale(out)Vector3

Extracts the scaling component of this matrix.

Parameters
out Vector3

optional storage for the results.

Returns
Vector3

getTranslation(out)Vector3

Extracts the translational component of this matrix.

Parameters
out Vector3

optional storage for the results.

Returns
Vector3

getX(out)Vector3

Extracts the x-axis from this matrix.

Parameters
out Vector3

optional storage for the results.

Returns
Vector3

getY(out)Vector3

Extracts the y-axis from this matrix.

Parameters
out Vector3

optional storage for the results.

Returns
Vector3

getZ(out)Vector3

Extracts the z-axis from this matrix.

Parameters
out Vector3

optional storage for the results.

Returns
Vector3

invert(out)Matrix4

Invert the matrix.

Parameters
out Matrix4

Optional storage for the inverted matrix. If not provided, invert itself.

Returns
Matrix4

invertToMatrix3(out)Matrix3

Inverts the upper 3x3 portion of this matrix, returning it as a Matrix3.

Parameters
out Matrix3

optional storage for the results.

Returns
Matrix3

isIdentity() → Boolean

Checks if this is an identity matrix.

Returns
Boolean

true if this is an identity matrix.

normalizeScale()Matrix4

Remove any scaling from the matrix.

Returns
Matrix4

Returns this matrix.

rotateAxisAngle(angle, axis)Matrix4

Rotate the matrix around an axis vector by an angle amount.

Parameters
angle number

The angle to rotate, in degrees.

axis Vector3

The axis to rotate around.

Returns
Matrix4

Returns this matrix.

rotateEuler()Matrix4

Rotate the matrix by the given euler angles. Angles are given in degrees.

rotateEuler(x, y, z, order = RotationOrder.Default)
rotateEuler(Vector3, order = RotationOrder.Default)
Returns
Matrix4

Returns this matrix.

rotateQuaternion(arguments)Matrix4

Rotate the matrix by a quaternion.

Parameters
arguments *

Can either be a Quaternion, or 4 numbers.

Returns
Matrix4

Returns this matrix.

rotateX(angle)Matrix4

Rotate the matrix around the X axis.

Parameters
angle number

The amount to rotate, in degrees.

Returns
Matrix4

Returns this matrix.

rotateY(angle)Matrix4

Rotate the matrix around the Y axis.

Parameters
angle number

The amount to rotate, in degrees.

Returns
Matrix4

Returns this matrix.

rotateZ(angle)Matrix4

Rotate the matrix around the Z axis.

Parameters
angle number

The amount to rotate, in degrees.

Returns
Matrix4

Returns this matrix.

scale(arguments)Matrix4

Scale the matrix

scale(Vector3)
scale(x, y, z)
Parameters
arguments *

Can either be a Vector3 or 3 numbers.

Returns
Matrix4

Returns this matrix.

setAlignToVector(d, z, out)

Create a rotation matrix that aligns [v1] to [v2]. From https://iquilezles.org/articles/noacos/

Parameters
d Vector3
z Vector3
out Matrix4

setAxisAngle()

setAxisAngle(angle, x, y, z)

setAxisAngle(angle, [x, y, z])

setAxisAngle(angle, Vector3)

setColumn()

setColumn(column, Vector3)
setColumn(column, Vector4)
setColumn(column, x, y, z)
setColumn(column, x, y, z, w)

setColumns(x, y, z, translate)

Set the matrix from a set of vector columns

Parameters
x *
y *
z *
translate *

setEulerAngles()

Set the matrix as an euler rotation. Angles are given in degrees.

setEulerAngles(x, y, z, order = RotationOrder.ZYX)

setEulerAngles(Vector3, order = RotationOrder.ZYX)

setFrom()

setFrom(m00, m01, m02, m03, m10, m11, m12, m13, m20, m21, m22, m23, m30, m31, m32, m33)

setFrom([m00, m01, m02, m03, m10, m11, m12, m13, m20, m21, m22, m23, m30, m31, m32, m33])

setFrom(Matrix4)

setIdentity()

Set the matrix as an identity matrix.

setLookAt(eye, center, up)

Set the matrix as a look-at transformation

Parameters
eye *
center *
up *

setOrtho(left, right, bottom, top, near, far)

Set as an orthographic projection matrix.

Parameters
left *
right *
bottom *
top *
near *
far *

setPerspective(fovx, aspect, near, far)

Set as a perspective projection matrix.

Parameters
fovx number

Horizontal field of view, in radians

aspect number

Aspect ratio

near number

Distance to the near clipping plane

far number

Distance to the far clipping plane

setQuaternion()

setQuaternion(x, y, z, w)

setQuaternion([x, y, z, w])

setQuaternion(Quaternion)

setRotateX(angle)

Set the matrix as a rotation around the X axis.

Parameters
angle number

Angle of the rotation, in radians.

setRotateY(angle)

Set the matrix as a rotation around the Y axis.

Parameters
angle number

Angle of the rotation, in degrees.

setRotateZ(angle)

Set the matrix as a rotation around the Z axis.

Parameters
angle

Angle of the rotation, in degrees.

setRow()

setRow(row, Vector3)

setRow(row, Vector4)

setRow(row, x, y, z)

setRow(row, x, y, z, w)

setScale()

setScale(x, y, z)

setScale([x, y, z])

setScale(Vector3)

setTransform(t, q, s)

Sets the matrix to the concatination of a translation, rotation by quaternion, and scale.

Parameters
t Vector3

The translation of the matrix.

q Vector3

The quaternion orientation of the matrix.

s Vector3

The scale of the matrix.

setTranslate()

setTranslate(x, y, z)

setTranslate([x, y, z])

setTranslate(Vector3)

toArray() → Array

Convert the matrix to an array.

Returns
Array

An array containing the values of the matrix.

transformVector3(v, w, out)Vector3

Transform a Vector3

Parameters
v Vector3

The Vector3 to transform

w number

The w coordinate of the vector. 0 for a vector, 1 for a point. Default 1.

out Vector3

Optional storage for the results.

Returns
Vector3

transformVector4(v, out)Vector4

Transform a Vector4

Parameters
v Vector4

The Vector4 to transform

out Vector4

Optional storage for the results.

Returns
Vector4

translate(arguments)Matrix4

Translate the matrix.

translate(Vector3)
translate(x, y, z)
Parameters
arguments *

Can either be a Vector3 or 3 numbers.

Returns
Matrix4

Returns this matrix.

transpose()Matrix4

Transpose the matrix.

Returns
Matrix4

Returns this matrix.

static invert(m, out)Matrix4

Invert a Matrix4.

Parameters
m Matrix4
out Matrix4
Returns
Matrix4

static multiply(a, b, out)Matrix4

Multiply two Matrix4s.

Parameters
a Matrix4
b Matrix4
out Matrix4
Returns
Matrix4

static scale(m, v, out)Matrix4

Scale a Matrix4.

Parameters
m Matrix4
v Vector3
out Matrix4
Returns
Matrix4

static translate(m, v, out)Matrix4

Translate a Matrix4.

Parameters
m Matrix4
v Vector3
out Matrix4
Returns
Matrix4

static transpose(m, out)Matrix4

Transpose a Matrix4.

Parameters
m Matrix4
out Matrix4
Returns
Matrix4