gl-matrix (master) doxdox documentation

Javascript Matrix and Vector library for High Performance WebGL apps

# include()

Pull in the contents of an external file at the given path.

# makeSignature()

Build output for displaying function parameters.

# makeSortby()

Make a symbol sorter by some attribute.

# makeSrcFile()

Turn a raw source file into a code-hilited page in the docs.

# publish()

Called automatically by JsDoc Toolkit.

# resolveLinks()

Find symbol {@link ...} strings in text and turn into html links

# summarize()

Just the first sentence (up to a full stop). Should not break on dotted variable names.

# equals(a, b)

Tests whether or not the arguments have approximately the same value, within an absolute or relative tolerance of glMatrix.EPSILON (an absolute tolerance is used for values less than or equal to 1.0, and a relative tolerance is used for larger values)

Parameters

Name Types Description
a Number The first number to test.
b Number The second number to test.

# round(a)

Symmetric round see https://www.npmjs.com/package/round-half-up-symmetric#user-content-detailed-background

Parameters

Name Types Description
a Number value to round

# setMatrixArrayType(type)

Sets the type of array used when creating new vectors and matrices

Parameters

Name Types Description
type Float32ArrayConstructor ArrayConstructor

# toDegree(a)

Convert Radian To Degree

Parameters

Name Types Description
a Number Angle in Radians

# toRadian(a)

Convert Degree To Radian

Parameters

Name Types Description
a Number Angle in Degrees

# add(out, a, b)

Adds two mat2's

Parameters

Name Types Description
out mat2 the receiving matrix
a ReadonlyMat2 the first operand
b ReadonlyMat2 the second operand

# adjoint(out, a)

Calculates the adjugate of a mat2

Parameters

Name Types Description
out mat2 the receiving matrix
a ReadonlyMat2 the source matrix

# clone(a)

Creates a new mat2 initialized with values from an existing matrix

Parameters

Name Types Description
a ReadonlyMat2 matrix to clone

# copy(out, a)

Copy the values from one mat2 to another

Parameters

Name Types Description
out mat2 the receiving matrix
a ReadonlyMat2 the source matrix

# create()

Creates a new identity mat2

# determinant(a)

Calculates the determinant of a mat2

Parameters

Name Types Description
a ReadonlyMat2 the source matrix

# equals(a, b)

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

Parameters

Name Types Description
a ReadonlyMat2 The first matrix.
b ReadonlyMat2 The second matrix.

# exactEquals(a, b)

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

Parameters

Name Types Description
a ReadonlyMat2 The first matrix.
b ReadonlyMat2 The second matrix.

# frob(a)

Returns Frobenius norm of a mat2

Parameters

Name Types Description
a ReadonlyMat2 the matrix to calculate Frobenius norm of

# fromRotation(out, a, v)

Scales the mat2 by the dimensions in the given vec2

Parameters

Name Types Description
out mat2 the receiving matrix
a ReadonlyMat2 the matrix to rotate
v ReadonlyVec2 the vec2 to scale the matrix by

# fromScaling(out, v)

Creates a matrix from a vector scaling This is equivalent to (but much faster than): mat2.identity(dest); mat2.scale(dest, dest, vec);

Parameters

Name Types Description
out mat2 mat2 receiving operation result
v ReadonlyVec2 Scaling vector

# fromValues(m00, m01, m10, m11)

Create a new mat2 with the given values

Parameters

Name Types Description
m00 Number Component in column 0, row 0 position (index 0)
m01 Number Component in column 0, row 1 position (index 1)
m10 Number Component in column 1, row 0 position (index 2)
m11 Number Component in column 1, row 1 position (index 3)

# identity(out)

Set a mat2 to the identity matrix

Parameters

Name Types Description
out mat2 the receiving matrix

# invert(out, a)

Inverts a mat2

Parameters

Name Types Description
out mat2 the receiving matrix
a ReadonlyMat2 the source matrix

# LDU(L, D, U, a)

Returns L, D and U matrices (Lower triangular, Diagonal and Upper triangular) by factorizing the input matrix

Parameters

Name Types Description
L ReadonlyMat2 the lower triangular matrix
D ReadonlyMat2 the diagonal matrix
U ReadonlyMat2 the upper triangular matrix
a ReadonlyMat2 the input matrix to factorize

# mul()

Alias for {@link mat2.multiply}

# multiply(out, a, b)

Multiplies two mat2's

Parameters

Name Types Description
out mat2 the receiving matrix
a ReadonlyMat2 the first operand
b ReadonlyMat2 the second operand

# multiplyScalar(out, a, b)

Multiply each element of the matrix by a scalar.

Parameters

Name Types Description
out mat2 the receiving matrix
a ReadonlyMat2 the matrix to scale
b Number amount to scale the matrix's elements by

# multiplyScalarAndAdd(out, a, b, scale)

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

Parameters

Name Types Description
out mat2 the receiving vector
a ReadonlyMat2 the first operand
b ReadonlyMat2 the second operand
scale Number the amount to scale b's elements by before adding

# rotate(out, a, rad)

Rotates a mat2 by the given angle

Parameters

Name Types Description
out mat2 the receiving matrix
a ReadonlyMat2 the matrix to rotate
rad Number the angle to rotate the matrix by

# set(out, m00, m01, m10, m11)

Set the components of a mat2 to the given values

Parameters

Name Types Description
out mat2 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)
m10 Number Component in column 1, row 0 position (index 2)
m11 Number Component in column 1, row 1 position (index 3)

# str(a)

Returns a string representation of a mat2

Parameters

Name Types Description
a ReadonlyMat2 matrix to represent as a string

# sub()

Alias for {@link mat2.subtract}

# subtract(out, a, b)

Subtracts matrix b from matrix a

Parameters

Name Types Description
out mat2 the receiving matrix
a ReadonlyMat2 the first operand
b ReadonlyMat2 the second operand

# transpose(out, a)

Transpose the values of a mat2

Parameters

Name Types Description
out mat2 the receiving matrix
a ReadonlyMat2 the source matrix

# add(out, a, b)

Adds two mat2d's

Parameters

Name Types Description
out mat2d the receiving matrix
a ReadonlyMat2d the first operand
b ReadonlyMat2d the second operand

# clone(a)

Creates a new mat2d initialized with values from an existing matrix

Parameters

Name Types Description
a ReadonlyMat2d matrix to clone

# copy(out, a)

Copy the values from one mat2d to another

Parameters

Name Types Description
out mat2d the receiving matrix
a ReadonlyMat2d the source matrix

# create()

Creates a new identity mat2d

# determinant(a)

Calculates the determinant of a mat2d

Parameters

Name Types Description
a ReadonlyMat2d the source matrix

# equals(a, b)

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

Parameters

Name Types Description
a ReadonlyMat2d The first matrix.
b ReadonlyMat2d The second matrix.

# exactEquals(a, b)

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

Parameters

Name Types Description
a ReadonlyMat2d The first matrix.
b ReadonlyMat2d The second matrix.

# frob(a)

Returns Frobenius norm of a mat2d

Parameters

Name Types Description
a ReadonlyMat2d the matrix to calculate Frobenius norm of

# fromRotation(out, a, v)

Scales the mat2d by the dimensions in the given vec2

Parameters

Name Types Description
out mat2d the receiving matrix
a ReadonlyMat2d the matrix to translate
v ReadonlyVec2 the vec2 to scale the matrix by

# fromScaling(out, v)

Creates a matrix from a vector scaling This is equivalent to (but much faster than): mat2d.identity(dest); mat2d.scale(dest, dest, vec);

Parameters

Name Types Description
out mat2d mat2d receiving operation result
v ReadonlyVec2 Scaling vector

# fromTranslation(out, v)

Creates a matrix from a vector translation This is equivalent to (but much faster than): mat2d.identity(dest); mat2d.translate(dest, dest, vec);

Parameters

Name Types Description
out mat2d mat2d receiving operation result
v ReadonlyVec2 Translation vector

# fromValues(a, b, c, d, tx, ty)

Create a new mat2d with the given values

Parameters

