Skip to content

Latest commit

 

History

History
4044 lines (2472 loc) · 114 KB

api.md

File metadata and controls

4044 lines (2472 loc) · 114 KB

Table of Contents

EPSILON

Type: number

Properties

equals

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

  • a Number The first number to test.
  • b Number The second number to test.

Returns Boolean True if the numbers are approximately equal, false otherwise.

approx

Tests whether or not the arguments have approximately the same value by given maxDiff

Parameters

  • a Number The first number to test.
  • b Number The second number to test.
  • maxDiff Number Maximum difference.

Returns Boolean True if the numbers are approximately equal, false otherwise.

clamp

Clamps a value between a minimum float and maximum float value.

Parameters

Returns number

clamp01

Clamps a value between 0 and 1.

Parameters

Returns number

lerp

Parameters

Returns number

toRadian

Convert Degree To Radian

Parameters

toDegree

Convert Radian To Degree

Parameters

random

randomRange

Returns a floating-point random number between min (inclusive) and max (exclusive).

Parameters

Returns number the random number

randomRangeInt

Returns a random integer between min (inclusive) and max (exclusive).

Parameters

Returns number the random integer

vec2

create

Creates a new, empty vec2

Returns vec2 a new 2D vector

new

Creates a new vec2 initialized with the given values

Parameters

Returns vec2 a new 2D vector

clone

Creates a new vec2 initialized with values from an existing vector

Parameters

  • a vec2 vector to clone

Returns vec2 a new 2D vector

copy

Copy the values from one vec2 to another

Parameters

  • out vec2 the receiving vector
  • a vec2 the source vector

Returns vec2 out

set

Set the components of a vec2 to the given values

Parameters

Returns vec2 out

add

Adds two vec2's

Parameters

  • out vec2 the receiving vector
  • a vec2 the first operand
  • b vec2 the second operand

Returns vec2 out

subtract

Subtracts vector b from vector a

Parameters

  • out vec2 the receiving vector
  • a vec2 the first operand
  • b vec2 the second operand

Returns vec2 out

sub

Alias for vec2.subtract

multiply

Multiplies two vec2's

Parameters

  • out vec2 the receiving vector
  • a vec2 the first operand
  • b vec2 the second operand

Returns vec2 out

mul

Alias for vec2.multiply

divide

Divides two vec2's

Parameters

  • out vec2 the receiving vector
  • a vec2 the first operand
  • b vec2 the second operand

Returns vec2 out

div

Alias for vec2.divide

ceil

Math.ceil the components of a vec2

Parameters

  • out vec2 the receiving vector
  • a vec2 vector to ceil

Returns vec2 out

floor

Math.floor the components of a vec2

Parameters

  • out vec2 the receiving vector
  • a vec2 vector to floor

Returns vec2 out

min

Returns the minimum of two vec2's

Parameters

  • out vec2 the receiving vector
  • a vec2 the first operand
  • b vec2 the second operand

Returns vec2 out

max

Returns the maximum of two vec2's

Parameters

  • out vec2 the receiving vector
  • a vec2 the first operand
  • b vec2 the second operand

Returns vec2 out

round

Math.round the components of a vec2

Parameters

  • out vec2 the receiving vector
  • a vec2 vector to round

Returns vec2 out

scale

Scales a vec2 by a scalar number

Parameters

  • out vec2 the receiving vector
  • a vec2 the vector to scale
  • b Number amount to scale the vector by

Returns vec2 out

scaleAndAdd

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

Parameters

  • out vec2 the receiving vector
  • a vec2 the first operand
  • b vec2 the second operand
  • scale Number the amount to scale b by before adding

Returns vec2 out

distance

Calculates the euclidian distance between two vec2's

Parameters

  • a vec2 the first operand
  • b vec2 the second operand

Returns Number distance between a and b

dist

Alias for vec2.distance

squaredDistance

Calculates the squared euclidian distance between two vec2's

Parameters

  • a vec2 the first operand
  • b vec2 the second operand

Returns Number squared distance between a and b

sqrDist

Alias for vec2.squaredDistance

length

Calculates the length of a vec2

Parameters

  • a vec2 vector to calculate length of

Returns Number length of a

len

Alias for vec2.length

squaredLength

Calculates the squared length of a vec2

Parameters

  • a vec2 vector to calculate squared length of

Returns Number squared length of a

sqrLen

Alias for vec2.squaredLength

negate

Negates the components of a vec2

Parameters

  • out vec2 the receiving vector
  • a vec2 vector to negate

Returns vec2 out

inverse

Returns the inverse of the components of a vec2

Parameters

  • out vec2 the receiving vector
  • a vec2 vector to invert

Returns vec2 out

inverseSafe

Returns the inverse of the components of a vec2 safely

Parameters

  • out vec2 the receiving vector
  • a vec2 vector to invert

Returns vec2 out

normalize

Normalize a vec2

Parameters

  • out vec2 the receiving vector
  • a vec2 vector to normalize

Returns vec2 out

dot

Calculates the dot product of two vec2's

Parameters

  • a vec2 the first operand
  • b vec2 the second operand

Returns Number dot product of a and b

cross

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

Parameters

  • out vec3 the receiving vector
  • a vec2 the first operand
  • b vec2 the second operand

Returns vec3 out

lerp

Performs a linear interpolation between two vec2's

Parameters

  • out vec2 the receiving vector
  • a vec2 the first operand
  • b vec2 the second operand
  • t Number interpolation amount between the two inputs

Returns vec2 out

random

Generates a random vector with the given scale

Parameters

  • out vec2 the receiving vector
  • scale Number? Length of the resulting vector. If ommitted, a unit vector will be returned

Returns vec2 out

transformMat2

Transforms the vec2 with a mat2

Parameters

  • out vec2 the receiving vector
  • a vec2 the vector to transform
  • m mat2 matrix to transform with

Returns vec2 out

