mat4

mat4()

4x4 Matrix
Format: column-major, when typed out it looks like row-major
The matrices are being post multiplied.

Methods

inneradd$3(out, a, b)mat4

Adds two mat4's
Name Type Description
out mat4 the receiving matrix
a mat4 the first operand
b mat4 the second operand
Returns:
out

inneradjoint$2(out, a)mat4

Calculates the adjugate of a mat4
Name Type Description
out mat4 the receiving matrix
a mat4 the source matrix
Returns:
out

innerclone$3(a)mat4

Creates a new mat4 initialized with values from an existing matrix
Name Type Description
a mat4 matrix to clone
Returns:
a new 4x4 matrix

innercopy$3(out, a)mat4

Copy the values from one mat4 to another
Name Type Description
out mat4 the receiving matrix
a mat4 the source matrix
Returns:
out

innercreate$3()mat4

Creates a new identity mat4
Returns:
a new 4x4 matrix

innerdeterminant$3(a)Number

Calculates the determinant of a mat4
Name Type Description
a mat4 the source matrix
Returns:
determinant of a

innerequals$4(a, b)Boolean

Returns whether or not the matrices have approximately the same elements in the same position.
Name Type Description
a mat4 The first matrix.
b mat4 The second matrix.
Returns:
True if the matrices are equal, false otherwise.

innerexactEquals$3(a, b)Boolean

Returns whether or not the matrices have exactly the same elements in the same position (when compared with ===)
Name Type Description
a mat4 The first matrix.
b mat4 The second matrix.
Returns:
True if the matrices are equal, false otherwise.

innerfrob$3(a)Number

Returns Frobenius norm of a mat4
Name Type Description
a mat4 the matrix to calculate Frobenius norm of
Returns:
Frobenius norm

innerfromQuat2(out, a)mat4

Creates a new mat4 from a dual quat.
Name Type Description
out mat4 Matrix
a quat2 Dual Quaternion
Returns:
mat4 receiving operation result

innerfromQuat$1(out, q)mat4

Calculates a 4x4 matrix from the given quaternion
Name Type Description
out mat4 mat4 receiving operation result
q quat Quaternion to create matrix from
Returns:
out

innerfromRotation$3(out, rad, axis)mat4

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);
Name Type Description
out mat4 mat4 receiving operation result
rad Number the angle to rotate the matrix by
axis vec3 the axis to rotate around
Returns:
out

innerfromRotationTranslation(out, q, v)mat4

Creates a matrix from a quaternion rotation and vector translation This is equivalent to (but much faster than): mat4.identity(dest); mat4.translate(dest, vec); let quatMat = mat4.create(); quat4.toMat4(quat, quatMat); mat4.multiply(dest, quatMat);
Name Type Description
out mat4 mat4 receiving operation result
q quat4 Rotation quaternion
v vec3 Translation vector
Returns:
out

innerfromRotationTranslationScale(out, q, v, s)mat4

Creates a matrix from a quaternion rotation, vector translation and vector scale This is equivalent to (but much faster than): mat4.identity(dest); mat4.translate(dest, vec); let quatMat = mat4.create(); quat4.toMat4(quat, quatMat); mat4.multiply(dest, quatMat); mat4.scale(dest, scale)
Name Type Description
out mat4 mat4 receiving operation result
q quat4 Rotation quaternion
v vec3 Translation vector
s vec3 Scaling vector
Returns:
out

innerfromRotationTranslationScaleOrigin(out, q, v, s, o)mat4

Creates a matrix from a quaternion rotation, vector translation and vector scale, rotating and scaling around the given origin This is equivalent to (but much faster than): mat4.identity(dest); mat4.translate(dest, vec); mat4.translate(dest, origin); let quatMat = mat4.create(); quat4.toMat4(quat, quatMat); mat4.multiply(dest, quatMat); mat4.scale(dest, scale) mat4.translate(dest, negativeOrigin);
Name Type Description
out mat4 mat4 receiving operation result
q quat4 Rotation quaternion
v vec3 Translation vector
s vec3 Scaling vector
o vec3 The origin vector around which to scale and rotate
Returns:
out