Name Types Description
a Number Component A (index 0)
b Number Component B (index 1)
c Number Component C (index 2)
d Number Component D (index 3)
tx Number Component TX (index 4)
ty Number Component TY (index 5)

# identity(out)

Set a mat2d to the identity matrix

Parameters

Name Types Description
out mat2d the receiving matrix

# invert(out, a)

Inverts a mat2d

Parameters

Name Types Description
out mat2d the receiving matrix
a ReadonlyMat2d the source matrix

# mul()

Alias for {@link mat2d.multiply}

# multiply(out, a, b)

Multiplies two mat2d's

Parameters

Name Types Description
out mat2d the receiving matrix
a ReadonlyMat2d the first operand
b ReadonlyMat2d the second operand

# multiplyScalar(out, a, b)

Multiply each element of the matrix by a scalar.

Parameters

Name Types Description
out mat2d the receiving matrix
a ReadonlyMat2d the matrix to scale
b Number amount to scale the matrix's elements by

# multiplyScalarAndAdd(out, a, b, scale)

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

Parameters

Name Types Description
out mat2d the receiving vector
a ReadonlyMat2d the first operand
b ReadonlyMat2d the second operand
scale Number the amount to scale b's elements by before adding

# rotate(out, a, rad)

Rotates a mat2d by the given angle

Parameters

Name Types Description
out mat2d the receiving matrix
a ReadonlyMat2d the matrix to rotate
rad Number the angle to rotate the matrix by

# set(out, a, b, c, d, tx, ty)

Set the components of a mat2d to the given values

Parameters

Name Types Description
out mat2d the receiving matrix
a Number Component A (index 0)
b Number Component B (index 1)
c Number Component C (index 2)
d Number Component D (index 3)
tx Number Component TX (index 4)
ty Number Component TY (index 5)

# str(a)

Returns a string representation of a mat2d

Parameters

Name Types Description
a ReadonlyMat2d matrix to represent as a string

# sub()

Alias for {@link mat2d.subtract}

# subtract(out, a, b)

Subtracts matrix b from matrix a

Parameters

Name Types Description
out mat2d the receiving matrix
a ReadonlyMat2d the first operand
b ReadonlyMat2d the second operand

# add(out, a, b)

Adds two mat3's

Parameters

Name Types Description
out mat3 the receiving matrix
a ReadonlyMat3 the first operand
b ReadonlyMat3 the second operand

# adjoint(out, a)

Calculates the adjugate of a mat3

Parameters

Name Types Description
out mat3 the receiving matrix
a ReadonlyMat3 the source matrix

# clone(a)

Creates a new mat3 initialized with values from an existing matrix

Parameters

Name Types Description
a ReadonlyMat3 matrix to clone

# copy(out, a)

Copy the values from one mat3 to another

Parameters

Name Types Description
out mat3 the receiving matrix
a ReadonlyMat3 the source matrix

# create()

Creates a new identity mat3

# determinant(a)

Calculates the determinant of a mat3

Parameters

Name Types Description
a ReadonlyMat3 the source matrix

# equals(a, b)

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

Parameters

Name Types Description
a ReadonlyMat3 The first matrix.
b ReadonlyMat3 The second matrix.

# exactEquals(a, b)

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

Parameters

Name Types Description
a ReadonlyMat3 The first matrix.
b ReadonlyMat3 The second matrix.

# frob(a)

Returns Frobenius norm of a mat3

Parameters

Name Types Description
a ReadonlyMat3 the matrix to calculate Frobenius norm of

# fromMat4(out, a)

Copies the upper-left 3x3 values into the given mat3.

Parameters

Name Types Description
out mat3 the receiving 3x3 matrix
a ReadonlyMat4 the source 4x4 matrix

# fromQuat(out, a)

Copies the values from a mat2d into a mat3

Parameters

Name Types Description
out mat3 the receiving matrix
a ReadonlyMat2d the matrix to copy

# fromRotation(out, rad)

Creates a matrix from a given angle This is equivalent to (but much faster than): mat3.identity(dest); mat3.rotate(dest, dest, rad);

Parameters

Name Types Description
out mat3 mat3 receiving operation result
rad Number the angle to rotate the matrix by

# fromScaling(out, v)

Creates a matrix from a vector scaling This is equivalent to (but much faster than): mat3.identity(dest); mat3.scale(dest, dest, vec);

Parameters

Name Types Description
out mat3 mat3 receiving operation result
v ReadonlyVec2 Scaling vector

# fromTranslation(out, a, v)

Scales the mat3 by the dimensions in the given vec2

Parameters

Name Types Description
out mat3 the receiving matrix
a ReadonlyMat3 the matrix to scale
v ReadonlyVec2 the vec2 to scale the matrix by

# fromValues(m00, m01, m02, m10, m11, m12, m20, m21, m22)

Create a new mat3 with the given values

Parameters

Name Types 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)
m10 Number Component in column 1, row 0 position (index 3)
m11 Number Component in column 1, row 1 position (index 4)
m12 Number Component in column 1, row 2 position (index 5)
m20 Number Component in column 2, row 0 position (index 6)
m21 Number Component in column 2, row 1 position (index 7)
m22 Number Component in column 2, row 2 position (index 8)

# identity(out)

Set a mat3 to the identity matrix

Parameters

Name Types Description
out mat3 the receiving matrix

# invert(out, a)

Inverts a mat3

Parameters

Name Types Description
out mat3 the receiving matrix
a ReadonlyMat3 the source matrix

# mul()

Alias for {@link mat3.multiply}

# multiply(out, a, b)

Multiplies two mat3's

Parameters

Name Types Description
out mat3 the receiving matrix
a ReadonlyMat3 the first operand
b ReadonlyMat3 the second operand

# multiplyScalar(out, a, b)

Multiply each element of the matrix by a scalar.

Parameters

Name Types Description
out mat3 the receiving matrix
a ReadonlyMat3 the matrix to scale
b Number amount to scale the matrix's elements by

# multiplyScalarAndAdd(out, a, b, scale)

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

Parameters

Name Types Description
out mat3 the receiving vector
a ReadonlyMat3 the first operand
b ReadonlyMat3 the second operand
scale Number the amount to scale b's elements by before adding

# normalFromMat4(out, a)

Calculates a 3x3 normal matrix (transpose inverse) from the 4x4 matrix

Parameters

Name Types Description
out mat3 mat3 receiving operation result
a ReadonlyMat4 Mat4 to derive the normal matrix from

# projection(out, width, height)

Generates a 2D projection matrix with the given bounds

Parameters

Name Types Description
out mat3 mat3 frustum matrix will be written into
width number Width of your gl context
height number Height of gl context

# rotate(out, a, rad)

Rotates a mat3 by the given angle

Parameters

Name Types Description
out mat3 the receiving matrix
a ReadonlyMat3 the matrix to rotate
rad Number the angle to rotate the matrix by

# set(out, m00, m01, m02, m10, m11, m12, m20, m21, m22)

Set the components of a mat3 to the given values

Parameters

Name Types Description
out mat3 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)
m10 Number Component in column 1, row 0 position (index 3)
m11 Number Component in column 1, row 1 position (index 4)
m12 Number Component in column 1, row 2 position (index 5)
m20 Number Component in column 2, row 0 position (index 6)
m21 Number Component in column 2, row 1 position (index 7)
m22 Number Component in column 2, row 2 position (index 8)

# str(a)

Returns a string representation of a mat3

Parameters

Name Types Description
a ReadonlyMat3 matrix to represent as a string

# sub()

Alias for {@link mat3.subtract}

# subtract(out, a, b)

Subtracts matrix b from matrix a

Parameters

Name Types Description
out mat3 the receiving matrix
a ReadonlyMat3 the first operand
b ReadonlyMat3 the second operand

# translate(out, a, v)

Translate a mat3 by the given vector

Parameters

Name Types Description
out mat3 the receiving matrix
a ReadonlyMat3 the matrix to translate
v ReadonlyVec2 vector to translate by

# transpose(out, a)

Transpose the values of a mat3

Parameters

Name Types Description
out mat3 the receiving matrix
a ReadonlyMat3 the source matrix

# add(out, a, b)

Adds two mat4's