transformMat23

Transforms the vec2 with a mat23

Parameters

  • out vec2 the receiving vector
  • a vec2 the vector to transform
  • m mat23 matrix to transform with

Returns vec2 out

transformMat3

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

Parameters

  • out vec2 the receiving vector
  • a vec2 the vector to transform
  • m mat3 matrix to transform with

Returns vec2 out

transformMat4

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

Parameters

  • out vec2 the receiving vector
  • a vec2 the vector to transform
  • m mat4 matrix to transform with

Returns vec2 out

forEach

Perform some operation over an array of vec2s.

Parameters

  • 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

Returns Array a

str

Returns a string representation of a vector

Parameters

  • a vec2 vector to represent as a string

Returns String string representation of the vector

array

Returns typed array

Parameters

Returns array

exactEquals

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

Parameters

  • a vec2 The first vector.
  • b vec2 The second vector.

Returns Boolean True if the vectors are equal, false otherwise.

equals

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

Parameters

  • a vec2 The first vector.
  • b vec2 The second vector.

Returns Boolean True if the vectors are equal, false otherwise.

vec3

create

Creates a new, empty vec3

Returns vec3 a new 3D vector

new

Creates a new vec3 initialized with the given values

Parameters

Returns vec3 a new 3D vector

clone

Creates a new vec3 initialized with values from an existing vector

Parameters

  • a vec3 vector to clone

Returns vec3 a new 3D vector

copy

Copy the values from one vec3 to another

Parameters

  • out vec3 the receiving vector
  • a vec3 the source vector

Returns vec3 out

set

Set the components of a vec3 to the given values

Parameters

Returns vec3 out

add

Adds two vec3's

Parameters

  • out vec3 the receiving vector
  • a vec3 the first operand
  • b vec3 the second operand

Returns vec3 out

subtract

Subtracts vector b from vector a

Parameters

  • out vec3 the receiving vector
  • a vec3 the first operand
  • b vec3 the second operand

Returns vec3 out

sub

Alias for vec3.subtract

multiply

Multiplies two vec3's

Parameters

  • out vec3 the receiving vector
  • a vec3 the first operand
  • b vec3 the second operand

Returns vec3 out

mul

Alias for vec3.multiply

divide

Divides two vec3's

Parameters

  • out vec3 the receiving vector
  • a vec3 the first operand
  • b vec3 the second operand

Returns vec3 out

div

Alias for vec3.divide

ceil

Math.ceil the components of a vec3

Parameters

  • out vec3 the receiving vector
  • a vec3 vector to ceil

Returns vec3 out

floor

Math.floor the components of a vec3

Parameters

  • out vec3 the receiving vector
  • a vec3 vector to floor

Returns vec3 out

min

Returns the minimum of two vec3's

Parameters

  • out vec3 the receiving vector
  • a vec3 the first operand
  • b vec3 the second operand

Returns vec3 out

max

Returns the maximum of two vec3's

Parameters

  • out vec3 the receiving vector
  • a vec3 the first operand
  • b vec3 the second operand

Returns vec3 out

round

Math.round the components of a vec3

Parameters

  • out vec3 the receiving vector
  • a vec3 vector to round

Returns vec3 out

scale

Scales a vec3 by a scalar number

Parameters

  • out vec3 the receiving vector
  • a vec3 the vector to scale
  • b Number amount to scale the vector by

Returns vec3 out

scaleAndAdd

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

Parameters

  • out vec3 the receiving vector
  • a vec3 the first operand
  • b vec3 the second operand
  • scale Number the amount to scale b by before adding

Returns vec3 out

distance

Calculates the euclidian distance between two vec3's

Parameters

  • a vec3 the first operand
  • b vec3 the second operand

Returns Number distance between a and b

dist

Alias for vec3.distance

squaredDistance

Calculates the squared euclidian distance between two vec3's

Parameters

  • a vec3 the first operand
  • b vec3 the second operand

Returns Number squared distance between a and b

sqrDist

Alias for vec3.squaredDistance

length

Calculates the length of a vec3

Parameters

  • a vec3 vector to calculate length of

Returns Number length of a

len

Alias for vec3.length

squaredLength

Calculates the squared length of a vec3

Parameters

  • a vec3 vector to calculate squared length of

Returns Number squared length of a

sqrLen

Alias for vec3.squaredLength

negate

Negates the components of a vec3

Parameters

  • out vec3 the receiving vector
  • a vec3 vector to negate

Returns vec3 out

inverse

Returns the inverse of the components of a vec3

Parameters

  • out vec3 the receiving vector
  • a vec3 vector to invert

Returns vec3 out

inverseSafe

Returns the inverse of the components of a vec3 safely

Parameters

  • out vec3 the receiving vector
  • a vec3 vector to invert

Returns vec3 out

normalize

Normalize a vec3

Parameters

  • out vec3 the receiving vector
  • a vec3 vector to normalize

Returns vec3 out

dot

Calculates the dot product of two vec3's

Parameters

  • a vec3 the first operand
  • b vec3 the second operand

Returns Number dot product of a and b

cross

Computes the cross product of two vec3's

Parameters

  • out vec3 the receiving vector
  • a vec3 the first operand
  • b vec3 the second operand

Returns vec3 out

lerp

Performs a linear interpolation between two vec3's

Parameters

  • out vec3 the receiving vector
  • a vec3 the first operand
  • b vec3 the second operand
  • t Number interpolation amount between the two inputs

Returns vec3 out

hermite

Performs a hermite interpolation with two control points

Parameters

  • out vec3 the receiving vector
  • a vec3 the first operand
  • b vec3 the second operand
  • c vec3 the third operand
  • d vec3 the fourth operand
  • t Number interpolation amount between the two inputs

Returns vec3 out

bezier

Performs a bezier interpolation with two control points

