# Namespace: mat4

# Table of contents

# Type aliases

# Functions

# Type aliases

# valueType

Ƭ valueType: mat4type

# Functions

# add

▸ add(out: mat4type, a: mat4type, b: mat4type): mat4type

Adds two mat4's

# Parameters
Name Type Description
out mat4type the receiving matrix
a mat4type the first operand
b mat4type the second operand

Returns: mat4type

out


# adjoint

▸ adjoint(out: mat4type, a: mat4type): mat4type

Calculates the adjugate of a mat4

# Parameters
Name Type Description
out mat4type the receiving matrix
a mat4type the source matrix

Returns: mat4type

out


# clone

▸ clone(a: mat4type): mat4type

Creates a new mat4 initialized with values from an existing matrix

# Parameters
Name Type Description
a mat4type matrix to clone

Returns: mat4type

a new 4x4 matrix


# copy

▸ copy(out: mat4type, a: mat4type): mat4type

Copy the values from one mat4 to another

# Parameters
Name Type Description
out mat4type the receiving matrix
a mat4type the source matrix

Returns: mat4type

out


# create

▸ create(): mat4type

Creates a new identity mat4

Returns: mat4type

a new 4x4 matrix


# determinant

▸ determinant(a: mat4type): number

Calculates the determinant of a mat4

# Parameters
Name Type Description
a mat4type the source matrix

Returns: number

determinant of a


# equals

▸ equals(a: mat4type, b: mat4type): boolean

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

# Parameters
Name Type Description
a mat4type The first matrix.
b mat4type The second matrix.

Returns: boolean

True if the matrices are equal, false otherwise.


# exactEquals

▸ exactEquals(a: mat4type, b: mat4type): boolean

Returns whether or not the matrices have exactly the same elements in the same position (when compared with ===)

# Parameters
Name Type Description
a mat4type The first matrix.
b mat4type The second matrix.

Returns: boolean

True if the matrices are equal, false otherwise.


# frob

▸ frob(a: mat4type): number

Returns Frobenius norm of a mat4

# Parameters
Name Type Description
a mat4type the matrix to calculate Frobenius norm of

Returns: number

Frobenius norm


# fromQuat

▸ fromQuat(out: mat4type, q: quattype): mat4type

Calculates a 4x4 matrix from the given quaternion

# Parameters
Name Type Description
out mat4type mat4 receiving operation result
q quattype Quaternion to create matrix from

Returns: mat4type

out


# fromRotation

▸ fromRotation(out: mat4type, rad: number, axis: vec3type): mat4type | null

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);
# Parameters
Name Type Description
out mat4type mat4 receiving operation result
rad number the angle to rotate the matrix by
axis vec3type the axis to rotate around

Returns: mat4type | null

out


# fromRotationTranslation

▸ fromRotationTranslation(out: mat4type, q: quattype, v: vec3type): mat4type

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);
var quatMat = mat4.create();
quat.toMat4(quat, quatMat);
mat4.multiply(dest, quatMat);
# Parameters
Name Type Description
out mat4type mat4 receiving operation result
q quattype Rotation quaternion
v vec3type Translation vector

Returns: mat4type

out


# fromRotationTranslationScale

▸ fromRotationTranslationScale(out: mat4type, q: quattype, v: vec3type, s: vec3type): mat4type

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);
var quatMat = mat4.create();
quat4.toMat4(quat, quatMat);
mat4.multiply(dest, quatMat);
mat4.scale(dest, scale)
# Parameters
Name Type Description
out mat4type mat4 receiving operation result
q quattype Rotation quaternion
v vec3type Translation vector
s vec3type Scaling vector

Returns: mat4type

out


# fromRotationTranslationScaleOrigin

▸ fromRotationTranslationScaleOrigin(out: mat4type, q: quattype, v: vec3type, s: vec3type, o: vec3type): mat4type

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);
var quatMat = mat4.create();
quat4.toMat4(quat, quatMat);
mat4.multiply(dest, quatMat);
mat4.scale(dest, scale)
mat4.translate(dest, negativeOrigin);
# Parameters
Name Type Description
out mat4type mat4 receiving operation result
q quattype Rotation quaternion
v vec3type Translation vector
s vec3type Scaling vector
o vec3type The origin vector around which to scale and rotate