Parameters

Name Types Description
out mat4 the receiving matrix
a ReadonlyMat4 the first operand
b ReadonlyMat4 the second operand

# adjoint(out, a)

Calculates the adjugate of a mat4

Parameters

Name Types Description
out mat4 the receiving matrix
a ReadonlyMat4 the source matrix

# clone(a)

Creates a new mat4 initialized with values from an existing matrix

Parameters

Name Types Description
a ReadonlyMat4 matrix to clone

# copy(out, a)

Copy the values from one mat4 to another

Parameters

Name Types Description
out mat4 the receiving matrix
a ReadonlyMat4 the source matrix

# create()

Creates a new identity mat4

# decompose(out_r, out_t, out_s, mat)

Decomposes a transformation matrix into its rotation, translation and scale components. Returns only the rotation component

Parameters

Name Types Description
out_r quat Quaternion to receive the rotation component
out_t vec3 Vector to receive the translation vector
out_s vec3 Vector to receive the scaling factor
mat ReadonlyMat4 Matrix to be decomposed (input)

# determinant(a)

Calculates the determinant of a mat4

Parameters

Name Types Description
a ReadonlyMat4 the source matrix

# equals(a, b)

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

Parameters

Name Types Description
a ReadonlyMat4 The first matrix.
b ReadonlyMat4 The second matrix.

# exactEquals(a, b)

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

Parameters

Name Types Description
a ReadonlyMat4 The first matrix.
b ReadonlyMat4 The second matrix.

# frob(a)

Returns Frobenius norm of a mat4

Parameters

Name Types Description
a ReadonlyMat4 the matrix to calculate Frobenius norm of

# fromQuat(out, q)

Calculates a 4x4 matrix from the given quaternion

Parameters

Name Types Description
out mat4 mat4 receiving operation result
q ReadonlyQuat Quaternion to create matrix from

# fromQuat2(out, a)

Creates a new mat4 from a dual quat.

Parameters

Name Types Description
out mat4 Matrix
a ReadonlyQuat2 Dual Quaternion

# fromRotation(out, rad, axis)

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 Types Description
out mat4 mat4 receiving operation result
rad Number the angle to rotate the matrix by
axis ReadonlyVec3 the axis to rotate around

# fromRotationTranslation(out, q, v)

Creates a matrix from a quaternion rotation and vector translation This is equivalent to (but much faster than): mat4.identity(dest); mat4.translate(dest, dest, vec); let quatMat = mat4.create(); mat4.fromQuat(quatMat, quat); mat4.multiply(dest, dest, quatMat);

Parameters

Name Types Description
out mat4 mat4 receiving operation result
q quat Rotation quaternion
v ReadonlyVec3 Translation vector

# fromRotationTranslationScale(out, q, v, s)

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, dest, vec); let quatMat = mat4.create(); mat4.fromQuat(quatMat, quat); mat4.multiply(dest, dest, quatMat); mat4.scale(dest, dest, scale)

Parameters

Name Types Description
out mat4 mat4 receiving operation result
q quat Rotation quaternion
v ReadonlyVec3 Translation vector
s ReadonlyVec3 Scaling vector

# fromRotationTranslationScaleOrigin(out, q, v, s, o)

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, dest, vec); mat4.translate(dest, dest, origin); let quatMat = mat4.create(); mat4.fromQuat(quatMat, quat); mat4.multiply(dest, dest, quatMat); mat4.scale(dest, dest, scale) mat4.translate(dest, dest, negativeOrigin);

Parameters

Name Types Description
out mat4 mat4 receiving operation result
q quat Rotation quaternion
v ReadonlyVec3 Translation vector
s ReadonlyVec3 Scaling vector
o ReadonlyVec3 The origin vector around which to scale and rotate

# fromScaling(out, v)

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 Types Description
out mat4 mat4 receiving operation result
v ReadonlyVec3 Scaling vector

# fromTranslation(out, v)

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 Types Description
out mat4 mat4 receiving operation result
v ReadonlyVec3 Translation vector

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

Create a new mat4 with the given values

Parameters

Name Types 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)

# fromXRotation(out, rad)

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 Types Description
out mat4 mat4 receiving operation result
rad Number the angle to rotate the matrix by

# fromYRotation(out, rad)

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 Types Description
out mat4 mat4 receiving operation result
rad Number the angle to rotate the matrix by

# fromZRotation(out, rad)

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 Types Description
out mat4 mat4 receiving operation result
rad Number the angle to rotate the matrix by

# frustum(out, left, right, bottom, top, near, far)

Generates a frustum matrix with the given bounds

Parameters

Name Types 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

# getRotation(out, mat)

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 Types Description
out quat Quaternion to receive the rotation component
mat ReadonlyMat4 Matrix to be decomposed (input)

Returns

quat

out

# getScaling(out, mat)

Returns the scaling factor component of a transformation matrix. If a matrix is built with fromRotationTranslationScale with a normalized Quaternion parameter, the returned vector will be the same as the scaling vector originally supplied.

Parameters

Name Types Description
out vec3 Vector to receive scaling factor component
mat ReadonlyMat4 Matrix to be decomposed (input)

Returns

vec3

out

# getTranslation(out, mat)

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 Types Description
out vec3 Vector to receive translation component
mat ReadonlyMat4 Matrix to be decomposed (input)

Returns

vec3

out

# identity(out)

Set a mat4 to the identity matrix

Parameters

Name Types Description
out mat4 the receiving matrix

# invert(out, a)

Inverts a mat4

Parameters

Name Types Description
out mat4 the receiving matrix
a ReadonlyMat4 the source matrix

# lookAt(out, eye, center, up)

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.

Parameters

Name Types Description
out mat4 mat4 frustum matrix will be written into
eye ReadonlyVec3 Position of the viewer
center ReadonlyVec3 Point the viewer is looking at
up ReadonlyVec3 vec3 pointing up

# mul()

Alias for {@link mat4.multiply}

# multiply(out, a, b)

Multiplies two mat4s

Parameters

Name Types Description
out mat4 the receiving matrix
a ReadonlyMat4 the first operand
b ReadonlyMat4 the second operand

# multiplyScalar(out, a, b)

Multiply each element of the matrix by a scalar.

Parameters

Name Types Description
out mat4 the receiving matrix
a ReadonlyMat4 the matrix to scale
b Number amount to scale the matrix's elements by

# multiplyScalarAndAdd(out, a, b, scale)

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

Parameters

Name Types Description
out mat4 the receiving vector
a ReadonlyMat4 the first operand
b ReadonlyMat4 the second operand
scale Number the amount to scale b's elements by before adding

# ortho()

Alias for {@link mat4.orthoNO}

# orthoNO(out, left, right, bottom, top, near, far)

Generates a orthogonal projection matrix with the given bounds. The near/far clip planes correspond to a normalized device coordinate Z range of [-1, 1], which matches WebGL/OpenGL's clip volume.

Parameters

Name Types 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

# orthoZO(out, left, right, bottom, top, near, far)

Generates a orthogonal projection matrix with the given bounds. The near/far clip planes correspond to a normalized device coordinate Z range of [0, 1], which matches WebGPU/Vulkan/DirectX/Metal's clip volume.

Parameters

Name Types 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

# perspective()

Alias for {@link mat4.perspectiveNO}

# perspectiveFromFieldOfView(out, fov, near, far)

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 Types 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

# perspectiveNO(out, fovy, aspect, near, far)

Generates a perspective projection matrix with the given bounds. The near/far clip planes correspond to a normalized device coordinate Z range of [-1, 1], which matches WebGL/OpenGL's clip volume. Passing null/undefined/no value for far will generate infinite projection matrix.

Parameters

Name Types 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

# perspectiveZO(out, fovy, aspect, near, far)

Generates a perspective projection matrix suitable for WebGPU with the given bounds. The near/far clip planes correspond to a normalized device coordinate Z range of [0, 1], which matches WebGPU/Vulkan/DirectX/Metal's clip volume. Passing null/undefined/no value for far will generate infinite projection matrix.

Parameters

Name Types 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

# rotate(out, a, v)

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

Parameters