Parameters

  • out vec3 the receiving vector
  • a vec3 the first operand
  • b vec3 the second operand
  • c vec3 the third operand
  • d vec3 the fourth operand
  • t Number interpolation amount between the two inputs

Returns vec3 out

random

Generates a random vector with the given scale

Parameters

  • out vec3 the receiving vector
  • scale Number? Length of the resulting vector. If ommitted, a unit vector will be returned

Returns vec3 out

transformMat4

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

Parameters

  • out vec3 the receiving vector
  • a vec3 the vector to transform
  • m mat4 matrix to transform with

Returns vec3 out

transformMat3

Transforms the vec3 with a mat3.

Parameters

  • out vec3 the receiving vector
  • a vec3 the vector to transform
  • m mat4 the 3x3 matrix to transform with

Returns vec3 out

transformQuat

Transforms the vec3 with a quat

Parameters

  • out vec3 the receiving vector
  • a vec3 the vector to transform
  • q quat quaternion to transform with

Returns vec3 out

rotateX

Rotate a 3D vector around the x-axis

Parameters

  • out vec3 The receiving vec3
  • a vec3 The vec3 point to rotate
  • b vec3 The origin of the rotation
  • c Number The angle of rotation

Returns vec3 out

rotateY

Rotate a 3D vector around the y-axis

Parameters

  • out vec3 The receiving vec3
  • a vec3 The vec3 point to rotate
  • b vec3 The origin of the rotation
  • c Number The angle of rotation

Returns vec3 out

rotateZ

Rotate a 3D vector around the z-axis

Parameters

  • out vec3 The receiving vec3
  • a vec3 The vec3 point to rotate
  • b vec3 The origin of the rotation
  • c Number The angle of rotation

Returns vec3 out

forEach

Perform some operation over an array of vec3s.

Parameters

  • 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

Returns Array a

angle

Get the angle between two 3D vectors

Parameters

  • a vec3 The first operand
  • b vec3 The second operand

Returns Number The angle in radians

str

Returns a string representation of a vector

Parameters

  • a vec3 vector to represent as a string

Returns String string representation of the vector

array

Returns typed array

Parameters

Returns array

exactEquals

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

Parameters

  • a vec3 The first vector.
  • b vec3 The second vector.

Returns Boolean True if the vectors are equal, false otherwise.

equals

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

Parameters

  • a vec3 The first vector.
  • b vec3 The second vector.

Returns Boolean True if the vectors are equal, false otherwise.

vec4

create

Creates a new, empty vec4

Returns vec4 a new 4D vector

new

Creates a new vec4 initialized with the given values

Parameters

Returns vec4 a new 4D vector

clone

Creates a new vec4 initialized with values from an existing vector

Parameters

  • a vec4 vector to clone

Returns vec4 a new 4D vector

copy

Copy the values from one vec4 to another

Parameters

  • out vec4 the receiving vector
  • a vec4 the source vector

Returns vec4 out

set

Set the components of a vec4 to the given values

Parameters

Returns vec4 out

add

Adds two vec4's

Parameters

  • out vec4 the receiving vector
  • a vec4 the first operand
  • b vec4 the second operand

Returns vec4 out

subtract

Subtracts vector b from vector a

Parameters

  • out vec4 the receiving vector
  • a vec4 the first operand
  • b vec4 the second operand

Returns vec4 out

sub

Alias for vec4.subtract

multiply

Multiplies two vec4's

Parameters

  • out vec4 the receiving vector
  • a vec4 the first operand
  • b vec4 the second operand

Returns vec4 out

mul

Alias for vec4.multiply

divide

Divides two vec4's

Parameters

  • out vec4 the receiving vector
  • a vec4 the first operand
  • b vec4 the second operand

Returns vec4 out

div

Alias for vec4.divide

ceil

Math.ceil the components of a vec4

Parameters

  • out vec4 the receiving vector
  • a vec4 vector to ceil

Returns vec4 out

floor

Math.floor the components of a vec4

Parameters

  • out vec4 the receiving vector
  • a vec4 vector to floor

Returns vec4 out

min

Returns the minimum of two vec4's

Parameters

  • out vec4 the receiving vector
  • a vec4 the first operand
  • b vec4 the second operand

Returns vec4 out

max

Returns the maximum of two vec4's

Parameters

  • out vec4 the receiving vector
  • a vec4 the first operand
  • b vec4 the second operand

Returns vec4 out

round

Math.round the components of a vec4

Parameters

  • out vec4 the receiving vector
  • a vec4 vector to round

Returns vec4 out

scale

Scales a vec4 by a scalar number

Parameters

  • out vec4 the receiving vector
  • a vec4 the vector to scale
  • b Number amount to scale the vector by

Returns vec4 out

scaleAndAdd

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

Parameters

  • out vec4 the receiving vector
  • a vec4 the first operand
  • b vec4 the second operand
  • scale Number the amount to scale b by before adding

Returns vec4 out

distance

Calculates the euclidian distance between two vec4's

Parameters

  • a vec4 the first operand
  • b vec4 the second operand

Returns Number distance between a and b

dist

Alias for vec4.distance

squaredDistance

Calculates the squared euclidian distance between two vec4's

Parameters

  • a vec4 the first operand
  • b vec4 the second operand

Returns Number squared distance between a and b

sqrDist

Alias for vec4.squaredDistance

length

Calculates the length of a vec4

Parameters

  • a vec4 vector to calculate length of

Returns Number length of a

len

Alias for vec4.length

squaredLength

Calculates the squared length of a vec4

Parameters

  • a vec4 vector to calculate squared length of

Returns Number squared length of a

sqrLen

Alias for vec4.squaredLength

negate

Negates the components of a vec4

Parameters

  • out vec4 the receiving vector
  • a vec4 vector to negate

Returns vec4 out

inverse

Returns the inverse of the components of a vec4

Parameters

  • out vec4 the receiving vector
  • a vec4 vector to invert

Returns vec4 out

