modeling/maths/mat4

Represents a 4x4 matrix which is column-major (when typed out it looks row-major).

Source:
See:
  • mat4 for data structure information.

Methods

(static) add(out, a, b) → {mat4}

Source:

Adds the two matrices (A+B).

Parameters:
Name Type Description
out mat4

receiving matrix

a mat4

first operand

b mat4

second operand

Returns:

out

Type
mat4

(static) clone(matrix) → {mat4}

Source:

Creates a clone of the given matrix.

Parameters:
Name Type Description
matrix mat4

matrix to clone

Returns:

a new matrix

Type
mat4

(static) copy(out, matrix) → {mat4}

Source:

Creates a copy of the given matrix.

Parameters:
Name Type Description
out mat4

receiving matrix

matrix mat4

matrix to copy

Returns:

out

Type
mat4

(static) create() → {mat4}

Source:

Creates a new identity matrix.

Returns:

a new matrix

Type
mat4

(static) equals(a, b) → {Boolean}

Source:

Returns whether or not the matrices have exactly the same elements in the same position.

Parameters:
Name Type Description
a mat4

first matrix

b mat4

second matrix

Returns:

true if the matrices are equal

Type
Boolean

(static) fromRotation(out, rad, axis) → {mat4}

Source:

Creates a matrix from a given angle around a given axis This is equivalent to (but much faster than):

mat4.identity(dest)
mat4.rotate(dest, dest, rad, axis)
Example
let matrix = fromRotation(create(), Math.PI / 2, [0, 0, 3])
Parameters:
Name Type Description
out mat4

receiving matrix

rad Number

angle to rotate the matrix by

axis vec3

axis of which to rotate around

Returns:

out

Type
mat4

(static) fromScaling(out, vector) → {mat4}

Source:

Creates a matrix from a vector scaling. This is equivalent to (but much faster than):

mat4.identity(dest)
mat4.scale(dest, dest, vec)
Example
let matrix = fromScaling([1, 2, 0.5])
Parameters:
Name Type Description
out mat4

receiving matrix

vector vec3

X, Y, Z factors by which to scale

Returns:

out

Type
mat4

(static) fromTaitBryanRotation(out, yaw, pitch, roll) → {mat4}

Source:
See:

Creates a matrix from the given Tait–Bryan angles.

Tait-Bryan Euler angle convention using active, intrinsic rotations around the axes in the order z-y-x.

Example
let matrix = fromTaitBryanRotation(create(), Math.PI / 2, 0, Math.PI)
Parameters:
Name Type Description
out mat4

receiving matrix

yaw Number

Z rotation in radians

pitch Number

Y rotation in radians

roll Number

X rotation in radians

Returns:

out

Type
mat4

(static) fromTranslation(out, vector) → {mat4}

Source:

Creates a matrix from a vector translation. This is equivalent to (but much faster than):

mat4.identity(dest)
mat4.translate(dest, dest, vec)
Example
let matrix = fromTranslation(create(), [1, 2, 3])
Parameters:
Name Type Description
out mat4

receiving matrix

vector vec3

offset (vector) of translation

Returns:

out

Type
mat4

(static) fromValues(m00, m01, m02, m03, m10, m11, m12, m13, m20, m21, m22, m23, m30, m31, m32, m33) → {mat4}

Source:

Create a matrix with the given values.

Example
let matrix = fromValues(
  1, 0, 0, 1,
  0, 1, 0, 0,
  0, 0, 1, 0,
  0, 0, 0, 1
)
Parameters:
Name Type Description
m00 Number

Component in column 0, row 0 position (index 0)

m01 Number

Component in column 0, row 1 position (index 1)

m02 Number

Component in column 0, row 2 position (index 2)

m03 Number

Component in column 0, row 3 position (index 3)

m10 Number

Component in column 1, row 0 position (index 4)

m11 Number

Component in column 1, row 1 position (index 5)

m12 Number

Component in column 1, row 2 position (index 6)

m13 Number

Component in column 1, row 3 position (index 7)

m20 Number

Component in column 2, row 0 position (index 8)

m21 Number

Component in column 2, row 1 position (index 9)

m22 Number

Component in column 2, row 2 position (index 10)

m23 Number

Component in column 2, row 3 position (index 11)

m30 Number

Component in column 3, row 0 position (index 12)

m31 Number

Component in column 3, row 1 position (index 13)

m32 Number

Component in column 3, row 2 position (index 14)

m33 Number

Component in column 3, row 3 position (index 15)

Returns:

a new matrix

Type
mat4

(static) fromVectorRotation(out, source, target) → {mat4}

Source:
See:

Create a matrix that rotates the given source to the given target vector.

Each vector must be a directional vector with a length greater then zero.

Example
let matrix = fromVectorRotation(mat4.create(), [1, 2, 2], [-3, 3, 12])
Parameters:
Name Type Description
out mat4

receiving matrix

source vec3

source vector

target vec3

target vector

Returns:

a new matrix

Type
mat4

(static) fromXRotation(out, radians) → {mat4}

Source:

Creates a matrix from the given angle around the X axis. This is equivalent to (but much faster than):

mat4.identity(dest)
mat4.rotateX(dest, dest, radians)
Example
let matrix = fromXRotation(create(), Math.PI / 2)
Parameters:
Name Type Description
out mat4

receiving matrix

radians Number

angle to rotate the matrix by

Returns:

out

Type
mat4

(static) fromYRotation(out, radians) → {mat4}