Name Types Description
out mat4 the receiving matrix
a ReadonlyMat4 the matrix to scale
v ReadonlyVec3 the vec3 to scale the matrix by

# rotateX(out, a, rad)

Rotates a matrix by the given angle around the X axis

Parameters

Name Types Description
out mat4 the receiving matrix
a ReadonlyMat4 the matrix to rotate
rad Number the angle to rotate the matrix by

# rotateY(out, a, rad)

Rotates a matrix by the given angle around the Y axis

Parameters

Name Types Description
out mat4 the receiving matrix
a ReadonlyMat4 the matrix to rotate
rad Number the angle to rotate the matrix by

# rotateZ(out, a, rad)

Rotates a matrix by the given angle around the Z axis

Parameters

Name Types Description
out mat4 the receiving matrix
a ReadonlyMat4 the matrix to rotate
rad Number the angle to rotate the matrix by

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

Set the components of a mat4 to the given values

Parameters

Name Types 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)

# str(a)

Returns a string representation of a mat4

Parameters

Name Types Description
a ReadonlyMat4 matrix to represent as a string

# sub()

Alias for {@link mat4.subtract}

# subtract(out, a, b)

Subtracts matrix b from matrix a

Parameters

Name Types Description
out mat4 the receiving matrix
a ReadonlyMat4 the first operand
b ReadonlyMat4 the second operand

# targetTo(out, eye, target, up)

Generates a matrix that makes something look at something else.

Parameters

Name Types Description
out mat4 mat4 frustum matrix will be written into
eye ReadonlyVec3 Position of the viewer
target ReadonlyVec3 Point the viewer is looking at
up ReadonlyVec3 vec3 pointing up

# translate(out, a, v)

Translate a mat4 by the given vector

Parameters

Name Types Description
out mat4 the receiving matrix
a ReadonlyMat4 the matrix to translate
v ReadonlyVec3 vector to translate by

# transpose(out, a)

Transpose the values of a mat4

Parameters

Name Types Description
out mat4 the receiving matrix
a ReadonlyMat4 the source matrix

# add(out, a, b)

Adds two quat's

Parameters

Name Types Description
out quat the receiving quaternion
a ReadonlyQuat the first operand
b ReadonlyQuat the second operand

# calculateW(out, a)

Calculates the W component of a quat from the X, Y, and Z components. Assumes that quaternion is 1 unit in length. Any existing W component will be ignored.

Parameters

Name Types Description
out quat the receiving quaternion
a ReadonlyQuat quat to calculate W component of

# clone(a)

Creates a new quat initialized with values from an existing quaternion

Parameters

Name Types Description
a ReadonlyQuat quaternion to clone

# conjugate(out, a)

Calculates the conjugate of a quat If the quaternion is normalized, this function is faster than quat.inverse and produces the same result.

Parameters

Name Types Description
out quat the receiving quaternion
a ReadonlyQuat quat to calculate conjugate of

# copy(out, a)

Copy the values from one quat to another

Parameters

Name Types Description
out quat the receiving quaternion
a ReadonlyQuat the source quaternion

# create()

Creates a new identity quat

# dot(a, b)

Calculates the dot product of two quat's

Parameters

Name Types Description
a ReadonlyQuat the first operand
b ReadonlyQuat the second operand

# equals(a, b)

Returns whether or not the quaternions point approximately to the same direction. Both quaternions are assumed to be unit length.

Parameters

Name Types Description
a ReadonlyQuat The first unit quaternion.
b ReadonlyQuat The second unit quaternion.

# exactEquals(a, b)

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

Parameters

Name Types Description
a ReadonlyQuat The first quaternion.
b ReadonlyQuat The second quaternion.

# exp(out, a)

Calculate the exponential of a unit quaternion.

Parameters

Name Types Description
out quat the receiving quaternion
a ReadonlyQuat quat to calculate the exponential of

# fromEuler(out, x, y, z, order)

Creates a quaternion from the given euler angle x, y, z using the provided intrinsic order for the conversion.

Parameters

Name Types Description
out quat the receiving quaternion
x Number Angle to rotate around X axis in degrees.
y Number Angle to rotate around Y axis in degrees.
z Number Angle to rotate around Z axis in degrees.
order 'xyz' 'xzy'

# fromMat3(out, m)

Creates a quaternion from the given 3x3 rotation matrix. NOTE: The resultant quaternion is not normalized, so you should be sure to renormalize the quaternion yourself where necessary.

Parameters

Name Types Description
out quat the receiving quaternion
m ReadonlyMat3 rotation matrix

# fromValues(x, y, z, w)

Creates a new quat initialized with the given values

Parameters

Name Types Description
x Number X component
y Number Y component
z Number Z component
w Number W component

# getAngle(a, b)

Gets the angular distance between two unit quaternions

Parameters

Name Types Description
a ReadonlyQuat Origin unit quaternion
b ReadonlyQuat Destination unit quaternion

Returns

Number

Angle, in radians, between the two quaternions

# getAxisAngle(out, axis, rad)

Sets a quat from the given angle and rotation axis, then returns it.

Parameters

Name Types Description
out quat the receiving quaternion
axis ReadonlyVec3 the axis around which to rotate
rad Number the angle in radians

# identity(out)

Set a quat to the identity quaternion

Parameters

Name Types Description
out quat the receiving quaternion

# invert(out, a)

Calculates the inverse of a quat

Parameters

Name Types Description
out quat the receiving quaternion
a ReadonlyQuat quat to calculate inverse of

# len()

Alias for {@link quat.length}

# length(a)

Calculates the length of a quat

Parameters

Name Types Description
a ReadonlyQuat vector to calculate length of

# lerp(out, a, b, t)

Performs a linear interpolation between two quat's

Parameters

Name Types Description
out quat the receiving quaternion
a ReadonlyQuat the first operand
b ReadonlyQuat the second operand
t Number interpolation amount, in the range [0-1], between the two inputs

# ln(out, a)

Calculate the natural logarithm of a unit quaternion.

Parameters

Name Types Description
out quat the receiving quaternion
a ReadonlyQuat quat to calculate the exponential of

# mul()

Alias for {@link quat.multiply}

# multiply(out, a, b)

Multiplies two quat's

Parameters

Name Types Description
out quat the receiving quaternion
a ReadonlyQuat the first operand
b ReadonlyQuat the second operand

# normalize(out, a)

Normalize a quat

Parameters

Name Types Description
out quat the receiving quaternion
a ReadonlyQuat quaternion to normalize

# pow(out, a, b)

Calculate the scalar power of a unit quaternion.

Parameters

Name Types Description
out quat the receiving quaternion
a ReadonlyQuat quat to calculate the exponential of
b Number amount to scale the quaternion by

# random(out)

Generates a random unit quaternion

Parameters

Name Types Description
out quat the receiving quaternion

# rotateX(out, a, rad)

Rotates a quaternion by the given angle about the X axis

Parameters

Name Types Description
out quat quat receiving operation result
a ReadonlyQuat quat to rotate
rad number angle (in radians) to rotate

# rotateY(out, a, rad)

Rotates a quaternion by the given angle about the Y axis

Parameters

Name Types Description
out quat quat receiving operation result
a ReadonlyQuat quat to rotate
rad number angle (in radians) to rotate

# rotateZ(out, a, rad)

Rotates a quaternion by the given angle about the Z axis

Parameters

Name Types Description
out quat quat receiving operation result
a ReadonlyQuat quat to rotate
rad number angle (in radians) to rotate

# rotationTo(out, a, b)

Sets a quaternion to represent the shortest rotation from one vector to another. Both vectors are assumed to be unit length.

Parameters

Name Types Description
out quat the receiving quaternion.
a ReadonlyVec3 the initial vector
b ReadonlyVec3 the destination vector

# scale(out, a, b)

Scales a quat by a scalar number

Parameters

Name Types Description
out quat the receiving vector
a ReadonlyQuat the vector to scale
b Number amount to scale the vector by

# set(out, x, y, z, w)

Set the components of a quat to the given values

Parameters

Name Types Description
out quat the receiving quaternion
x Number X component
y Number Y component
z Number Z component
w Number W component