inverseSafe

Returns the inverse of the components of a vec4 safely

Parameters

  • out vec4 the receiving vector
  • a vec4 vector to invert

Returns vec4 out

normalize

Normalize a vec4

Parameters

  • out vec4 the receiving vector
  • a vec4 vector to normalize

Returns vec4 out

dot

Calculates the dot product of two vec4's

Parameters

  • a vec4 the first operand
  • b vec4 the second operand

Returns Number dot product of a and b

lerp

Performs a linear interpolation between two vec4's

Parameters

  • out vec4 the receiving vector
  • a vec4 the first operand
  • b vec4 the second operand
  • t Number interpolation amount between the two inputs

Returns vec4 out

random

Generates a random vector with the given scale

Parameters

  • out vec4 the receiving vector
  • scale Number? Length of the resulting vector. If ommitted, a unit vector will be returned

Returns vec4 out

transformMat4

Transforms the vec4 with a mat4.

Parameters

  • out vec4 the receiving vector
  • a vec4 the vector to transform
  • m mat4 matrix to transform with

Returns vec4 out

transformQuat

Transforms the vec4 with a quat

Parameters

  • out vec4 the receiving vector
  • a vec4 the vector to transform
  • q quat quaternion to transform with

Returns vec4 out

forEach

Perform some operation over an array of vec4s.

Parameters

  • 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

Returns Array a

str

Returns a string representation of a vector

Parameters

  • a vec4 vector to represent as a string

Returns String string representation of the vector

array

Returns typed array

Parameters

Returns array

exactEquals

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

Parameters

  • a vec4 The first vector.
  • b vec4 The second vector.

Returns Boolean True if the vectors are equal, false otherwise.

equals

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

Parameters

  • a vec4 The first vector.
  • b vec4 The second vector.

Returns Boolean True if the vectors are equal, false otherwise.

quat

create

Creates a new identity quat

Returns quat a new quaternion

new

Creates a new quat initialized with the given values

Parameters

Returns quat a new quaternion

clone

Creates a new quat initialized with values from an existing quaternion

Parameters

  • a quat quaternion to clone

Returns quat a new quaternion

copy

Copy the values from one quat to another

Parameters

  • out quat the receiving quaternion
  • a quat the source quaternion

Returns quat out

set

Set the components of a quat to the given values

Parameters

Returns quat out

identity

Set a quat to the identity quaternion

Parameters

  • out quat the receiving quaternion

Returns quat out

rotationTo

Sets a quaternion to represent the shortest rotation from one vector to another.

Both vectors are assumed to be unit length.

Parameters

  • out quat the receiving quaternion.
  • a vec3 the initial vector
  • b vec3 the destination vector

Returns quat out

getAxisAngle

Gets the rotation axis and angle for a given quaternion. If a quaternion is created with fromAxisAngle, this method will return the same values as providied in the original parameter list OR functionally equivalent values. Example: The quaternion formed by axis [0, 0, 1] and angle -90 is the same as the quaternion formed by [0, 0, 1] and 270. This method favors the latter.

Parameters

  • out_axis vec3 Vector receiving the axis of rotation
  • q quat Quaternion to be decomposed

Returns Number Angle, in radians, of the rotation

add

Adds two quat's

Parameters

  • out quat the receiving quaternion
  • a quat the first operand
  • b quat the second operand

Returns quat out

multiply

Multiplies two quat's

Parameters

  • out quat the receiving quaternion
  • a quat the first operand
  • b quat the second operand

Returns quat out

mul

Alias for quat.multiply

scale

Scales a quat by a scalar number

Parameters

  • out quat the receiving vector
  • a quat the vector to scale
  • b Number amount to scale the vector by

Returns quat out

rotateX

Rotates a quaternion by the given angle about the X axis

Parameters

  • out quat quat receiving operation result
  • a quat quat to rotate
  • rad number angle (in radians) to rotate

Returns quat out

rotateY

Rotates a quaternion by the given angle about the Y axis

Parameters

  • out quat quat receiving operation result
  • a quat quat to rotate
  • rad number angle (in radians) to rotate

Returns quat out

rotateZ

Rotates a quaternion by the given angle about the Z axis

Parameters

  • out quat quat receiving operation result
  • a quat quat to rotate
  • rad number angle (in radians) to rotate

Returns quat out

calculateW

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

  • out quat the receiving quaternion
  • a quat quat to calculate W component of

Returns quat out

dot

Calculates the dot product of two quat's

Parameters

  • a quat the first operand
  • b quat the second operand

Returns Number dot product of a and b

lerp

Performs a linear interpolation between two quat's

Parameters

  • out quat the receiving quaternion
  • a quat the first operand
  • b quat the second operand
  • t Number interpolation amount between the two inputs

Returns quat out

slerp

Performs a spherical linear interpolation between two quat

Parameters

  • out quat the receiving quaternion
  • a quat the first operand
  • b quat the second operand
  • t Number interpolation amount between the two inputs

Returns quat out

sqlerp

Performs a spherical linear interpolation with two control points

Parameters

  • out quat the receiving quaternion
  • a quat the first operand
  • b quat the second operand
  • c quat the third operand
  • d quat the fourth operand
  • t Number interpolation amount

Returns quat out

invert

Calculates the inverse of a quat

Parameters

  • out quat the receiving quaternion
  • a quat quat to calculate inverse of

Returns quat out

conjugate

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

Parameters

  • out quat the receiving quaternion
  • a quat quat to calculate conjugate of

Returns quat out

length

Calculates the length of a quat

Parameters

  • a quat vector to calculate length of

Returns Number length of a

len

Alias for quat.length

squaredLength

Calculates the squared length of a quat

Parameters

  • a quat vector to calculate squared length of

Returns Number squared length of a

sqrLen

Alias for quat.squaredLength

normalize

Normalize a quat

Parameters

  • out quat the receiving quaternion
  • a quat quaternion to normalize