Returns: mat4type

out


# fromScaling

▸ fromScaling(out: mat4type, v: vec3type): mat4type

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

mat4.identity(dest);
mat4.scale(dest, dest, vec);
# Parameters
Name Type Description
out mat4type mat4 receiving operation result
v vec3type Scaling vector

Returns: mat4type

out


# fromTranslation

▸ fromTranslation(out: mat4type, v: vec3type): mat4type

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

mat4.identity(dest);
mat4.translate(dest, dest, vec);
# Parameters
Name Type Description
out mat4type mat4 receiving operation result
v vec3type Translation vector

Returns: mat4type

out


# fromValues

▸ fromValues(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): mat4type

Create a new mat4 with the given values

# 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: mat4type

A new mat4


# fromXRotation

▸ fromXRotation(out: mat4type, rad: number): mat4type

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);
# Parameters
Name Type Description
out mat4type mat4 receiving operation result
rad number the angle to rotate the matrix by

Returns: mat4type

out


# fromYRotation

▸ fromYRotation(out: mat4type, rad: number): mat4type

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);
# Parameters
Name Type Description
out mat4type mat4 receiving operation result
rad number the angle to rotate the matrix by

Returns: mat4type

out


# fromZRotation

▸ fromZRotation(out: mat4type, rad: number): mat4type

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);
# Parameters
Name Type Description
out mat4type mat4 receiving operation result
rad number the angle to rotate the matrix by

Returns: mat4type

out


# frustum

▸ frustum(out: mat4type, left: number, right: number, bottom: number, top: number, near: number, far: number): mat4type

Generates a frustum matrix with the given bounds

# Parameters
Name Type Description
out mat4type 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: mat4type

out


# getRotation

▸ getRotation(out: vec4type, mat: mat4type): quattype

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.

# Parameters
Name Type Description
out vec4type Quaternion to receive the rotation component
mat mat4type Matrix to be decomposed (input)

Returns: quattype

out


# getScaling

▸ getScaling(out: vec3type, mat: mat4type): vec3type

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.

# Parameters
Name Type Description
out vec3type Vector to receive scaling factor component
mat mat4type Matrix to be decomposed (input)

Returns: vec3type

out


# getTranslation

▸ getTranslation(out: vec3type, mat: mat4type): vec3type

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.

# Parameters
Name Type Description
out vec3type Vector to receive translation component
mat mat4type Matrix to be decomposed (input)

Returns: vec3type

out


# identity

▸ identity(out: mat4type): mat4type

Set a mat4 to the identity matrix

# Parameters
Name Type Description
out mat4type the receiving matrix

Returns: mat4type

out


# invert

▸ invert(out: mat4type, a: mat4type): mat4type | null

Inverts a mat4

# Parameters
Name Type Description
out mat4type the receiving matrix
a mat4type the source matrix

Returns: mat4type | null

out


# lookAt

▸ lookAt(out: mat4type, eye: vec3type, center: vec3type, up: vec3type): mat4type

Generates a look-at matrix with the given eye position, focal point, and up axis

# Parameters
Name Type Description
out mat4type mat4 frustum matrix will be written into
eye vec3type Position of the viewer
center vec3type Point the viewer is looking at
up vec3type vec3 pointing up

Returns: mat4type

out


# multiply

▸ multiply(out: mat4type, a: mat4type, b: mat4type): mat4type

Multiplies two mat4s

# Parameters
Name Type Description
out mat4type the receiving matrix
a mat4type the first operand
b mat4type the second operand

Returns: mat4type

out


# multiplyScalar

▸ multiplyScalar(out: mat4type, a: mat4type, b: number): mat4type

Multiply each element of the matrix by a scalar.

# Parameters
Name Type Description
out mat4type the receiving matrix
a mat4type the matrix to scale
b number amount to scale the matrix's elements by

Returns: mat4type

out


# multiplyScalarAndAdd

▸ multiplyScalarAndAdd(out: mat4type, a: mat4type, b: mat4type, s: number): mat4type

Adds two mat4's after multiplying each element of the second operand by a scalar value.