# setAxes(view, right, up)

Sets the specified quaternion with values corresponding to the given axes. Each axis is a vec3 and is expected to be unit length and perpendicular to all other specified axes.

Parameters

Name Types Description
view ReadonlyVec3 the vector representing the viewing direction
right ReadonlyVec3 the vector representing the local "right" direction
up ReadonlyVec3 the vector representing the local "up" direction

# slerp(out, a, b, t)

Performs a spherical linear interpolation between two quat

Parameters

Name Types Description
out quat the receiving quaternion
a ReadonlyQuat the first operand
b ReadonlyQuat the second operand
t Number interpolation amount, in the range [0-1], between the two inputs

# sqlerp(out, a, b, c, d, t)

Performs a spherical linear interpolation with two control points

Parameters

Name Types Description
out quat the receiving quaternion
a ReadonlyQuat the first operand
b ReadonlyQuat the second operand
c ReadonlyQuat the third operand
d ReadonlyQuat the fourth operand
t Number interpolation amount, in the range [0-1], between the two inputs

# sqrLen()

Alias for {@link quat.squaredLength}

# squaredLength(a)

Calculates the squared length of a quat

Parameters

Name Types Description
a ReadonlyQuat vector to calculate squared length of

# str(a)

Returns a string representation of a quaternion

Parameters

Name Types Description
a ReadonlyQuat vector to represent as a string

# add(out, a, b)

Adds two dual quat's

Parameters

Name Types Description
out quat2 the receiving dual quaternion
a ReadonlyQuat2 the first operand
b ReadonlyQuat2 the second operand

# clone(a)

Creates a new quat initialized with values from an existing quaternion

Parameters

Name Types Description
a ReadonlyQuat2 dual quaternion to clone

# conjugate(out, a)

Calculates the conjugate of a dual quat If the dual quaternion is normalized, this function is faster than quat2.inverse and produces the same result.

Parameters

Name Types Description
out quat2 the receiving quaternion
a ReadonlyQuat2 quat to calculate conjugate of

# copy(out, a)

Copy the values from one dual quat to another

Parameters

Name Types Description
out quat2 the receiving dual quaternion
a ReadonlyQuat2 the source dual quaternion

# create()

Creates a new identity dual quat

# dot(a, b)

Calculates the dot product of two dual quat's (The dot product of the real parts)

Parameters

Name Types Description
a ReadonlyQuat2 the first operand
b ReadonlyQuat2 the second operand

# equals(a, b)

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

Parameters

Name Types Description
a ReadonlyQuat2 the first dual quat.
b ReadonlyQuat2 the second dual quat.

# exactEquals(a, b)

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

Parameters

Name Types Description
a ReadonlyQuat2 the first dual quaternion.
b ReadonlyQuat2 the second dual quaternion.

# fromMat4(out, a)

Creates a new dual quat from a matrix (4x4)

Parameters

Name Types Description
out quat2 the dual quaternion
a ReadonlyMat4 the matrix

# fromRotation(dual, q)

Creates a dual quat from a quaternion

Parameters

Name Types Description
dual ReadonlyQuat2 quaternion receiving operation result
q ReadonlyQuat the quaternion

# fromRotationTranslation(dual, q, t)

Creates a dual quat from a quaternion and a translation

Parameters

Name Types Description
dual ReadonlyQuat2 quaternion receiving operation result
q ReadonlyQuat a normalized quaternion
t ReadonlyVec3 translation vector

# fromRotationTranslationValues(x1, y1, z1, w1, x2, y2, z2)

Creates a new dual quat from the given values (quat and translation)

Parameters

Name Types Description
x1 Number X component
y1 Number Y component
z1 Number Z component
w1 Number W component
x2 Number X component (translation)
y2 Number Y component (translation)
z2 Number Z component (translation)

# fromTranslation(dual, t)

Creates a dual quat from a translation

Parameters

Name Types Description
dual ReadonlyQuat2 quaternion receiving operation result
t ReadonlyVec3 translation vector

# fromValues(x1, y1, z1, w1, x2, y2, z2, w2)

Creates a new dual quat initialized with the given values

Parameters

Name Types Description
x1 Number X component
y1 Number Y component
z1 Number Z component
w1 Number W component
x2 Number X component
y2 Number Y component
z2 Number Z component
w2 Number W component

# getDual(out, a)

Gets the dual part of a dual quat

Parameters

Name Types Description
out quat dual part
a ReadonlyQuat2 Dual Quaternion

Returns

quat

dual part

# getReal(out, a)

Gets the real part of a dual quat

Parameters

Name Types Description
out quat real part
a ReadonlyQuat2 Dual Quaternion

Returns

quat

real part

# getTranslation(out, a)

Gets the translation of a normalized dual quat

Parameters

Name Types Description
out vec3 translation
a ReadonlyQuat2 Dual Quaternion to be decomposed

Returns

vec3

translation

# identity(out)

Set a dual quat to the identity dual quaternion

Parameters

Name Types Description
out quat2 the receiving quaternion

# invert(out, a)

Calculates the inverse of a dual quat. If they are normalized, conjugate is cheaper

Parameters

Name Types Description
out quat2 the receiving dual quaternion
a ReadonlyQuat2 dual quat to calculate inverse of

# len()

Alias for {@link quat2.length}

# length(a)

Calculates the length of a dual quat

Parameters

Name Types Description
a ReadonlyQuat2 dual quat to calculate length of

# lerp(out, a, b, t)

Performs a linear interpolation between two dual quats's NOTE: The resulting dual quaternions won't always be normalized (The error is most noticeable when t = 0.5)

Parameters

Name Types Description
out quat2 the receiving dual quat
a ReadonlyQuat2 the first operand
b ReadonlyQuat2 the second operand
t Number interpolation amount, in the range [0-1], between the two inputs

# mul()

Alias for {@link quat2.multiply}

# multiply(out, a, b)

Multiplies two dual quat's

Parameters

Name Types Description
out quat2 the receiving dual quaternion
a ReadonlyQuat2 the first operand
b ReadonlyQuat2 the second operand

# normalize(out, a)

Normalize a dual quat

Parameters

Name Types Description
out quat2 the receiving dual quaternion
a ReadonlyQuat2 dual quaternion to normalize

# rotateAroundAxis(out, a, axis, rad)

Rotates a dual quat around a given axis. Does the normalisation automatically

Parameters

Name Types Description
out quat2 the receiving dual quaternion
a ReadonlyQuat2 the dual quaternion to rotate
axis ReadonlyVec3 the axis to rotate around
rad Number how far the rotation should be

# rotateByQuatAppend(out, a, q)

Rotates a dual quat by a given quaternion (a * q)

Parameters

Name Types Description
out quat2 the receiving dual quaternion
a ReadonlyQuat2 the dual quaternion to rotate
q ReadonlyQuat quaternion to rotate by

# rotateByQuatPrepend(out, q, a)

Rotates a dual quat by a given quaternion (q * a)

Parameters

Name Types Description
out quat2 the receiving dual quaternion
q ReadonlyQuat quaternion to rotate by
a ReadonlyQuat2 the dual quaternion to rotate

# rotateX(out, a, rad)

Rotates a dual quat around the X axis

Parameters

Name Types Description
out quat2 the receiving dual quaternion
a ReadonlyQuat2 the dual quaternion to rotate
rad number how far should the rotation be

# rotateY(out, a, rad)

Rotates a dual quat around the Y axis

Parameters

Name Types Description
out quat2 the receiving dual quaternion
a ReadonlyQuat2 the dual quaternion to rotate
rad number how far should the rotation be

# rotateZ(out, a, rad)

Rotates a dual quat around the Z axis

Parameters

Name Types Description
out quat2 the receiving dual quaternion
a ReadonlyQuat2 the dual quaternion to rotate
rad number how far should the rotation be

# scale(out, a, b)

Scales a dual quat by a scalar number

Parameters

Name Types Description
out quat2 the receiving dual quat
a ReadonlyQuat2 the dual quat to scale
b Number amount to scale the dual quat by

# set(out, x1, y1, z1, w1, x2, y2, z2, w2)

Set the components of a dual quat to the given values

