pex-math
Array-based vector, quaternion and matrix math with utils for PEX.
Installation
npm install pex-math
Usage
import { mat4 } from "pex-math";
const identityMatrix = mat4.create();
// => [1, 0, 0, 0,
// 0, 1, 0, 0,
// 0, 0, 1, 0,
// 0, 0, 0, 1]
API
Modules
Typedefs
-
TypedArray :
Int8Array
|Uint8Array
|Uint8ClampedArray
|Int16Array
|Uint16Array
|Int32Array
|Uint32Array
|Float32Array
|Float64Array
|BigInt64Array
|BigUint64Array
-
avec2 :
TypedArray
-
avec3 :
TypedArray
-
avec4 :
TypedArray
-
amat4 :
TypedArray
-
aquat :
TypedArray
-
euler :
Array.<number>
-
mat2x3 :
Array.<number>
-
mat3 :
Array.<number>
-
mat4 :
Array.<number>
-
quat :
Array.<number>
-
vec2 :
Array.<number>
-
vec3 :
Array.<number>
-
vec4 :
Array.<number>
-
Degrees :
number
-
Radians :
number
-
iterativeCallback :
function
-
Callback for iterating typed arrays.
pex-math
mat2x3
pex-math.mat2x3 : Kind: static property of pex-math
mat3
pex-math.mat3 : Kind: static property of pex-math
mat4
pex-math.mat4 : Kind: static property of pex-math
vec2
pex-math.vec2 : Kind: static property of pex-math
vec3
pex-math.vec3 : Kind: static property of pex-math
vec4
pex-math.vec4 : Kind: static property of pex-math
avec2
pex-math.avec2 : Kind: static property of pex-math
avec3
pex-math.avec3 : Kind: static property of pex-math
avec4
pex-math.avec4 : Kind: static property of pex-math
quat
pex-math.quat : Kind: static property of pex-math
euler
pex-math.euler : Kind: static property of pex-math
utils
pex-math.utils : Kind: static property of pex-math
avec2
-
avec2
- .set2(a, i, x, y)
- .set(a, i, b, j)
-
.equals(a, i, b, j) ⇒
boolean
- .add(a, i, b, j)
- .sub(a, i, b, j)
- .scale(a, i, s)
- .addScaled(a, i, b, j, s)
-
.dot(a, i, b, j) ⇒
number
-
.length(a, i) ⇒
number
-
.lengthSq(a, i) ⇒
number
- .normalize(a, i)
-
.distance(a, i, b, j) ⇒
number
-
.distanceSq(a, i, b, j) ⇒
number
- .limit(a, i, len)
- .lerp(a, i, b, j, t)
- .forEach(a, callbackFn)
-
.map(a, callbackFn) ⇒
avec2
-
.toString(a, i, [precision]) ⇒
string
avec2.set2(a, i, x, y)
Sets a vector components.
Kind: static method of avec2
Param | Type |
---|---|
a | avec2 |
i | number |
x | number |
y | number |
avec2.set(a, i, b, j)
Sets a vector to another vector.
Kind: static method of avec2
Param | Type |
---|---|
a | avec2 |
i | number |
b | avec2 |
j | number |
boolean
avec2.equals(a, i, b, j) ⇒ Compares two vectors.
Kind: static method of avec2
Param | Type |
---|---|
a | avec2 |
i | number |
b | avec2 |
j | number |
avec2.add(a, i, b, j)
Adds a vector to another.
Kind: static method of avec2
Param | Type |
---|---|
a | avec2 |
i | number |
b | avec2 |
j | number |
avec2.sub(a, i, b, j)
Subtracts a vector from another.
Kind: static method of avec2
Param | Type |
---|---|
a | avec2 |
i | number |
b | avec2 |
j | number |
avec2.scale(a, i, s)
Scales a vector by a number.
Kind: static method of avec2
Param | Type |
---|---|
a | avec2 |
i | number |
s | number |
avec2.addScaled(a, i, b, j, s)
Adds two vectors after scaling the second one.
Kind: static method of avec2
Param | Type |
---|---|
a | avec2 |
i | number |
b | avec2 |
j | number |
s | number |
number
avec2.dot(a, i, b, j) ⇒ Calculates the dot product of two vectors.
Kind: static method of avec2
Param | Type |
---|---|
a | avec2 |
i | number |
b | avec2 |
j | number |
number
avec2.length(a, i) ⇒ Calculates the length of a vector.
Kind: static method of avec2
Param | Type |
---|---|
a | avec2 |
i | number |
number
avec2.lengthSq(a, i) ⇒ Calculates the squared length of a vector.
Kind: static method of avec2
Param | Type |
---|---|
a | avec2 |
i | number |
avec2.normalize(a, i)
Normalises a vector.
Kind: static method of avec2
Param | Type |
---|---|
a | avec2 |
i | number |
number
avec2.distance(a, i, b, j) ⇒ Calculates the distance between two vectors.
Kind: static method of avec2
Param | Type |
---|---|
a | avec2 |
i | number |
b | avec2 |
j | number |
number
avec2.distanceSq(a, i, b, j) ⇒ Calculates the squared distance between two vectors.
Kind: static method of avec2
Param | Type |
---|---|
a | avec2 |
i | number |
b | avec2 |
j | number |
avec2.limit(a, i, len)
Limits a vector to a length.
Kind: static method of avec2
Param | Type |
---|---|
a | avec2 |
i | number |
len | number |
avec2.lerp(a, i, b, j, t)
Linearly interpolates between two vectors.
Kind: static method of avec2
Param | Type |
---|---|
a | avec2 |
i | number |
b | avec2 |
j | number |
t | number |
avec2.forEach(a, callbackFn)
Executes a function once for each array element.
Kind: static method of avec2
Param | Type |
---|---|
a | avec2 |
callbackFn | iterativeCallback |
avec2
avec2.map(a, callbackFn) ⇒ Creates a new array populated with the results of calling a provided function on every element in the calling array.
Kind: static method of avec2
Param | Type |
---|---|
a | avec2 |
callbackFn | iterativeCallback |
string
avec2.toString(a, i, [precision]) ⇒ Prints a vector to a string.
Kind: static method of avec2
Param | Type | Default |
---|---|---|
a | avec2 |
|
i | number |
|
[precision] | number |
4 |
avec3
-
avec3
- .set3(a, i, x, y, z)
- .set(a, i, b, j)
-
.equals(a, i, b, j) ⇒
boolean
- .add(a, i, b, j)
- .sub(a, i, b, j)
- .scale(a, i, s)
- .addScaled(a, i, b, j, s)
- .multMat4(a, i, m, j)
- .multQuat(a, i, q, j)
-
.dot(a, i, b, j) ⇒
number
- .cross(a, i, b, j)
-
.length(a, i) ⇒
number
-
.lengthSq(a, i) ⇒
number
- .normalize(a, i)
-
.distance(a, i, b, j) ⇒
number
-
.distanceSq(a, i, b, j) ⇒
number
- .limit(a, i, len)
- .lerp(a, i, b, j, t)
- .forEach(a, callbackFn)
-
.map(a, callbackFn) ⇒
avec3
-
.toString(a, i, [precision]) ⇒
string
avec3.set3(a, i, x, y, z)
Sets a vector components.
Kind: static method of avec3
Param | Type |
---|---|
a | avec3 |
i | number |
x | number |
y | number |
z | number |
avec3.set(a, i, b, j)
Sets a vector to another vector.
Kind: static method of avec3
Param | Type |
---|---|
a | avec3 |
i | number |
b | avec3 |
j | number |
boolean
avec3.equals(a, i, b, j) ⇒ Compares two vectors.
Kind: static method of avec3
Param | Type |
---|---|
a | avec3 |
i | number |
b | avec3 |
j | number |
avec3.add(a, i, b, j)
Adds a vector to another.
Kind: static method of avec3
Param | Type |
---|---|
a | avec3 |
i | number |
b | avec3 |
j | number |
avec3.sub(a, i, b, j)
Subtracts a vector from another.
Kind: static method of avec3
Param | Type |
---|---|
a | avec3 |
i | number |
b | avec3 |
j | number |
avec3.scale(a, i, s)
Scales a vector by a number.
Kind: static method of avec3
Param | Type |
---|---|
a | avec3 |
i | number |
s | number |
avec3.addScaled(a, i, b, j, s)
Adds two vectors after scaling the second one.
Kind: static method of avec3
Param | Type |
---|---|
a | avec3 |
i | number |
b | avec3 |
j | number |
s | number |
avec3.multMat4(a, i, m, j)
Multiplies a vector by a matrix.
Kind: static method of avec3
Param | Type |
---|---|
a | avec3 |
i | number |
m | amat4 |
j | number |
avec3.multQuat(a, i, q, j)
Multiplies a vector by a quaternion.
Kind: static method of avec3
Param | Type |
---|---|
a | avec3 |
i | number |
q | aquat |
j | number |
number
avec3.dot(a, i, b, j) ⇒ Calculates the dot product of two vectors.
Kind: static method of avec3
Param | Type |
---|---|
a | avec3 |
i | number |
b | avec3 |
j | number |
avec3.cross(a, i, b, j)
Calculates the cross product of two vectors.
Kind: static method of avec3
Param | Type |
---|---|
a | avec3 |
i | number |
b | avec3 |
j | number |
number
avec3.length(a, i) ⇒ Calculates the length of a vector.
Kind: static method of avec3
Param | Type |
---|---|
a | avec3 |
i | number |
number
avec3.lengthSq(a, i) ⇒ Calculates the squared length of a vector.
Kind: static method of avec3
Param | Type |
---|---|
a | avec3 |
i | number |
avec3.normalize(a, i)
Normalises a vector.
Kind: static method of avec3
Param | Type |
---|---|
a | avec3 |
i | number |
number
avec3.distance(a, i, b, j) ⇒ Calculates the distance between two vectors.
Kind: static method of avec3
Param | Type |
---|---|
a | avec3 |
i | number |
b | avec3 |
j | number |
number
avec3.distanceSq(a, i, b, j) ⇒ Calculates the squared distance between two vectors.
Kind: static method of avec3
Param | Type |
---|---|
a | avec3 |
i | number |
b | avec3 |
j | number |
avec3.limit(a, i, len)
Limits a vector to a length.
Kind: static method of avec3
Param | Type |
---|---|
a | avec3 |
i | number |
len | number |
avec3.lerp(a, i, b, j, t)
Linearly interpolates between two vectors.
Kind: static method of avec3
Param | Type |
---|---|
a | avec3 |
i | number |
b | avec3 |
j | number |
t | number |
avec3.forEach(a, callbackFn)
Executes a function once for each array element.
Kind: static method of avec3
Param | Type |
---|---|
a | avec3 |
callbackFn | iterativeCallback |
avec3
avec3.map(a, callbackFn) ⇒ Creates a new array populated with the results of calling a provided function on every element in the calling array.
Kind: static method of avec3
Param | Type |
---|---|
a | avec3 |
callbackFn | iterativeCallback |
string
avec3.toString(a, i, [precision]) ⇒ Prints a vector to a string.
Kind: static method of avec3
Param | Type | Default |
---|---|---|
a | avec3 |
|
i | number |
|
[precision] | number |
4 |
avec4
avec4.set4(a, i, x, y, z, w)
Sets a vector components.
Kind: static method of avec4
Param | Type |
---|---|
a | avec4 |
i | number |
x | number |
y | number |
z | number |
w | number |
avec4.set(a, i, b, j)
Sets a vector to another vector.
Kind: static method of avec4
Param | Type |
---|---|
a | avec4 |
i | number |
b | avec4 |
j | number |
boolean
avec4.equals(a, i, b, j) ⇒ Compares two vectors.
Kind: static method of avec4
Param | Type |
---|---|
a | avec4 |
i | number |
b | avec4 |
j | number |
avec4.add(a, i, b, j)
Adds a vector to another.
Kind: static method of avec4
Param | Type |
---|---|
a | avec4 |
i | number |
b | avec4 |
j | number |
avec4.sub(a, i, b, j)
Subtracts a vector from another.
Kind: static method of avec4
Param | Type |
---|---|
a | avec4 |
i | number |
b | avec4 |
j | number |
avec4.scale(a, i, s)
Scales a vector by a number.
Kind: static method of avec4
Param | Type |
---|---|
a | avec4 |
i | number |
s | number |
avec4.addScaled(a, i, b, j, s)
Adds two vectors after scaling the second one.
Kind: static method of avec4
Param | Type |
---|---|
a | avec4 |
i | number |
b | avec4 |
j | number |
s | number |
avec4.multMat4(a, i, m, j)
Multiplies a vector with a matrix.
Kind: static method of avec4
Param | Type |
---|---|
a | avec4 |
i | number |
m | amat4 |
j | number |
avec4.lerp(a, i, b, j, t)
Linearly interpolates between two vectors.
Kind: static method of avec4
Param | Type |
---|---|
a | avec4 |
i | number |
b | avec4 |
j | number |
t | number |
avec4.forEach(a, callbackFn)
Executes a function once for each array element.
Kind: static method of avec4
Param | Type |
---|---|
a | avec4 |
callbackFn | iterativeCallback |
avec4
avec4.map(a, callbackFn) ⇒ Creates a new array populated with the results of calling a provided function on every element in the calling array.
Kind: static method of avec4
Param | Type |
---|---|
a | avec4 |
callbackFn | iterativeCallback |
string
avec4.toString(a, i, [precision]) ⇒ Prints a vector to a string.
Kind: static method of avec4
Param | Type | Default |
---|---|---|
a | avec4 |
|
i | number |
|
[precision] | number |
4 |
euler
euler
euler.create() ⇒ Create a new euler angles [0, 0, 0]: vec3 array of [x, y, z] rotation [yaw, pitch, roll] in radians.
Kind: static method of euler
euler
euler.fromQuat(a, q) ⇒ Creates euler angles from quaternion. Assumes XYZ order of rotations.
Kind: static method of euler
Param | Type |
---|---|
a | euler |
q | quat |
mat2x3
-
mat2x3
-
.create() ⇒
mat2x3
-
.identity(a) ⇒
mat2x3
-
.copy(a) ⇒
mat2x3
-
.set(a, b) ⇒
mat2x3
-
.equals(a, b) ⇒
boolean
-
.mult(a, b) ⇒
mat2x3
-
.translate(a, v) ⇒
mat2x3
-
.rotate(a, rad) ⇒
mat2x3
-
.scale(a, v) ⇒
mat2x3
-
.create() ⇒
mat2x3
mat2x3.create() ⇒ Returns a 2x3 identity matrix, a short form for a 3x3 matrix with the last row ignored.
Row major memory layout:
0 1
2 3
4 5
Equivalent to the column major OpenGL spec:
0 3
1 4
2 5
m00 m10
m01 m11
m02 m12
Kind: static method of mat2x3
mat2x3
mat2x3.identity(a) ⇒ Sets a matrix to the identity matrix.
Kind: static method of mat2x3
Param | Type |
---|---|
a | mat2x3 |
mat2x3
mat2x3.copy(a) ⇒ Returns a copy of a matrix.
Kind: static method of mat2x3
Param | Type |
---|---|
a | mat2x3 |
mat2x3
mat2x3.set(a, b) ⇒ Sets a matrix from another matrix.
Kind: static method of mat2x3
Param | Type |
---|---|
a | mat2x3 |
b | mat2x3 |
boolean
mat2x3.equals(a, b) ⇒ Compares two matrices.
Kind: static method of mat2x3
Param | Type |
---|---|
a | mat2x3 |
b | mat2x3 |
mat2x3
mat2x3.mult(a, b) ⇒ Multiplies two matrices.
Kind: static method of mat2x3
Param | Type |
---|---|
a | mat2x3 |
b | mat2x3 |
mat2x3
mat2x3.translate(a, v) ⇒ Translates a matrix by a vector.
Kind: static method of mat2x3
Param | Type |
---|---|
a | mat2x3 |
v | vec2 |
mat2x3
mat2x3.rotate(a, rad) ⇒ Rotates a matrix by an angle.
Kind: static method of mat2x3
Param | Type |
---|---|
a | mat2x3 |
rad | Radians |
mat2x3
mat2x3.scale(a, v) ⇒ Scales a matrix by a vector.
Kind: static method of mat2x3
Param | Type |
---|---|
a | mat2x3 |
v | vec2 |
mat3
-
mat3
-
.create() ⇒
mat3
-
.identity(a) ⇒
mat3
-
.copy(a) ⇒
mat3
-
.set(a, b) ⇒
mat3
-
.equals(a, b) ⇒
boolean
-
.mult(a, b) ⇒
mat3
-
.transpose(a) ⇒
mat3
-
.fromQuat(a, q) ⇒
mat3
-
.fromMat2x3(a, b) ⇒
mat3
-
.fromMat4(a, b) ⇒
mat3
-
.create() ⇒
mat3
mat3.create() ⇒ Returns a 3x3 identity matrix.
Row major memory layout:
0 1 2
3 4 5
6 7 8
Equivalent to the column major OpenGL spec:
0 3 6
1 4 7
2 5 8
m00 m10 m20
m01 m11 m21
m02 m12 m22
Kind: static method of mat3
mat3
mat3.identity(a) ⇒ Sets a matrix to the identity matrix.
Kind: static method of mat3
Param | Type |
---|---|
a | mat3 |
mat3
mat3.copy(a) ⇒ Returns a copy of a matrix.
Kind: static method of mat3
Param | Type |
---|---|
a | mat3 |
mat3
mat3.set(a, b) ⇒ Sets a matrix from another matrix.
Kind: static method of mat3
Param | Type |
---|---|
a | mat3 |
b | mat3 |
boolean
mat3.equals(a, b) ⇒ Compares two matrices.
Kind: static method of mat3
Param | Type |
---|---|
a | mat3 |
b | mat3 |
mat3
mat3.mult(a, b) ⇒ Multiplies two matrices.
Kind: static method of mat3
Param | Type |
---|---|
a | mat3 |
b | mat3 |
mat3
mat3.transpose(a) ⇒ Transposes a matrix.
Kind: static method of mat3
Param | Type |
---|---|
a | mat3 |
mat3
mat3.fromQuat(a, q) ⇒ Sets matrix to a quaternion.
Kind: static method of mat3
Param | Type |
---|---|
a | mat3 |
q | quat |
mat3
mat3.fromMat2x3(a, b) ⇒ Sets a 3x3 matrix from a 2x3 matrix.
Kind: static method of mat3
Param | Type |
---|---|
a | mat3 |
b | mat2x3 |
mat3
mat3.fromMat4(a, b) ⇒ Sets a 3x3 matrix to a 4x4 matrix.
Kind: static method of mat3
Param | Type |
---|---|
a | mat3 |
b | mat4 |
mat4
-
mat4
-
.create() ⇒
mat4
-
.identity(a) ⇒
mat4
-
.copy(a) ⇒
mat4
-
.set(a, b) ⇒
mat4
-
.equals(a, b) ⇒
boolean
-
.mult(a, b) ⇒
mat4
-
.invert(a) ⇒
mat4
-
.transpose(a) ⇒
mat4
-
.translate(a, v) ⇒
mat4
-
.rotate(a, r, v) ⇒
mat4
-
.scale(a, v) ⇒
mat4
-
.fromQuat(a, q) ⇒
mat4
-
.fromTranslationRotationScale(a, v, q, s) ⇒
mat4
-
.fromMat3(a, b) ⇒
mat4
-
.frustum(a, left, right, bottom, top, near, far) ⇒
mat4
-
.perspective(a, fovy, aspectRatio, near, far) ⇒
mat4
-
.ortho(a, left, right, bottom, top, near, far) ⇒
mat4
-
.lookAt(a, from, to, [up]) ⇒
mat4
-
.fromDirection(a, direction, [up]) ⇒
mat4
-
.fromPointToPoint(a, from, to, [up]) ⇒
mat4
-
.create() ⇒
mat4
mat4.create() ⇒ Returns a 4x4 identity matrix.
Row major memory layout:
0 1 2 3
4 5 6 7
8 9 10 11
12 13 14 15
Equivalent to the column major OpenGL spec:
0 4 8 12
1 5 9 13
2 6 10 14
3 7 11 15
m00 m10 m20 m30
m01 m11 m21 m31
m02 m12 m22 m32
m03 m13 m23 m33
Kind: static method of mat4
mat4
mat4.identity(a) ⇒ Sets a matrix to the identity matrix.
Kind: static method of mat4
Param | Type |
---|---|
a | mat4 |
mat4
mat4.copy(a) ⇒ Returns a copy of a matrix.
Kind: static method of mat4
Param | Type |
---|---|
a | mat4 |
mat4
mat4.set(a, b) ⇒ Sets a matrix from another matrix.
Kind: static method of mat4
Param | Type |
---|---|
a | mat4 |
b | mat4 |
boolean
mat4.equals(a, b) ⇒ Compares two matrices.
Kind: static method of mat4
Param | Type |
---|---|
a | mat4 |
b | mat4 |
mat4
mat4.mult(a, b) ⇒ Multiplies two matrices.
Kind: static method of mat4
Param | Type |
---|---|
a | mat4 |
b | mat4 |
mat4
mat4.invert(a) ⇒ Inverts a matrix.
Kind: static method of mat4
Param | Type |
---|---|
a | mat4 |
mat4
mat4.transpose(a) ⇒ Transposes a matrix.
Kind: static method of mat4
Param | Type |
---|---|
a | mat4 |
mat4
mat4.translate(a, v) ⇒ Translates a matrix by a vector.
Kind: static method of mat4
Param | Type |
---|---|
a | mat4 |
v | vec3 |
mat4
mat4.rotate(a, r, v) ⇒ Rotates a matrix by an angle at an axis.
Kind: static method of mat4
Param | Type |
---|---|
a | mat4 |
r | Radians |
v | vec3 |
mat4
mat4.scale(a, v) ⇒ Scales a matrix by a vector.
Kind: static method of mat4
Param | Type |
---|---|
a | mat4 |
v | vec3 |
mat4
mat4.fromQuat(a, q) ⇒ Sets a matrix to a quaternion.
Kind: static method of mat4
Param | Type |
---|---|
a | mat4 |
q | quat |
mat4
mat4.fromTranslationRotationScale(a, v, q, s) ⇒ Sets a matrix to the TRS matrix.
Kind: static method of mat4
Param | Type |
---|---|
a | mat4 |
v | vec3 |
q | quat |
s | vec3 |
mat4
mat4.fromMat3(a, b) ⇒ Sets a 4x4 matrix to a 3x3 matrix.
Kind: static method of mat4
Param | Type |
---|---|
a | mat4 |
b | mat3 |
mat4
mat4.frustum(a, left, right, bottom, top, near, far) ⇒ Creates a frustum matrix.
Kind: static method of mat4
Param | Type |
---|---|
a | mat4 |
left | number |
right | number |
bottom | number |
top | number |
near | number |
far | number |
mat4
mat4.perspective(a, fovy, aspectRatio, near, far) ⇒ Creates a perspective matrix.
Kind: static method of mat4
Param | Type |
---|---|
a | mat4 |
fovy | Radians |
aspectRatio | number |
near | number |
far | number |
mat4
mat4.ortho(a, left, right, bottom, top, near, far) ⇒ Creates an orthographic matrix.
Kind: static method of mat4
Param | Type |
---|---|
a | mat4 |
left | number |
right | number |
bottom | number |
top | number |
near | number |
far | number |
mat4
mat4.lookAt(a, from, to, [up]) ⇒ Calculates a lookAt matrix from position, target and up vectors.
Kind: static method of mat4
Param | Type | Default |
---|---|---|
a | mat4 |
|
from | vec3 |
|
to | vec3 |
|
[up] | vec3 |
Y_UP |
mat4
mat4.fromDirection(a, direction, [up]) ⇒ Sets a matrix from a direction. Note: we assume +Z facing models.
Kind: static method of mat4
Param | Type | Default |
---|---|---|
a | mat4 |
|
direction | vec3 |
|
[up] | vec3 |
Y_UP |
mat4
mat4.fromPointToPoint(a, from, to, [up]) ⇒ Sets a matrix from a point to another.
Kind: static method of mat4
Param | Type | Default |
---|---|---|
a | mat4 |
|
from | vec3 |
|
to | vec3 |
|
[up] | vec3 |
Y_UP |
quat
-
quat
-
.set ⇒
quat
-
.equals ⇒
boolean
-
.toString ⇒
quat
-
.create() ⇒
quat
-
.identity(a) ⇒
quat
-
.copy(a) ⇒
quat
-
.mult(a, b) ⇒
quat
-
.invert(a) ⇒
quat
-
.conjugate(a) ⇒
quat
-
.length(a) ⇒
quat
-
.normalize(a) ⇒
quat
-
.dot(a, b) ⇒
quat
-
.fromEuler(a, e) ⇒
quat
-
.fromAxisAngle(a, v, r) ⇒
quat
-
.fromAxes(a, x, y, z) ⇒
quat
-
.fromMat3(a, m) ⇒
quat
-
.fromMat4(a, m) ⇒
quat
-
.fromDirection(a, direction, [up]) ⇒
quat
-
.fromPointToPoint(a, from, to, [up]) ⇒
quat
-
.slerp(a, b, t) ⇒
quat
-
.set ⇒
quat
quat.set ⇒ Sets a quaternion to another quaternion.
Kind: static constant of quat
Param | Type |
---|---|
a | quat |
b | quat |
boolean
quat.equals ⇒ Compares two quaternions.
Kind: static constant of quat
Param | Type |
---|---|
a | quat |
b | quat |
quat
quat.toString ⇒ Prints a quaternion to a string.
Kind: static constant of quat
Param | Type |
---|---|
a | quat |
precision | number |
quat
quat.create() ⇒ Returns a new quat at 0, 0, 0, 1.
Kind: static method of quat
quat
quat.identity(a) ⇒ Sets a quaternion to the identity quaternion.
Kind: static method of quat
Param | Type |
---|---|
a | quat |
quat
quat.copy(a) ⇒ Returns a copy of a quaternion.
Kind: static method of quat
Param | Type |
---|---|
a | quat |
quat
quat.mult(a, b) ⇒ Multiplies one quaternion by another.
Kind: static method of quat
Param | Type |
---|---|
a | quat |
b | quat |
quat
quat.invert(a) ⇒ Inverts a quaternion.
Kind: static method of quat
Param | Type |
---|---|
a | quat |
quat
quat.conjugate(a) ⇒ Conjugates a quaternion.
Kind: static method of quat
Param | Type |
---|---|
a | quat |
quat
quat.length(a) ⇒ Calculates the length of a quaternion.
Kind: static method of quat
Param | Type |
---|---|
a | quat |
quat
quat.normalize(a) ⇒ Normalizes a quaternion.
Kind: static method of quat
Param | Type |
---|---|
a | quat |
quat
quat.dot(a, b) ⇒ Calculates the dot product of two quaternions.
Kind: static method of quat
Param | Type |
---|---|
a | quat |
b | quat |
quat
quat.fromEuler(a, e) ⇒ Set euler angles to a quaternion. Assumes XYZ rotation order.
Kind: static method of quat
Param | Type |
---|---|
a | quat |
e | euler |
quat
quat.fromAxisAngle(a, v, r) ⇒ Set the angle at an axis of a quaternion.
Kind: static method of quat
Param | Type |
---|---|
a | quat |
v | vec3 |
r | Radians |
quat
quat.fromAxes(a, x, y, z) ⇒ Sets a quaternion from orthonormal base xyz.
Kind: static method of quat
Param | Type |
---|---|
a | quat |
x | vec3 |
y | vec3 |
z | vec3 |
quat
quat.fromMat3(a, m) ⇒ Sets a quaternion to a 3x3 matrix.
Kind: static method of quat
Param | Type |
---|---|
a | quat |
m | mat3 |
quat
quat.fromMat4(a, m) ⇒ Sets a quaternion to a 4x4 matrix.
Kind: static method of quat
Param | Type |
---|---|
a | quat |
m | mat4 |
quat
quat.fromDirection(a, direction, [up]) ⇒ Sets a quaternion from a direction Note: we assume +Z facing models.
Kind: static method of quat
Param | Type | Default |
---|---|---|
a | quat |
|
direction | vec3 |
|
[up] | vec3 |
Y_UP |
quat
quat.fromPointToPoint(a, from, to, [up]) ⇒ Sets a quaternion from a point to another.
Kind: static method of quat
Param | Type | Default |
---|---|---|
a | quat |
|
from | vec3 |
|
to | vec3 |
|
[up] | vec3 |
Y_UP |
quat
quat.slerp(a, b, t) ⇒ Spherical linear interpolates between two quaternions.
Kind: static method of quat
Param | Type |
---|---|
a | quat |
b | quat |
t | number |
utils
-
utils
-
.EPSILON :
number
-
.Y_UP :
vec3
-
.lerp(a, b, t) ⇒
number
-
.clamp(n, min, max) ⇒
number
-
.smoothstep(n, min, max) ⇒
number
-
.remap(n, inStart, inEnd, outStart, outEnd) ⇒
number
-
.toRadians(degrees) ⇒
Radians
-
.toDegrees(radians) ⇒
Degrees
-
.isPowerOfTwo(a) ⇒
boolean
-
.nextPowerOfTwo(n) ⇒
number
-
.prevPowerOfTwo(n) ⇒
number
-
.EPSILON :
number
utils.EPSILON : Kind: static constant of utils
vec3
utils.Y_UP : Kind: static constant of utils
number
utils.lerp(a, b, t) ⇒ Linear interpolation between two numbers.
Kind: static method of utils
Param | Type |
---|---|
a | number |
b | number |
t | number |
number
utils.clamp(n, min, max) ⇒ Clamps a number between two numbers.
Kind: static method of utils
Param | Type |
---|---|
n | number |
min | number |
max | number |
number
utils.smoothstep(n, min, max) ⇒ Smooth Hermite interpolation between 0 and 1
Kind: static method of utils
Param | Type |
---|---|
n | number |
min | number |
max | number |
number
utils.remap(n, inStart, inEnd, outStart, outEnd) ⇒ Maps a number from one range to another.
Kind: static method of utils
Param | Type |
---|---|
n | number |
inStart | number |
inEnd | number |
outStart | number |
outEnd | number |
Radians
utils.toRadians(degrees) ⇒ Transforms degrees into radians.
Kind: static method of utils
Param | Type |
---|---|
degrees | Degrees |
Degrees
utils.toDegrees(radians) ⇒ Transforms radians into degrees.
Kind: static method of utils
Param | Type |
---|---|
radians | Radians |
boolean
utils.isPowerOfTwo(a) ⇒ Check if a number is a power of two
Kind: static method of utils
Param | Type |
---|---|
a | number |
number
utils.nextPowerOfTwo(n) ⇒ Returns the next highest power of two.
Kind: static method of utils
Param | Type |
---|---|
n | number |
number
utils.prevPowerOfTwo(n) ⇒ Returns the previous power of two.
Kind: static method of utils
Param | Type |
---|---|
n | number |
vec2
-
vec2
-
.create() ⇒
vec2
-
.copy(a) ⇒
vec2
-
.set(a, b) ⇒
vec2
-
.equals(a, b) ⇒
boolean
-
.add(a, b) ⇒
vec2
-
.sub(a, b) ⇒
vec2
-
.scale(a, s) ⇒
vec2
-
.addScaled(a, b, s) ⇒
vec2
-
.dot(a, b) ⇒
number
-
.length(a) ⇒
number
-
.lengthSq(a) ⇒
number
-
.normalize(a) ⇒
vec2
-
.distance(a, b) ⇒
number
-
.distanceSq(a, b) ⇒
number
-
.limit(a, len) ⇒
vec2
-
.lerp(a, b, t) ⇒
vec2
-
.toString(a, [precision]) ⇒
string
-
.create() ⇒
vec2
vec2.create() ⇒ Returns a new vec2 at 0, 0.
Kind: static method of vec2
vec2
vec2.copy(a) ⇒ Returns a copy of a vector.
Kind: static method of vec2
Param | Type |
---|---|
a | vec2 |
vec2
vec2.set(a, b) ⇒ Sets a vector to another vector.
Kind: static method of vec2
Param | Type |
---|---|
a | vec2 |
b | vec2 |
boolean
vec2.equals(a, b) ⇒ Compares two vectors.
Kind: static method of vec2
Param | Type |
---|---|
a | vec2 |
b | vec2 |
vec2
vec2.add(a, b) ⇒ Add a vector to another.
Kind: static method of vec2
Param | Type |
---|---|
a | vec2 |
b | vec2 |
vec2
vec2.sub(a, b) ⇒ Subtracts a vector from another.
Kind: static method of vec2
Param | Type |
---|---|
a | vec2 |
b | vec2 |
vec2
vec2.scale(a, s) ⇒ Scales a vector by a number.
Kind: static method of vec2
Param | Type |
---|---|
a | vec2 |
s | number |
vec2
vec2.addScaled(a, b, s) ⇒ Adds two vectors after scaling the second one.
Kind: static method of vec2
Param | Type |
---|---|
a | vec2 |
b | vec2 |
s | number |
number
vec2.dot(a, b) ⇒ Calculates the dot product of two vectors.
Kind: static method of vec2
Param | Type |
---|---|
a | vec2 |
b | vec2 |
number
vec2.length(a) ⇒ Calculates the length of a vector.
Kind: static method of vec2
Param | Type |
---|---|
a | vec2 |
number
vec2.lengthSq(a) ⇒ Calculates the squared length of a vector.
Kind: static method of vec2
Param | Type |
---|---|
a | vec2 |
vec2
vec2.normalize(a) ⇒ Normalises a vector.
Kind: static method of vec2
Param | Type |
---|---|
a | vec2 |
number
vec2.distance(a, b) ⇒ Calculates the distance between two vectors.
Kind: static method of vec2
Param | Type |
---|---|
a | vec2 |
b | vec2 |
number
vec2.distanceSq(a, b) ⇒ Calculates the squared distance between two vectors.
Kind: static method of vec2
Param | Type |
---|---|
a | vec2 |
b | vec2 |
vec2
vec2.limit(a, len) ⇒ Limits a vector to a length.
Kind: static method of vec2
Param | Type |
---|---|
a | vec2 |
len | number |
vec2
vec2.lerp(a, b, t) ⇒ Linearly interpolates between two vectors.
Kind: static method of vec2
Param | Type |
---|---|
a | vec2 |
b | vec2 |
t | number |
string
vec2.toString(a, [precision]) ⇒ Prints a vector to a string.
Kind: static method of vec2
Param | Type | Default |
---|---|---|
a | vec2 |
|
[precision] | number |
4 |
vec3
-
vec3
-
.create() ⇒
vec3
-
.copy(a) ⇒
vec3
-
.set(a, b) ⇒
vec3
-
.equals(a, b) ⇒
boolean
-
.add(a, b) ⇒
vec3
-
.sub(a, b) ⇒
vec3
-
.scale(a, s) ⇒
vec3
-
.addScaled(a, b, s) ⇒
vec3
-
.multMat4(a, m) ⇒
vec3
-
.multQuat(a, q) ⇒
vec3
-
.dot(a, b) ⇒
number
-
.cross(a, b) ⇒
vec3
-
.length(a) ⇒
number
-
.lengthSq(a) ⇒
number
-
.normalize(a) ⇒
vec3
-
.distance(a, b) ⇒
number
-
.distanceSq(a, b) ⇒
number
-
.limit(a, len) ⇒
vec3
-
.lerp(a, b, t) ⇒
vec3
-
.toString(a, [precision]) ⇒
string
-
.create() ⇒
vec3
vec3.create() ⇒ Returns a new vec3 at 0, 0, 0.
Kind: static method of vec3
vec3
vec3.copy(a) ⇒ Returns a copy of a vector.
Kind: static method of vec3
Param | Type |
---|---|
a | vec3 |
vec3
vec3.set(a, b) ⇒ Sets a vector to another vector.
Kind: static method of vec3
Param | Type |
---|---|
a | vec3 |
b | vec3 |
boolean
vec3.equals(a, b) ⇒ Compares two vectors.
Kind: static method of vec3
Param | Type |
---|---|
a | vec3 |
b | vec3 |
vec3
vec3.add(a, b) ⇒ Adds a vector to another.
Kind: static method of vec3
Param | Type |
---|---|
a | vec3 |
b | vec3 |
vec3
vec3.sub(a, b) ⇒ Subtracts a vector from another.
Kind: static method of vec3
Param | Type |
---|---|
a | vec3 |
b | vec3 |
vec3
vec3.scale(a, s) ⇒ Scales a vector by a number.
Kind: static method of vec3
Param | Type |
---|---|
a | vec3 |
s | number |
vec3
vec3.addScaled(a, b, s) ⇒ Adds two vectors after scaling the second one.
Kind: static method of vec3
Param | Type |
---|---|
a | vec3 |
b | vec3 |
s | number |
vec3
vec3.multMat4(a, m) ⇒ Multiplies a vector by a matrix.
Kind: static method of vec3
Param | Type |
---|---|
a | vec3 |
m | mat4 |
vec3
vec3.multQuat(a, q) ⇒ Multiplies a vector by a quaternion.
Kind: static method of vec3
Param | Type |
---|---|
a | vec3 |
q | quat |
number
vec3.dot(a, b) ⇒ Calculates the dot product of two vectors.
Kind: static method of vec3
Param | Type |
---|---|
a | vec3 |
b | vec3 |
vec3
vec3.cross(a, b) ⇒ Calculates the cross product of two vectors.
Kind: static method of vec3
Param | Type |
---|---|
a | vec3 |
b | vec3 |
number
vec3.length(a) ⇒ Calculates the length of a vector.
Kind: static method of vec3
Param | Type |
---|---|
a | vec3 |
number
vec3.lengthSq(a) ⇒ Calculates the squared length of a vector.
Kind: static method of vec3
Param | Type |
---|---|
a | vec3 |
vec3
vec3.normalize(a) ⇒ Normalises a vector.
Kind: static method of vec3
Param | Type |
---|---|
a | vec3 |
number
vec3.distance(a, b) ⇒ Calculates the distance between two vectors.
Kind: static method of vec3
Param | Type |
---|---|
a | vec3 |
b | vec3 |
number
vec3.distanceSq(a, b) ⇒ Calculates the squared distance between two vectors.
Kind: static method of vec3
Param | Type |
---|---|
a | vec3 |
b | vec3 |
vec3
vec3.limit(a, len) ⇒ Limits a vector to a length.
Kind: static method of vec3
Param | Type |
---|---|
a | vec3 |
len | number |
vec3
vec3.lerp(a, b, t) ⇒ Linearly interpolates between two vectors.
Kind: static method of vec3
Param | Type |
---|---|
a | vec3 |
b | vec3 |
t | number |
string
vec3.toString(a, [precision]) ⇒ Prints a vector to a string.
Kind: static method of vec3
Param | Type | Default |
---|---|---|
a | vec3 |
|
[precision] | number |
4 |
vec4
-
vec4
-
.create() ⇒
vec4
-
.copy(a) ⇒
vec4
-
.set(a, b) ⇒
vec4
-
.equals(a, b) ⇒
boolean
-
.add(a, b) ⇒
vec4
-
.sub(a, b) ⇒
vec4
-
.scale(a, s) ⇒
vec4
-
.addScaled(a, b, s) ⇒
vec4
-
.fromVec3(a, b) ⇒
vec4
-
.multMat4(a, m) ⇒
vec4
-
.lerp(a, b, t) ⇒
vec4
-
.toString(a, [precision]) ⇒
string
-
.create() ⇒
vec4
vec4.create() ⇒ Returns a new vec4 at 0, 0, 0, 1.
Kind: static method of vec4
vec4
vec4.copy(a) ⇒ Returns a copy of a vector.
Kind: static method of vec4
Param | Type |
---|---|
a | vec4 |
vec4
vec4.set(a, b) ⇒ Sets a vector to another vector.
Kind: static method of vec4
Param | Type |
---|---|
a | vec4 |
b | vec4 |
boolean
vec4.equals(a, b) ⇒ Compares two vectors.
Kind: static method of vec4
Param | Type |
---|---|
a | vec4 |
b | vec4 |
vec4
vec4.add(a, b) ⇒ Adds a vector to another.
Kind: static method of vec4
Param | Type |
---|---|
a | vec4 |
b | vec4 |
vec4
vec4.sub(a, b) ⇒ Subtracts a vector from another.
Kind: static method of vec4
Param | Type |
---|---|
a | vec4 |
b | vec4 |
vec4
vec4.scale(a, s) ⇒ Scales a vector by a number.
Kind: static method of vec4
Param | Type |
---|---|
a | vec4 |
s | number |
vec4
vec4.addScaled(a, b, s) ⇒ Adds two vectors after scaling the second one.
Kind: static method of vec4
Param | Type |
---|---|
a | vec4 |
b | vec4 |
s | number |
vec4
vec4.fromVec3(a, b) ⇒ Create a vec4 from vec3.
Kind: static method of vec4
Param | Type |
---|---|
a | vec4 |
b | vec3 |
vec4
vec4.multMat4(a, m) ⇒ Multiplies a vector with a matrix.
Kind: static method of vec4
Param | Type |
---|---|
a | vec4 |
m | mat4 |
vec4
vec4.lerp(a, b, t) ⇒ Linearly interpolates between two vectors.
Kind: static method of vec4
Param | Type |
---|---|
a | vec4 |
b | vec4 |
t | number |
string
vec4.toString(a, [precision]) ⇒ Prints a vector to a string.
Kind: static method of vec4
Param | Type | Default |
---|---|---|
a | vec4 |
|
[precision] | number |
4 |
Int8Array
| Uint8Array
| Uint8ClampedArray
| Int16Array
| Uint16Array
| Int32Array
| Uint32Array
| Float32Array
| Float64Array
| BigInt64Array
| BigUint64Array
TypedArray :
TypedArray
avec2 :
TypedArray
avec3 :
TypedArray
avec4 :
TypedArray
amat4 :
TypedArray
aquat :
Array.<number>
euler :
Array.<number>
mat2x3 :
Array.<number>
mat3 :
Array.<number>
mat4 :
Array.<number>
quat :
Array.<number>
vec2 :
Array.<number>
vec3 :
Array.<number>
vec4 :
number
Degrees :
number
Radians :
function
iterativeCallback : Callback for iterating typed arrays.
Kind: global typedef
Param | Type |
---|---|
element |
vec2 | vec3 | vec4
|
index | number |
array |
avec2 | avec3 | avec4
|
License
MIT. See license file.