Returns quat out

fromAxes

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

  • xAxis vec3 the vector representing the local "right" direction
  • yAxis vec3 the vector representing the local "up" direction
  • zAxis vec3 the vector representing the viewing direction

Returns quat out

fromViewUp

Calculates a quaternion from view direction and up direction

Parameters

  • out quat mat3 receiving operation result
  • view vec3 view direction (must be normalized)
  • up vec3? up direction, default is (0,1,0) (must be normalized)

Returns quat out

fromAxisAngle

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

Parameters

  • out quat the receiving quaternion
  • axis vec3 the axis around which to rotate
  • rad Number the angle in radians

Returns quat out

fromMat3

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

  • out quat the receiving quaternion
  • m mat3 rotation matrix

Returns quat out

fromEuler

Creates a quaternion from the given euler angle x, y, z.

Parameters

  • out quat the receiving quaternion
  • Angle x to rotate around X axis in degrees.
  • Angle y to rotate around Y axis in degrees.
  • Angle z to rotate around Z axis in degrees.
  • x
  • y
  • z

Returns quat out

str

Returns a string representation of a quatenion

Parameters

  • a quat vector to represent as a string

Returns String string representation of the vector

array

Returns typed array

Parameters

Returns array

exactEquals

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

Parameters

  • a quat The first quaternion.
  • b quat The second quaternion.

Returns Boolean True if the vectors are equal, false otherwise.

equals

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

Parameters

  • a quat The first vector.
  • b quat The second vector.

Returns Boolean True if the vectors are equal, false otherwise.

mat2

create

Creates a new identity mat2

Returns mat2 a new 2x2 matrix

new

Create a new mat2 with the given values

Parameters

  • 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)

Returns mat2 out A new 2x2 matrix

clone

Creates a new mat2 initialized with values from an existing matrix

Parameters

  • a mat2 matrix to clone

Returns mat2 a new 2x2 matrix

copy

Copy the values from one mat2 to another

Parameters

  • out mat2 the receiving matrix
  • a mat2 the source matrix

Returns mat2 out

identity

Set a mat2 to the identity matrix

Parameters

  • out mat2 the receiving matrix

Returns mat2 out

set

Set the components of a mat2 to the given values

Parameters

  • 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)

Returns mat2 out

transpose

Transpose the values of a mat2

Parameters

  • out mat2 the receiving matrix
  • a mat2 the source matrix

Returns mat2 out

invert

Inverts a mat2

Parameters

  • out mat2 the receiving matrix
  • a mat2 the source matrix

Returns mat2 out

adjoint

Calculates the adjugate of a mat2

Parameters

  • out mat2 the receiving matrix
  • a mat2 the source matrix

Returns mat2 out

determinant

Calculates the determinant of a mat2

Parameters

  • a mat2 the source matrix

Returns Number determinant of a

multiply

Multiplies two mat2's

Parameters

  • out mat2 the receiving matrix
  • a mat2 the first operand
  • b mat2 the second operand

Returns mat2 out

mul

Alias for mat2.multiply

rotate

Rotates a mat2 by the given angle

Parameters

  • out mat2 the receiving matrix
  • a mat2 the matrix to rotate
  • rad Number the angle to rotate the matrix by

Returns mat2 out

scale

Scales the mat2 by the dimensions in the given vec2

Parameters

  • out mat2 the receiving matrix
  • a mat2 the matrix to rotate
  • v vec2 the vec2 to scale the matrix by

Returns mat2 out

fromRotation

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

mat2.identity(dest);
mat2.rotate(dest, dest, rad);

Parameters

  • out mat2 mat2 receiving operation result
  • rad Number the angle to rotate the matrix by

Returns mat2 out

fromScaling

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

mat2.identity(dest);
mat2.scale(dest, dest, vec);

Parameters

  • out mat2 mat2 receiving operation result
  • v vec2 Scaling vector

Returns mat2 out

str

Returns a string representation of a mat2

Parameters

  • a mat2 matrix to represent as a string

Returns String string representation of the matrix

array

Returns typed array

Parameters

Returns array

frob

Returns Frobenius norm of a mat2

Parameters

  • a mat2 the matrix to calculate Frobenius norm of

Returns Number Frobenius norm

LDU

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

Parameters

  • L mat2 the lower triangular matrix
  • D mat2 the diagonal matrix
  • U mat2 the upper triangular matrix
  • a mat2 the input matrix to factorize

add

Adds two mat2's

Parameters

  • out mat2 the receiving matrix
  • a mat2 the first operand
  • b mat2 the second operand

Returns mat2 out

subtract

Subtracts matrix b from matrix a

Parameters

  • out mat2 the receiving matrix
  • a mat2 the first operand
  • b mat2 the second operand

Returns mat2 out

sub

Alias for mat2.subtract

exactEquals

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

Parameters

  • a mat2 The first matrix.
  • b mat2 The second matrix.

Returns Boolean True if the matrices are equal, false otherwise.

equals

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

Parameters

  • a mat2 The first matrix.
  • b mat2 The second matrix.

Returns Boolean True if the matrices are equal, false otherwise.

multiplyScalar

Multiply each element of the matrix by a scalar.

Parameters

  • out mat2 the receiving matrix
  • a mat2 the matrix to scale
  • b Number amount to scale the matrix's elements by

Returns mat2 out

multiplyScalarAndAdd

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

Parameters

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

Returns mat2 out

mat23

A mat23 contains six elements defined as:

[a, c, tx,
 b, d, ty]

This is a short form for the 3x3 matrix:

[a, c, tx,
 b, d, ty,
 0, 0, 1]

The last row is ignored so the array is shorter and operations are faster.

create

Creates a new identity mat23

Returns mat23 a new 2x3 matrix

new

Create a new mat23 with the given values

Parameters

  • 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)

Returns mat23 A new mat23

clone