Parameters

Name Types Description
out quat2 the receiving quaternion
x1 Number X component
y1 Number Y component
z1 Number Z component
w1 Number W component
x2 Number X component
y2 Number Y component
z2 Number Z component
w2 Number W component

# setDual(out, q)

Set the dual component of a dual quat to the given quaternion

Parameters

Name Types Description
out quat2 the receiving quaternion
q ReadonlyQuat a quaternion representing the dual part

# setReal(out, q)

Set the real component of a dual quat to the given quaternion

Parameters

Name Types Description
out quat2 the receiving quaternion
q ReadonlyQuat a quaternion representing the real part

# sqrLen()

Alias for {@link quat2.squaredLength}

# squaredLength(a)

Calculates the squared length of a dual quat

Parameters

Name Types Description
a ReadonlyQuat2 dual quat to calculate squared length of

# str(a)

Returns a string representation of a dual quaternion

Parameters

Name Types Description
a ReadonlyQuat2 dual quaternion to represent as a string

# translate(out, a, v)

Translates a dual quat by the given vector

Parameters

Name Types Description
out quat2 the receiving dual quaternion
a ReadonlyQuat2 the dual quaternion to translate
v ReadonlyVec3 vector to translate by

# add(out, a, b)

Adds two vec2's

Parameters

Name Types Description
out vec2 the receiving vector
a ReadonlyVec2 the first operand
b ReadonlyVec2 the second operand

# angle(a, b)

Get the angle between two 2D vectors

Parameters

Name Types Description
a ReadonlyVec2 The first operand
b ReadonlyVec2 The second operand

# ceil(out, a)

Math.ceil the components of a vec2

Parameters

Name Types Description
out vec2 the receiving vector
a ReadonlyVec2 vector to ceil

# clone(a)

Creates a new vec2 initialized with values from an existing vector

Parameters

Name Types Description
a ReadonlyVec2 vector to clone

# copy(out, a)

Copy the values from one vec2 to another

Parameters

Name Types Description
out vec2 the receiving vector
a ReadonlyVec2 the source vector

# create()

Creates a new, empty vec2

# cross(out, a, b)

Computes the cross product of two vec2's Note that the cross product must by definition produce a 3D vector

Parameters

Name Types Description
out vec3 the receiving vector
a ReadonlyVec2 the first operand
b ReadonlyVec2 the second operand

# dist()

Alias for {@link vec2.distance}

# distance(a, b)

Calculates the euclidian distance between two vec2's

Parameters

Name Types Description
a ReadonlyVec2 the first operand
b ReadonlyVec2 the second operand

# div()

Alias for {@link vec2.divide}

# divide(out, a, b)

Divides two vec2's

Parameters

Name Types Description
out vec2 the receiving vector
a ReadonlyVec2 the first operand
b ReadonlyVec2 the second operand

# dot(a, b)

Calculates the dot product of two vec2's

Parameters

Name Types Description
a ReadonlyVec2 the first operand
b ReadonlyVec2 the second operand

# equals(a, b)

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

Parameters

Name Types Description
a ReadonlyVec2 The first vector.
b ReadonlyVec2 The second vector.

# exactEquals(a, b)

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

Parameters

Name Types Description
a ReadonlyVec2 The first vector.
b ReadonlyVec2 The second vector.

# floor(out, a)

Math.floor the components of a vec2

Parameters

Name Types Description
out vec2 the receiving vector
a ReadonlyVec2 vector to floor

# forEach(a, stride, offset, count, fn, arg)

Perform some operation over an array of vec2s.

Parameters

Name Types Description
a Array the array of vectors to iterate over
stride Number Number of elements between the start of each vec2. If 0 assumes tightly packed
offset Number Number of elements to skip at the beginning of the array
count Number Number of vec2s to iterate over. If 0 iterates over entire array
fn Function Function to call for each vector in the array
arg Object additional argument to pass to fn

# fromValues(x, y)

Creates a new vec2 initialized with the given values

Parameters

Name Types Description
x Number X component
y Number Y component

# inverse(out, a)

Returns the inverse of the components of a vec2

Parameters

Name Types Description
out vec2 the receiving vector
a ReadonlyVec2 vector to invert

# len()

Alias for {@link vec2.length}

# length(a)

Calculates the length of a vec2

Parameters

Name Types Description
a ReadonlyVec2 vector to calculate length of

# lerp(out, a, b, t)

Performs a linear interpolation between two vec2's

Parameters

Name Types Description
out vec2 the receiving vector
a ReadonlyVec2 the first operand
b ReadonlyVec2 the second operand
t Number interpolation amount, in the range [0-1], between the two inputs

# max(out, a, b)

Returns the maximum of two vec2's

Parameters

Name Types Description
out vec2 the receiving vector
a ReadonlyVec2 the first operand
b ReadonlyVec2 the second operand

# min(out, a, b)

Returns the minimum of two vec2's

Parameters

Name Types Description
out vec2 the receiving vector
a ReadonlyVec2 the first operand
b ReadonlyVec2 the second operand

# mul()

Alias for {@link vec2.multiply}

# multiply(out, a, b)

Multiplies two vec2's

Parameters

Name Types Description
out vec2 the receiving vector
a ReadonlyVec2 the first operand
b ReadonlyVec2 the second operand

# negate(out, a)

Negates the components of a vec2

Parameters

Name Types Description
out vec2 the receiving vector
a ReadonlyVec2 vector to negate

# normalize(out, a)

Normalize a vec2

Parameters

Name Types Description
out vec2 the receiving vector
a ReadonlyVec2 vector to normalize

# random(out, scale)

Generates a random vector with the given scale

Parameters

Name Types Description
out vec2 the receiving vector
scale Number Length of the resulting vector. If omitted, a unit vector will be returned

# rotate(out, a, b, rad)

Rotate a 2D vector

Parameters

Name Types Description
out vec2 The receiving vec2
a ReadonlyVec2 The vec2 point to rotate
b ReadonlyVec2 The origin of the rotation
rad Number The angle of rotation in radians

# round(out, a)

symmetric round the components of a vec2

Parameters

Name Types Description
out vec2 the receiving vector
a ReadonlyVec2 vector to round

# scale(out, a, b)

Scales a vec2 by a scalar number

Parameters

Name Types Description
out vec2 the receiving vector
a ReadonlyVec2 the vector to scale
b Number amount to scale the vector by

# scaleAndAdd(out, a, b, scale)

Adds two vec2's after scaling the second operand by a scalar value

Parameters

Name Types Description
out vec2 the receiving vector
a ReadonlyVec2 the first operand
b ReadonlyVec2 the second operand
scale Number the amount to scale b by before adding

# set(out, x, y)

Set the components of a vec2 to the given values

Parameters

Name Types Description
out vec2 the receiving vector
x Number X component
y Number Y component

# sqrDist()

Alias for {@link vec2.squaredDistance}

# sqrLen()

Alias for {@link vec2.squaredLength}

# squaredDistance(a, b)

Calculates the squared euclidian distance between two vec2's

Parameters

Name Types Description
a ReadonlyVec2 the first operand
b ReadonlyVec2 the second operand

# squaredLength(a)

Calculates the squared length of a vec2

Parameters

Name Types Description
a ReadonlyVec2 vector to calculate squared length of

# str(a)

Returns a string representation of a vector

Parameters

Name Types Description
a ReadonlyVec2 vector to represent as a string

# sub()

Alias for {@link vec2.subtract}

# subtract(out, a, b)

Subtracts vector b from vector a

Parameters

Name Types Description
out vec2 the receiving vector
a ReadonlyVec2 the first operand
b ReadonlyVec2 the second operand

# transformMat2(out, a, m)

Transforms the vec2 with a mat2

Parameters

Name Types Description
out vec2 the receiving vector
a ReadonlyVec2 the vector to transform
m ReadonlyMat2 matrix to transform with

# transformMat2d(out, a, m)

Transforms the vec2 with a mat2d

Parameters

Name Types Description
out vec2 the receiving vector
a ReadonlyVec2 the vector to transform
m ReadonlyMat2d matrix to transform with