# Parameters
Name Type Description
out mat4type the receiving vector
a mat4type the first operand
b mat4type the second operand
s number the amount to scale b's elements by before adding

Returns: mat4type

out


# ortho

▸ ortho(out: mat4type, left: number, right: number, bottom: number, top: number, near: number, far: number): mat4type

Generates a orthogonal projection matrix with the given bounds

# Parameters
Name Type Description
out mat4type 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: mat4type

out


# perspective

▸ perspective(out: mat4type, fovy: number, aspect: number, near: number, far: number): mat4type

Generates a perspective projection matrix with the given bounds

# Parameters
Name Type Description
out mat4type 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

Returns: mat4type

out


# perspectiveFromFieldOfView

▸ perspectiveFromFieldOfView(out: mat4type, fov: { downDegrees: number ; leftDegrees: number ; rightDegrees: number ; upDegrees: number }, near: number, far: number): mat4type

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.

# Parameters
Name Type Description
out mat4type mat4 frustum matrix will be written into
fov object Object containing the following values: upDegrees, downDegrees, leftDegrees, rightDegrees
fov.downDegrees number -
fov.leftDegrees number -
fov.rightDegrees number -
fov.upDegrees number -
near number Near bound of the frustum
far number Far bound of the frustum

Returns: mat4type

out


# rotate

▸ rotate(out: mat4type, a: mat4type, rad: number, axis: vec3type): mat4type | null

Rotates a mat4 by the given angle around the given axis

# Parameters
Name Type Description
out mat4type the receiving matrix
a mat4type the matrix to rotate
rad number the angle to rotate the matrix by
axis vec3type the axis to rotate around

Returns: mat4type | null

out


# rotateX

▸ rotateX(out: mat4type, a: mat4type, rad: number): mat4type

Rotates a matrix by the given angle around the X axis

# Parameters
Name Type Description
out mat4type the receiving matrix
a mat4type the matrix to rotate
rad number the angle to rotate the matrix by

Returns: mat4type

out


# rotateY

▸ rotateY(out: mat4type, a: mat4type, rad: number): mat4type

Rotates a matrix by the given angle around the Y axis

# Parameters
Name Type Description
out mat4type the receiving matrix
a mat4type the matrix to rotate
rad number the angle to rotate the matrix by

Returns: mat4type

out


# rotateZ

▸ rotateZ(out: mat4type, a: mat4type, rad: number): mat4type

Rotates a matrix by the given angle around the Z axis

# Parameters
Name Type Description
out mat4type the receiving matrix
a mat4type the matrix to rotate
rad number the angle to rotate the matrix by

Returns: mat4type

out


# scale

▸ scale(out: mat4type, a: mat4type, v: vec3type): mat4type

Scales the mat4 by the dimensions in the given vec3 not using vectorization

# Parameters
Name Type Description
out mat4type the receiving matrix
a mat4type the matrix to scale
v vec3type the vec3 to scale the matrix by

Returns: mat4type

out


# set

▸ set(out: mat4type, 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): mat4type

Set the components of a mat4 to the given values

# Parameters
Name Type Description
out mat4type 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: mat4type

out


# str

▸ str(a: mat4type): string

Returns a string representation of a mat4

# Parameters
Name Type Description
a mat4type matrix to represent as a string

Returns: string

string representation of the matrix


# subtract

▸ subtract(out: mat4type, a: mat4type, b: mat4type): mat4type

Subtracts matrix b from matrix a

# Parameters
Name Type Description
out mat4type the receiving matrix
a mat4type the first operand
b mat4type the second operand

Returns: mat4type

out


# translate

▸ translate(out: mat4type, a: mat4type, v: vec3type): mat4type

Translate a mat4 by the given vector

# Parameters
Name Type Description
out mat4type the receiving matrix
a mat4type the matrix to translate
v vec3type vector to translate by

Returns: mat4type

out


# transpose

▸ transpose(out: mat4type, a: mat4type): mat4type

Transpose the values of a mat4

# Parameters
Name Type Description
out mat4type the receiving matrix
a mat4type the source matrix

Returns: mat4type

out

vjmap / Exports / Math2D