Creates a new mat23 initialized with values from an existing matrix

Parameters

  • a mat23 matrix to clone

Returns mat23 a new 2x3 matrix

copy

Copy the values from one mat23 to another

Parameters

  • out mat23 the receiving matrix
  • a mat23 the source matrix

Returns mat23 out

identity

Set a mat23 to the identity matrix

Parameters

  • out mat23 the receiving matrix

Returns mat23 out

set

Set the components of a mat23 to the given values

Parameters

  • out mat23 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)

Returns mat23 out

invert

Inverts a mat23

Parameters

  • out mat23 the receiving matrix
  • a mat23 the source matrix

Returns mat23 out

determinant

Calculates the determinant of a mat23

Parameters

  • a mat23 the source matrix

Returns Number determinant of a

multiply

Multiplies two mat23's

Parameters

  • out mat23 the receiving matrix
  • a mat23 the first operand
  • b mat23 the second operand

Returns mat23 out

mul

Alias for mat23.multiply

rotate

Rotates a mat23 by the given angle

Parameters

  • out mat23 the receiving matrix
  • a mat23 the matrix to rotate
  • rad Number the angle to rotate the matrix by

Returns mat23 out

scale

Scales the mat23 by the dimensions in the given vec2

Parameters

  • out mat23 the receiving matrix
  • a mat23 the matrix to translate
  • v vec2 the vec2 to scale the matrix by

Returns mat23 out

translate

Translates the mat23 by the dimensions in the given vec2

Parameters

  • out mat23 the receiving matrix
  • a mat23 the matrix to translate
  • v vec2 the vec2 to translate the matrix by

Returns mat23 out

fromRotation

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

mat23.identity(dest);
mat23.rotate(dest, dest, rad);

Parameters

  • out mat23 mat23 receiving operation result
  • rad Number the angle to rotate the matrix by

Returns mat23 out

fromScaling

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

mat23.identity(dest);
mat23.scale(dest, dest, vec);

Parameters

  • out mat23 mat23 receiving operation result
  • v vec2 Scaling vector

Returns mat23 out

fromTranslation

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

mat23.identity(dest);
mat23.translate(dest, dest, vec);

Parameters

  • out mat23 mat23 receiving operation result
  • v vec2 Translation vector

Returns mat23 out

str

Returns a string representation of a mat23

Parameters

  • a mat23 matrix to represent as a string

Returns String string representation of the matrix

array

Returns typed array

Parameters

Returns array

frob

Returns Frobenius norm of a mat23

Parameters

  • a mat23 the matrix to calculate Frobenius norm of

Returns Number Frobenius norm

add

Adds two mat23's

Parameters

  • out mat23 the receiving matrix
  • a mat23 the first operand
  • b mat23 the second operand

Returns mat23 out

subtract

Subtracts matrix b from matrix a

Parameters

  • out mat23 the receiving matrix
  • a mat23 the first operand
  • b mat23 the second operand

Returns mat23 out

sub

Alias for mat23.subtract

multiplyScalar

Multiply each element of the matrix by a scalar.

Parameters

  • out mat23 the receiving matrix
  • a mat23 the matrix to scale
  • b Number amount to scale the matrix's elements by

Returns mat23 out

multiplyScalarAndAdd

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

Parameters

  • out mat23 the receiving vector
  • a mat23 the first operand
  • b mat23 the second operand
  • scale Number the amount to scale b's elements by before adding

Returns mat23 out

exactEquals

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

Parameters

  • a mat23 The first matrix.
  • b mat23 The second matrix.

Returns Boolean True if the matrices are equal, false otherwise.

equals

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

Parameters

  • a mat23 The first matrix.
  • b mat23 The second matrix.

Returns Boolean True if the matrices are equal, false otherwise.

mat3

create

Creates a new identity mat3

Returns mat3 a new 3x3 matrix

new

Create a new mat3 with the given values

Parameters

  • 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)

Returns mat3 A new mat3

clone

Creates a new mat3 initialized with values from an existing matrix

Parameters

  • a mat3 matrix to clone

Returns mat3 a new 3x3 matrix

copy

Copy the values from one mat3 to another

Parameters

  • out mat3 the receiving matrix
  • a mat3 the source matrix

Returns mat3 out

set

Set the components of a mat3 to the given values

Parameters

  • 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)

Returns mat3 out

identity

Set a mat3 to the identity matrix

Parameters

  • out mat3 the receiving matrix

Returns mat3 out

transpose

Transpose the values of a mat3

Parameters

  • out mat3 the receiving matrix
  • a mat3 the source matrix

Returns mat3 out

invert

Inverts a mat3

Parameters

  • out mat3 the receiving matrix
  • a mat3 the source matrix

Returns mat3 out

adjoint

Calculates the adjugate of a mat3

Parameters

  • out mat3 the receiving matrix
  • a mat3 the source matrix

Returns mat3 out

determinant

Calculates the determinant of a mat3

Parameters

  • a mat3 the source matrix

Returns Number determinant of a

multiply

Multiplies two mat3's

Parameters

  • out mat3 the receiving matrix
  • a mat3 the first operand
  • b mat3 the second operand

Returns mat3 out

mul

Alias for mat3.multiply

translate

Translate a mat3 by the given vector

Parameters

  • out mat3 the receiving matrix
  • a mat3 the matrix to translate
  • v vec2 vector to translate by

Returns mat3 out

rotate

Rotates a mat3 by the given angle

Parameters

  • out mat3 the receiving matrix
  • a mat3 the matrix to rotate
  • rad Number the angle to rotate the matrix by

Returns mat3 out

scale

Scales the mat3 by the dimensions in the given vec2

Parameters

  • out mat3 the receiving matrix
  • a mat3 the matrix to rotate
  • v vec2 the vec2 to scale the matrix by

Returns mat3 out

fromMat4

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

Parameters

  • out mat3 the receiving 3x3 matrix
  • a mat4 the source 4x4 matrix