# transformMat3(out, a, m)

Transforms the vec2 with a mat3 3rd vector component is implicitly '1'

Parameters

Name Types Description
out vec2 the receiving vector
a ReadonlyVec2 the vector to transform
m ReadonlyMat3 matrix to transform with

# transformMat4(out, a, m)

Transforms the vec2 with a mat4 3rd vector component is implicitly '0' 4th vector component is implicitly '1'

Parameters

Name Types Description
out vec2 the receiving vector
a ReadonlyVec2 the vector to transform
m ReadonlyMat4 matrix to transform with

# zero(out)

Set the components of a vec2 to zero

Parameters

Name Types Description
out vec2 the receiving vector

# add(out, a, b)

Adds two vec3's

Parameters

Name Types Description
out vec3 the receiving vector
a ReadonlyVec3 the first operand
b ReadonlyVec3 the second operand

# angle(a, b)

Get the angle between two 3D vectors

Parameters

Name Types Description
a ReadonlyVec3 The first operand
b ReadonlyVec3 The second operand

# bezier(out, a, b, c, d, t)

Performs a bezier interpolation with two control points

Parameters

Name Types Description
out vec3 the receiving vector
a ReadonlyVec3 the first operand
b ReadonlyVec3 the second operand
c ReadonlyVec3 the third operand
d ReadonlyVec3 the fourth operand
t Number interpolation amount, in the range [0-1], between the two inputs

# ceil(out, a)

Math.ceil the components of a vec3

Parameters

Name Types Description
out vec3 the receiving vector
a ReadonlyVec3 vector to ceil

# clone(a)

Creates a new vec3 initialized with values from an existing vector

Parameters

Name Types Description
a ReadonlyVec3 vector to clone

# copy(out, a)

Copy the values from one vec3 to another

Parameters

Name Types Description
out vec3 the receiving vector
a ReadonlyVec3 the source vector

# create()

Creates a new, empty vec3

# cross(out, a, b)

Computes the cross product of two vec3's

Parameters

Name Types Description
out vec3 the receiving vector
a ReadonlyVec3 the first operand
b ReadonlyVec3 the second operand

# dist()

Alias for {@link vec3.distance}

# distance(a, b)

Calculates the euclidian distance between two vec3's

Parameters

Name Types Description
a ReadonlyVec3 the first operand
b ReadonlyVec3 the second operand

# div()

Alias for {@link vec3.divide}

# divide(out, a, b)

Divides two vec3's

Parameters

Name Types Description
out vec3 the receiving vector
a ReadonlyVec3 the first operand
b ReadonlyVec3 the second operand

# dot(a, b)

Calculates the dot product of two vec3's

Parameters

Name Types Description
a ReadonlyVec3 the first operand
b ReadonlyVec3 the second operand

# equals(a, b)

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

Parameters

Name Types Description
a ReadonlyVec3 The first vector.
b ReadonlyVec3 The second vector.

# exactEquals(a, b)

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

Parameters

Name Types Description
a ReadonlyVec3 The first vector.
b ReadonlyVec3 The second vector.

# floor(out, a)

Math.floor the components of a vec3

Parameters

Name Types Description
out vec3 the receiving vector
a ReadonlyVec3 vector to floor

# forEach(a, stride, offset, count, fn, arg)

Perform some operation over an array of vec3s.

Parameters

Name Types Description
a Array the array of vectors to iterate over
stride Number Number of elements between the start of each vec3. If 0 assumes tightly packed
offset Number Number of elements to skip at the beginning of the array
count Number Number of vec3s to iterate over. If 0 iterates over entire array
fn Function Function to call for each vector in the array
arg Object additional argument to pass to fn

# fromValues(x, y, z)

Creates a new vec3 initialized with the given values

Parameters

Name Types Description
x Number X component
y Number Y component
z Number Z component

# hermite(out, a, b, c, d, t)

Performs a hermite interpolation with two control points

Parameters

Name Types Description
out vec3 the receiving vector
a ReadonlyVec3 the first operand
b ReadonlyVec3 the second operand
c ReadonlyVec3 the third operand
d ReadonlyVec3 the fourth operand
t Number interpolation amount, in the range [0-1], between the two inputs

# inverse(out, a)

Returns the inverse of the components of a vec3

Parameters

Name Types Description
out vec3 the receiving vector
a ReadonlyVec3 vector to invert

# len()

Alias for {@link vec3.length}

# length(a)

Calculates the length of a vec3

Parameters

Name Types Description
a ReadonlyVec3 vector to calculate length of

# lerp(out, a, b, t)

Performs a linear interpolation between two vec3's

Parameters

Name Types Description
out vec3 the receiving vector
a ReadonlyVec3 the first operand
b ReadonlyVec3 the second operand
t Number interpolation amount, in the range [0-1], between the two inputs

# max(out, a, b)

Returns the maximum of two vec3's

Parameters

Name Types Description
out vec3 the receiving vector
a ReadonlyVec3 the first operand
b ReadonlyVec3 the second operand

# min(out, a, b)

Returns the minimum of two vec3's

Parameters

Name Types Description
out vec3 the receiving vector
a ReadonlyVec3 the first operand
b ReadonlyVec3 the second operand

# mul()

Alias for {@link vec3.multiply}

# multiply(out, a, b)

Multiplies two vec3's

Parameters

Name Types Description
out vec3 the receiving vector
a ReadonlyVec3 the first operand
b ReadonlyVec3 the second operand

# negate(out, a)

Negates the components of a vec3

Parameters

Name Types Description
out vec3 the receiving vector
a ReadonlyVec3 vector to negate

# normalize(out, a)

Normalize a vec3

Parameters

Name Types Description
out vec3 the receiving vector
a ReadonlyVec3 vector to normalize

# random(out, scale)

Generates a random vector with the given scale

Parameters

Name Types Description
out vec3 the receiving vector
scale Number Length of the resulting vector. If omitted, a unit vector will be returned

# rotateX(out, a, b, rad)

Rotate a 3D vector around the x-axis

Parameters

Name Types Description
out vec3 The receiving vec3
a ReadonlyVec3 The vec3 point to rotate
b ReadonlyVec3 The origin of the rotation
rad Number The angle of rotation in radians

# rotateY(out, a, b, rad)

Rotate a 3D vector around the y-axis

Parameters

Name Types Description
out vec3 The receiving vec3
a ReadonlyVec3 The vec3 point to rotate
b ReadonlyVec3 The origin of the rotation
rad Number The angle of rotation in radians

# rotateZ(out, a, b, rad)

Rotate a 3D vector around the z-axis

Parameters

Name Types Description
out vec3 The receiving vec3
a ReadonlyVec3 The vec3 point to rotate
b ReadonlyVec3 The origin of the rotation
rad Number The angle of rotation in radians

# round(out, a)

symmetric round the components of a vec3

Parameters

Name Types Description
out vec3 the receiving vector
a ReadonlyVec3 vector to round

# scale(out, a, b)

Scales a vec3 by a scalar number

Parameters

Name Types Description
out vec3 the receiving vector
a ReadonlyVec3 the vector to scale
b Number amount to scale the vector by

# scaleAndAdd(out, a, b, scale)

Adds two vec3's after scaling the second operand by a scalar value

Parameters

Name Types Description
out vec3 the receiving vector
a ReadonlyVec3 the first operand
b ReadonlyVec3 the second operand
scale Number the amount to scale b by before adding

# set(out, x, y, z)

Set the components of a vec3 to the given values

Parameters

Name Types Description
out vec3 the receiving vector
x Number X component
y Number Y component
z Number Z component

# slerp(out, a, b, t)

Performs a spherical linear interpolation between two vec3's

Parameters

Name Types Description
out vec3 the receiving vector
a ReadonlyVec3 the first operand
b ReadonlyVec3 the second operand
t Number interpolation amount, in the range [0-1], between the two inputs

# sqrDist()

Alias for {@link vec3.squaredDistance}

# sqrLen()

Alias for {@link vec3.squaredLength}

# squaredDistance(a, b)

Calculates the squared euclidian distance between two vec3's

Parameters

Name Types Description
a ReadonlyVec3 the first operand
b ReadonlyVec3 the second operand