innerfromScaling$3(out, v)mat4

Creates a matrix from a vector scaling This is equivalent to (but much faster than): mat4.identity(dest); mat4.scale(dest, dest, vec);
Name Type Description
out mat4 mat4 receiving operation result
v vec3 Scaling vector
Returns:
out

innerfromTranslation$2(out, v)mat4

Creates a matrix from a vector translation This is equivalent to (but much faster than): mat4.identity(dest); mat4.translate(dest, dest, vec);
Name Type Description
out mat4 mat4 receiving operation result
v vec3 Translation vector
Returns:
out

innerfromValues$3(m00, m01, m02, m03, m10, m11, m12, m13, m20, m21, m22, m23, m30, m31, m32, m33)mat4

Create a new mat4 with the given values
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 mat4

innerfromXRotation(out, rad)mat4

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, rad);
Name Type Description
out mat4 mat4 receiving operation result
rad Number the angle to rotate the matrix by
Returns:
out

innerfromYRotation(out, rad)mat4

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, rad);
Name Type Description
out mat4 mat4 receiving operation result
rad Number the angle to rotate the matrix by
Returns:
out

innerfromZRotation(out, rad)mat4

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, rad);
Name Type Description
out mat4 mat4 receiving operation result
rad Number the angle to rotate the matrix by
Returns:
out

innerfrustum(out, left, right, bottom, top, near, far)mat4

Generates a frustum matrix with the given bounds
Name Type Description
out mat4 mat4 frustum matrix will be written into
left Number Left bound of the frustum
right Number Right bound of the frustum
bottom Number Bottom bound of the frustum
top Number Top bound of the frustum
near Number Near bound of the frustum
far Number Far bound of the frustum
Returns:
out

innergetRotation(out, mat)quat

Returns a quaternion representing the rotational component of a transformation matrix. If a matrix is built with fromRotationTranslation, the returned quaternion will be the same as the quaternion originally supplied.
Name Type Description
out quat Quaternion to receive the rotation component
mat mat4 Matrix to be decomposed (input)
Returns:
out

innergetScaling(out, mat)vec3

Returns the scaling factor component of a transformation matrix. If a matrix is built with fromRotationTranslationScale with a normalized Quaternion paramter, the returned vector will be the same as the scaling vector originally supplied.
Name Type Description
out vec3 Vector to receive scaling factor component
mat mat4 Matrix to be decomposed (input)
Returns:
out

innergetTranslation(out, mat)vec3

Returns the translation vector component of a transformation matrix. If a matrix is built with fromRotationTranslation, the returned vector will be the same as the translation vector originally supplied.
Name Type Description
out vec3 Vector to receive translation component
mat mat4 Matrix to be decomposed (input)
Returns:
out

inneridentity$3(out)mat4

Set a mat4 to the identity matrix
Name Type Description
out mat4 the receiving matrix
Returns:
out

innerinvert$3(out, a)mat4

Inverts a mat4
Name Type Description
out mat4 the receiving matrix
a mat4 the source matrix
Returns:
out

innerlookAt(out, eye, center, up)mat4

Generates a look-at matrix with the given eye position, focal point, and up axis. If you want a matrix that actually makes an object look at another object, you should use targetTo instead.
Name Type Description
out mat4 mat4 frustum matrix will be written into
eye vec3 Position of the viewer
center vec3 Point the viewer is looking at
up vec3 vec3 pointing up
Returns:
out

innermul$3()

Alias for mat4.multiply

innermultiply$3(out, a, b)mat4

Multiplies two mat4s
Name Type Description
out mat4 the receiving matrix
a mat4 the first operand
b mat4 the second operand
Returns:
out

innermultiplyScalar$3(out, a, b)mat4

Multiply each element of the matrix by a scalar.
Name Type Description
out mat4 the receiving matrix
a mat4 the matrix to scale
b Number amount to scale the matrix's elements by
Returns:
out

innermultiplyScalarAndAdd$3(out, a, b, scale)mat4