Returns mat3 out

fromTranslation

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

mat3.identity(dest);
mat3.translate(dest, dest, vec);

Parameters

  • out mat3 mat3 receiving operation result
  • v vec2 Translation vector

Returns mat3 out

fromRotation

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

mat3.identity(dest);
mat3.rotate(dest, dest, rad);

Parameters

  • out mat3 mat3 receiving operation result
  • rad Number the angle to rotate the matrix by

Returns mat3 out

fromScaling

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

mat3.identity(dest);
mat3.scale(dest, dest, vec);

Parameters

  • out mat3 mat3 receiving operation result
  • v vec2 Scaling vector

Returns mat3 out

fromMat2d

Copies the values from a mat2d into a mat3

Parameters

  • out mat3 the receiving matrix
  • a mat2d the matrix to copy

Returns mat3 out

fromQuat

Calculates a 3x3 matrix from the given quaternion

Parameters

  • out mat3 mat3 receiving operation result
  • q quat Quaternion to create matrix from

Returns mat3 out

fromViewUp

Calculates a 3x3 matrix from view direction and up direction

Parameters

  • out mat3 mat3 receiving operation result
  • view vec3 view direction (must be normalized)
  • up vec3? up direction, default is (0,1,0) (must be normalized)

Returns mat3 out

normalFromMat4

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

Parameters

  • out mat3 mat3 receiving operation result
  • a mat4 Mat4 to derive the normal matrix from

Returns mat3 out

str

Returns a string representation of a mat3

Parameters

  • a mat3 matrix to represent as a string

Returns String string representation of the matrix

array

Returns typed array

Parameters

Returns array

frob

Returns Frobenius norm of a mat3

Parameters

  • a mat3 the matrix to calculate Frobenius norm of

Returns Number Frobenius norm

add

Adds two mat3's

Parameters

  • out mat3 the receiving matrix
  • a mat3 the first operand
  • b mat3 the second operand

Returns mat3 out

subtract

Subtracts matrix b from matrix a

Parameters

  • out mat3 the receiving matrix
  • a mat3 the first operand
  • b mat3 the second operand

Returns mat3 out

sub

Alias for mat3.subtract

multiplyScalar

Multiply each element of the matrix by a scalar.

Parameters

  • out mat3 the receiving matrix
  • a mat3 the matrix to scale
  • b Number amount to scale the matrix's elements by

Returns mat3 out

multiplyScalarAndAdd

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

Parameters

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

Returns mat3 out

exactEquals

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

Parameters

  • a mat3 The first matrix.
  • b mat3 The second matrix.

Returns Boolean True if the matrices are equal, false otherwise.

equals

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

Parameters

  • a mat3 The first matrix.
  • b mat3 The second matrix.

Returns Boolean True if the matrices are equal, false otherwise.

mat4

create

Creates a new identity mat4

Returns mat4 a new 4x4 matrix

new

Create a new mat4 with the given values

Parameters

  • 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 mat4 A new mat4

clone

Creates a new mat4 initialized with values from an existing matrix

Parameters

  • a mat4 matrix to clone

Returns mat4 a new 4x4 matrix

copy

Copy the values from one mat4 to another

Parameters

  • out mat4 the receiving matrix
  • a mat4 the source matrix

Returns mat4 out

set

Set the components of a mat4 to the given values

Parameters

  • 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 mat4 out

identity

Set a mat4 to the identity matrix

Parameters

  • out mat4 the receiving matrix

Returns mat4 out

transpose

Transpose the values of a mat4

Parameters

  • out mat4 the receiving matrix
  • a mat4 the source matrix

Returns mat4 out

invert

Inverts a mat4

Parameters

  • out mat4 the receiving matrix
  • a mat4 the source matrix

Returns mat4 out

adjoint

Calculates the adjugate of a mat4

Parameters

  • out mat4 the receiving matrix
  • a mat4 the source matrix

Returns mat4 out

determinant

Calculates the determinant of a mat4

Parameters

  • a mat4 the source matrix

Returns Number determinant of a

multiply

Multiplies two mat4's explicitly

Parameters

  • out mat4 the receiving matrix
  • a mat4 the first operand
  • b mat4 the second operand

Returns mat4 out

mul

Alias for mat4.multiply

translate

Translate a mat4 by the given vector

Parameters

  • out mat4 the receiving matrix
  • a mat4 the matrix to translate
  • v vec3 vector to translate by

Returns mat4 out

scale

Scales the mat4 by the dimensions in the given vec3

Parameters

  • out mat4 the receiving matrix
  • a mat4 the matrix to scale
  • v vec3 the vec3 to scale the matrix by

Returns mat4 out

rotate

Rotates a mat4 by the given angle around the given axis

Parameters

  • 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 mat4 out

rotateX

Rotates a matrix by the given angle around the X axis

Parameters

  • out mat4 the receiving matrix
  • a mat4 the matrix to rotate
  • rad Number the angle to rotate the matrix by

Returns mat4 out

rotateY

Rotates a matrix by the given angle around the Y axis

Parameters

  • out mat4 the receiving matrix
  • a mat4 the matrix to rotate
  • rad Number the angle to rotate the matrix by

Returns mat4 out

rotateZ

Rotates a matrix by the given angle around the Z axis

Parameters

  • out mat4 the receiving matrix
  • a mat4 the matrix to rotate
  • rad Number the angle to rotate the matrix by

Returns mat4 out

fromTranslation

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

mat4.identity(dest);
mat4.translate(dest, dest, vec);

Parameters

  • out mat4 mat4 receiving operation result
  • v vec3 Translation vector

Returns mat4 out

fromScaling

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

mat4.identity(dest);
mat4.scale(dest, dest, vec);

Parameters

  • out mat4 mat4 receiving operation result
  • v vec3 Scaling vector

Returns mat4 out