# squaredLength(a)

Calculates the squared length of a vec3

Parameters

Name Types Description
a ReadonlyVec3 vector to calculate squared length of

# str(a)

Returns a string representation of a vector

Parameters

Name Types Description
a ReadonlyVec3 vector to represent as a string

# sub()

Alias for {@link vec3.subtract}

# subtract(out, a, b)

Subtracts vector b from vector a

Parameters

Name Types Description
out vec3 the receiving vector
a ReadonlyVec3 the first operand
b ReadonlyVec3 the second operand

# transformMat3(out, a, m)

Transforms the vec3 with a mat3.

Parameters

Name Types Description
out vec3 the receiving vector
a ReadonlyVec3 the vector to transform
m ReadonlyMat3 the 3x3 matrix to transform with

# transformMat4(out, a, m)

Transforms the vec3 with a mat4. 4th vector component is implicitly '1'

Parameters

Name Types Description
out vec3 the receiving vector
a ReadonlyVec3 the vector to transform
m ReadonlyMat4 matrix to transform with

# transformQuat(out, a, q)

Transforms the vec3 with a quat Can also be used for dual quaternions. (Multiply it with the real part)

Parameters

Name Types Description
out vec3 the receiving vector
a ReadonlyVec3 the vector to transform
q ReadonlyQuat quaternion to transform with

# zero(out)

Set the components of a vec3 to zero

Parameters

Name Types Description
out vec3 the receiving vector

# add(out, a, b)

Adds two vec4's

Parameters

Name Types Description
out vec4 the receiving vector
a ReadonlyVec4 the first operand
b ReadonlyVec4 the second operand

# ceil(out, a)

Math.ceil the components of a vec4

Parameters

Name Types Description
out vec4 the receiving vector
a ReadonlyVec4 vector to ceil

# clone(a)

Creates a new vec4 initialized with values from an existing vector

Parameters

Name Types Description
a ReadonlyVec4 vector to clone

# copy(out, a)

Copy the values from one vec4 to another

Parameters

Name Types Description
out vec4 the receiving vector
a ReadonlyVec4 the source vector

# create()

Creates a new, empty vec4

# cross(out, u, v, w)

Returns the cross-product of three vectors in a 4-dimensional space

Parameters

Name Types Description
out ReadonlyVec4 the receiving vector
u ReadonlyVec4 the first vector
v ReadonlyVec4 the second vector
w ReadonlyVec4 the third vector

# dist()

Alias for {@link vec4.distance}

# distance(a, b)

Calculates the euclidian distance between two vec4's

Parameters

Name Types Description
a ReadonlyVec4 the first operand
b ReadonlyVec4 the second operand

# div()

Alias for {@link vec4.divide}

# divide(out, a, b)

Divides two vec4's

Parameters

Name Types Description
out vec4 the receiving vector
a ReadonlyVec4 the first operand
b ReadonlyVec4 the second operand

# dot(a, b)

Calculates the dot product of two vec4's

Parameters

Name Types Description
a ReadonlyVec4 the first operand
b ReadonlyVec4 the second operand

# equals(a, b)

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

Parameters

Name Types Description
a ReadonlyVec4 The first vector.
b ReadonlyVec4 The second vector.

# exactEquals(a, b)

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

Parameters

Name Types Description
a ReadonlyVec4 The first vector.
b ReadonlyVec4 The second vector.

# floor(out, a)

Math.floor the components of a vec4

Parameters

Name Types Description
out vec4 the receiving vector
a ReadonlyVec4 vector to floor

# forEach(a, stride, offset, count, fn, arg)

Perform some operation over an array of vec4s.

Parameters

Name Types Description
a Array the array of vectors to iterate over
stride Number Number of elements between the start of each vec4. If 0 assumes tightly packed
offset Number Number of elements to skip at the beginning of the array
count Number Number of vec4s to iterate over. If 0 iterates over entire array
fn Function Function to call for each vector in the array
arg Object additional argument to pass to fn

# fromValues(x, y, z, w)

Creates a new vec4 initialized with the given values

Parameters

Name Types Description
x Number X component
y Number Y component
z Number Z component
w Number W component

# inverse(out, a)

Returns the inverse of the components of a vec4

Parameters

Name Types Description
out vec4 the receiving vector
a ReadonlyVec4 vector to invert

# len()

Alias for {@link vec4.length}

# length(a)

Calculates the length of a vec4

Parameters

Name Types Description
a ReadonlyVec4 vector to calculate length of

# lerp(out, a, b, t)

Performs a linear interpolation between two vec4's

Parameters

Name Types Description
out vec4 the receiving vector
a ReadonlyVec4 the first operand
b ReadonlyVec4 the second operand
t Number interpolation amount, in the range [0-1], between the two inputs

# max(out, a, b)

Returns the maximum of two vec4's

Parameters

Name Types Description
out vec4 the receiving vector
a ReadonlyVec4 the first operand
b ReadonlyVec4 the second operand

# min(out, a, b)

Returns the minimum of two vec4's

Parameters

Name Types Description
out vec4 the receiving vector
a ReadonlyVec4 the first operand
b ReadonlyVec4 the second operand

# mul()

Alias for {@link vec4.multiply}

# multiply(out, a, b)

Multiplies two vec4's

Parameters

Name Types Description
out vec4 the receiving vector
a ReadonlyVec4 the first operand
b ReadonlyVec4 the second operand

# negate(out, a)

Negates the components of a vec4

Parameters

Name Types Description
out vec4 the receiving vector
a ReadonlyVec4 vector to negate

# normalize(out, a)

Normalize a vec4

Parameters

Name Types Description
out vec4 the receiving vector
a ReadonlyVec4 vector to normalize

# random(out, scale)

Generates a random vector with the given scale

Parameters

Name Types Description
out vec4 the receiving vector
scale Number Length of the resulting vector. If omitted, a unit vector will be returned

# round(out, a)

symmetric round the components of a vec4

Parameters

Name Types Description
out vec4 the receiving vector
a ReadonlyVec4 vector to round

# scale(out, a, b)

Scales a vec4 by a scalar number

Parameters

Name Types Description
out vec4 the receiving vector
a ReadonlyVec4 the vector to scale
b Number amount to scale the vector by

# scaleAndAdd(out, a, b, scale)

Adds two vec4's after scaling the second operand by a scalar value

Parameters

Name Types Description
out vec4 the receiving vector
a ReadonlyVec4 the first operand
b ReadonlyVec4 the second operand
scale Number the amount to scale b by before adding

# set(out, x, y, z, w)

Set the components of a vec4 to the given values

Parameters

Name Types Description
out vec4 the receiving vector
x Number X component
y Number Y component
z Number Z component
w Number W component

# sqrDist()

Alias for {@link vec4.squaredDistance}

# sqrLen()

Alias for {@link vec4.squaredLength}

# squaredDistance(a, b)

Calculates the squared euclidian distance between two vec4's

Parameters

Name Types Description
a ReadonlyVec4 the first operand
b ReadonlyVec4 the second operand

# squaredLength(a)

Calculates the squared length of a vec4

Parameters

Name Types Description
a ReadonlyVec4 vector to calculate squared length of

# str(a)

Returns a string representation of a vector

Parameters

Name Types Description
a ReadonlyVec4 vector to represent as a string

# sub()

Alias for {@link vec4.subtract}

# subtract(out, a, b)

Subtracts vector b from vector a

Parameters

Name Types Description
out vec4 the receiving vector
a ReadonlyVec4 the first operand
b ReadonlyVec4 the second operand

# transformMat4(out, a, m)

Transforms the vec4 with a mat4.

Parameters

Name Types Description
out vec4 the receiving vector
a ReadonlyVec4 the vector to transform
m ReadonlyMat4 matrix to transform with

# transformQuat(out, a, q)

Transforms the vec4 with a quat

Parameters

Name Types Description
out vec4 the receiving vector
a ReadonlyVec4 the vector to transform
q ReadonlyQuat quaternion to transform with

# zero(out)

Set the components of a vec4 to zero

Parameters

Name Types Description
out vec4 the receiving vector