Source:

Creates a matrix from the given angle around the Y axis. This is equivalent to (but much faster than):

mat4.identity(dest)
mat4.rotateY(dest, dest, radians)
Example
let matrix = fromYRotation(create(), Math.PI / 2)
Parameters:
Name Type Description
out mat4

receiving matrix

radians Number

angle to rotate the matrix by

Returns:

out

Type
mat4

(static) fromZRotation(out, radians) → {mat4}

Source:

Creates a matrix from the given angle around the Z axis. This is equivalent to (but much faster than):

mat4.identity(dest)
mat4.rotateZ(dest, dest, radians)
Example
let matrix = fromZRotation(create(), Math.PI / 2)
Parameters:
Name Type Description
out mat4

receiving matrix

radians Number

angle to rotate the matrix by

Returns:

out

Type
mat4

(static) identity(out) → {mat4}

Source:

Set a matrix to the identity transform.

Parameters:
Name Type Description
out mat4

receiving matrix

Returns:

out

Type
mat4

(static) invert(out, m) → {mat4}

Source:
Author:
  • Julian Lloyd code from https://github.com/jlmakes/rematrix/blob/master/src/index.js

Creates a invert copy of the given matrix.

Parameters:
Name Type Description
out mat4

receiving matrix

m mat4

matrix to invert

Returns:

out

Type
mat4

(static) isIdentity(matrix) → {Boolean}

Source:

Determine whether the given matris is the identity transform. This is equivalent to (but much faster than):

mat4.equals(mat4.create(), matrix)
Example
if (mat4.isIdentity(mymatrix)) ...
Parameters:
Name Type Description
matrix mat4

the matrix

Returns:

true if matrix is the identity transform

Type
Boolean

(static) isMirroring(matrix) → {Boolean}

Source:

Determine whether the given matrix is a mirroring transformation.

Parameters:
Name Type Description
matrix mat4

matrix of reference

Returns:

true if matrix is a mirroring transformation

Type
Boolean

(static) mirrorByPlane(out, plane) → {mat4}

Source:

Create a matrix for mirroring about the given plane.

Parameters:
Name Type Description
out mat4

receiving matrix

plane vec4

plane of which to mirror the matrix

Returns:

out

Type
mat4

(static) multiply(out, a, b) → {mat4}

Source:

Multiplies the two matrices.

Parameters:
Name Type Description
out mat4

receiving matrix

a mat4

first operand

b mat4

second operand

Returns:

out

Type
mat4

(static) rightMultiplyVec2(vector, matrix) → {vec2}

Source:

Multiply a 2D vector by a matrix (interpreted as 2 row, 1 column).

Calculation: result = v*M, where the fourth element is set to 1.

Parameters:
Name Type Description
vector vec2

input vector

matrix mat4

input matrix

Returns:

a new vector

Type
vec2

(static) rightMultiplyVec3(vector, matrix) → {vec3}

Source:

Multiply a 3D vector by a matrix (interpreted as 3 row, 1 column)

Calculation: result = v*M, where the fourth element is set to 1.

Parameters:
Name Type Description
vector vec3

input vector

matrix mat4

input matrix

Returns:

a new vector

Type
vec3

(static) rotate(out, matrix, radians, axis) → {mat4}

Source:

Rotates a matrix by the given angle about the given axis.

Parameters:
Name Type Description
out mat4

receiving matrix

matrix mat4

matrix to rotate

radians Number

angle to rotate the matrix by

axis vec3

axis to rotate around

Returns:

out

Type
mat4

(static) rotateX(out, matrix, radians) → {mat4}

Source:

Rotates a matrix by the given angle around the X axis.

Parameters:
Name Type Description
out mat4

receiving matrix

matrix mat4

matrix to rotate

radians Number

angle to rotate the matrix by

Returns:

out

Type
mat4

(static) rotateY(out, matrix, radians) → {mat4}

Source:

Rotates a matrix by the given angle around the Y axis.

Parameters:
Name Type Description
out mat4

receiving matrix

matrix mat4

matrix to rotate

radians Number

angle to rotate the matrix by

Returns:

out

Type
mat4

(static) rotateZ(out, matrix, radians) → {mat4}

Source:

Rotates a matrix by the given angle around the Z axis.

Parameters:
Name Type Description
out mat4

receiving matrix

matrix mat4

matrix to rotate

radians Number

angle to rotate the matrix by

Returns:

out

Type
mat4

(static) scale(out, matrix, dimensions) → {mat4}

Source:

Scales the matrix by the given dimensions.

Parameters:
Name Type Description
out mat4

receiving matrix

matrix mat4

matrix to scale

dimensions vec3

dimensions to scale the matrix by

Returns:

out

Type
mat4

(static) subtract(out, a, b) → {mat4}

Source:

Subtracts matrix b from matrix a. (A-B)

Parameters:
Name Type Description
out mat4

receiving matrix

a mat4

first operand

b mat4

second operand

Returns:

out

Type
mat4

(static) toString(matrix) → {String}

Source:

Return a string representing the given matrix.

Parameters:
Name Type Description
matrix mat4

matrix of reference

Returns:

string representation

Type
String

(static) translate(out, matrix, offsets) → {mat4}

Source:

Translate the matrix by the given offset vector.

Parameters:
Name Type Description
out mat4

receiving matrix

matrix mat4

matrix to translate

offsets vec3

offset vector to translate by

Returns:

out

Type
mat4