fromRotation

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

  • out mat4 mat4 receiving operation result
  • rad Number the angle to rotate the matrix by
  • axis vec3 the axis to rotate around

Returns mat4 out

fromXRotation

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

  • out mat4 mat4 receiving operation result
  • rad Number the angle to rotate the matrix by

Returns mat4 out

fromYRotation

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

  • out mat4 mat4 receiving operation result
  • rad Number the angle to rotate the matrix by

Returns mat4 out

fromZRotation

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

  • out mat4 mat4 receiving operation result
  • rad Number the angle to rotate the matrix by

Returns mat4 out

fromRT

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();
quat.toMat4(quat, quatMat);
mat4.multiply(dest, quatMat);

Parameters

  • out mat4 mat4 receiving operation result
  • q quat Rotation quaternion
  • v vec3 Translation vector

Returns mat4 out

getTranslation

Returns the translation vector component of a transformation matrix. If a matrix is built with fromRT, the returned vector will be the same as the translation vector originally supplied.

Parameters

  • out vec3 Vector to receive translation component
  • mat mat4 Matrix to be decomposed (input)

Returns vec3 out

getScaling

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

Parameters

  • out vec3 Vector to receive scaling factor component
  • mat mat4 Matrix to be decomposed (input)

Returns vec3 out

getRotation

Returns a quaternion representing the rotational component of a transformation matrix. If a matrix is built with fromRT, the returned quaternion will be the same as the quaternion originally supplied.

Parameters

  • out quat Quaternion to receive the rotation component
  • mat mat4 Matrix to be decomposed (input)

Returns quat out

fromRTS

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();
quat.toMat4(quat, quatMat);
mat4.multiply(dest, quatMat);
mat4.scale(dest, scale)

Parameters

  • out mat4 mat4 receiving operation result
  • q quat Rotation quaternion
  • v vec3 Translation vector
  • s vec3 Scaling vector

Returns mat4 out

fromRTSOrigin

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();
quat.toMat4(quat, quatMat);
mat4.multiply(dest, quatMat);
mat4.scale(dest, scale)
mat4.translate(dest, negativeOrigin);

Parameters

  • out mat4 mat4 receiving operation result
  • q quat Rotation quaternion
  • v vec3 Translation vector
  • s vec3 Scaling vector
  • o vec3 The origin vector around which to scale and rotate

Returns mat4 out

fromQuat

Calculates a 4x4 matrix from the given quaternion

Parameters

  • out mat4 mat4 receiving operation result
  • q quat Quaternion to create matrix from

Returns mat4 out

frustum

Generates a frustum matrix with the given bounds

Parameters

  • 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 mat4 out

perspective

Generates a perspective projection matrix with the given bounds

Parameters

  • 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

Returns mat4 out

perspectiveFromFieldOfView

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

  • 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 mat4 out

ortho

Generates a orthogonal projection matrix with the given bounds

Parameters

  • 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 mat4 out

lookAt

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

Parameters

  • 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 mat4 out

str

Returns a string representation of a mat4

Parameters

  • a mat4 matrix to represent as a string

Returns String string representation of the matrix

array

Returns typed array

Parameters

Returns array

frob

Returns Frobenius norm of a mat4

Parameters

  • a mat4 the matrix to calculate Frobenius norm of

Returns Number Frobenius norm

add

Adds two mat4's

Parameters

  • out mat4 the receiving matrix
  • a mat4 the first operand
  • b mat4 the second operand

Returns mat4 out

subtract

Subtracts matrix b from matrix a

Parameters

  • out mat4 the receiving matrix
  • a mat4 the first operand
  • b mat4 the second operand

Returns mat4 out

sub

Alias for mat4.subtract

multiplyScalar

Multiply each element of the matrix by a scalar.

Parameters

  • out mat4 the receiving matrix
  • a mat4 the matrix to scale
  • b Number amount to scale the matrix's elements by

Returns mat4 out

multiplyScalarAndAdd

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

Parameters

  • 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 mat4 out

exactEquals

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

Parameters

  • a mat4 The first matrix.
  • b mat4 The second matrix.

Returns Boolean True if the matrices are equal, false otherwise.

equals

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

Parameters

  • a mat4 The first matrix.
  • b mat4 The second matrix.

Returns Boolean True if the matrices are equal, false otherwise.

Bit twiddling hacks for JavaScript.

Author: Mikola Lysenko

Ported from Stanford bit twiddling hack library: http://graphics.stanford.edu/~seander/bithacks.html

sign

Returns -1, 0, +1 depending on sign of x

Parameters

Returns number

abs

Computes absolute value of integer

Parameters

Returns number

min

Computes minimum of integers x and y

Parameters

Returns number

max

Computes maximum of integers x and y

Parameters

Returns number

isPow2

Checks if a number is a power of two

Parameters

Returns boolean

log2

Computes log base 2 of v

Parameters

Returns number

log10

Computes log base 10 of v

Parameters

Returns number

popCount

Counts number of bits

Parameters

Returns number

countTrailingZeros

Counts number of trailing zeros

Parameters

Returns number

nextPow2

Rounds to next power of 2

Parameters

Returns number

prevPow2

Rounds down to previous power of 2

Parameters

Returns number

parity

Computes parity of word

Parameters

Returns number

reverse

Reverse bits in a 32 bit word

Parameters

Returns number

interleave2

Interleave bits of 2 coordinates with 16 bits. Useful for fast quadtree codes

Parameters

Returns number

deinterleave2

Extracts the nth interleaved component

Parameters

Returns number

interleave3

Interleave bits of 3 coordinates, each with 10 bits. Useful for fast octree codes

Parameters

Returns number

deinterleave3

Extracts nth interleaved component of a 3-tuple

Parameters

Returns number

nextCombination

Computes next combination in colexicographic order (this is mistakenly called nextPermutation on the bit twiddling hacks page)

Parameters

Returns number