Adds two mat4's after multiplying each element of the second operand by a scalar value.
Name Type Description
out mat4 the receiving vector
a mat4 the first operand
b mat4 the second operand
scale Number the amount to scale b's elements by before adding
Returns:
out

innerortho(out, left, right, bottom, top, near, far)mat4

Generates a orthogonal projection matrix with the given bounds
Name Type Description
out mat4 mat4 frustum matrix will be written into
left number Left bound of the frustum
right number Right bound of the frustum
bottom number Bottom bound of the frustum
top number Top bound of the frustum
near number Near bound of the frustum
far number Far bound of the frustum
Returns:
out

innerperspective(out, fovy, aspect, near, far)mat4

Generates a perspective projection matrix with the given bounds. Passing null/undefined/no value for far will generate infinite projection matrix.
Name Type Description
out mat4 mat4 frustum matrix will be written into
fovy number Vertical field of view in radians
aspect number Aspect ratio. typically viewport width/height
near number Near bound of the frustum
far number Far bound of the frustum, can be null or Infinity
Returns:
out

innerperspectiveFromFieldOfView(out, fov, near, far)mat4

Generates a perspective projection matrix with the given field of view. This is primarily useful for generating projection matrices to be used with the still experiemental WebVR API.
Name Type Description
out mat4 mat4 frustum matrix will be written into
fov Object Object containing the following values: upDegrees, downDegrees, leftDegrees, rightDegrees
near number Near bound of the frustum
far number Far bound of the frustum
Returns:
out

innerrotate$3(out, a, rad, axis)mat4

Rotates a mat4 by the given angle around the given axis
Name Type Description
out mat4 the receiving matrix
a mat4 the matrix to rotate
rad Number the angle to rotate the matrix by
axis vec3 the axis to rotate around
Returns:
out

innerrotateX(out, a, rad)mat4

Rotates a matrix by the given angle around the X axis
Name Type Description
out mat4 the receiving matrix
a mat4 the matrix to rotate
rad Number the angle to rotate the matrix by
Returns:
out

innerrotateY(out, a, rad)mat4

Rotates a matrix by the given angle around the Y axis
Name Type Description
out mat4 the receiving matrix
a mat4 the matrix to rotate
rad Number the angle to rotate the matrix by
Returns:
out

innerrotateZ(out, a, rad)mat4

Rotates a matrix by the given angle around the Z axis
Name Type Description
out mat4 the receiving matrix
a mat4 the matrix to rotate
rad Number the angle to rotate the matrix by
Returns:
out

innerscale$3(out, a, v)mat4

Scales the mat4 by the dimensions in the given vec3 not using vectorization
Name Type Description
out mat4 the receiving matrix
a mat4 the matrix to scale
v vec3 the vec3 to scale the matrix by
Returns:
out

innerset$3(out, m00, m01, m02, m03, m10, m11, m12, m13, m20, m21, m22, m23, m30, m31, m32, m33)mat4

Set the components of a mat4 to the given values
Name Type Description
out mat4 the receiving matrix
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:
out

innerstr$3(a)String

Returns a string representation of a mat4
Name Type Description
a mat4 matrix to represent as a string
Returns:
string representation of the matrix

innersub$3()

Alias for mat4.subtract

innersubtract$3(out, a, b)mat4

Subtracts matrix b from matrix a
Name Type Description
out mat4 the receiving matrix
a mat4 the first operand
b mat4 the second operand
Returns:
out

innertargetTo(out, eye, center, up)mat4

Generates a matrix that makes something look at something else.
Name Type Description
out mat4 mat4 frustum matrix will be written into
eye vec3 Position of the viewer
center vec3 Point the viewer is looking at
up vec3 vec3 pointing up
Returns:
out

innertranslate$2(out, a, v)mat4

Translate a mat4 by the given vector
Name Type Description
out mat4 the receiving matrix
a mat4 the matrix to translate
v vec3 vector to translate by
Returns:
out

innertranspose$2(out, a)mat4

Transpose the values of a mat4
Name Type Description
out mat4 the receiving matrix
a mat4 the source matrix
Returns:
out