Array-based vector, quaternion and matrix math with utils for PEX.
npm install pex-mathimport { mat4 } from "pex-math";
const identityMatrix = mat4.create();
// => [1, 0, 0, 0,
// 0, 1, 0, 0,
// 0, 0, 1, 0,
// 0, 0, 0, 1]- TypedArray :
Int8Array|Uint8Array|Uint8ClampedArray|Int16Array|Uint16Array|Int32Array|Uint32Array|Float16Array|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.
- easeFn ⇒
number Ease functions signature.
- easeStepFn ⇒
number Ease step functions signature.
pex-math.mat2x3 : mat2x3
Kind: static property of pex-math
pex-math.mat3 : mat3
Kind: static property of pex-math
pex-math.mat4 : mat4
Kind: static property of pex-math
pex-math.vec2 : vec2
Kind: static property of pex-math
pex-math.vec3 : vec3
Kind: static property of pex-math
pex-math.vec4 : vec4
Kind: static property of pex-math
pex-math.avec2 : avec2
Kind: static property of pex-math
pex-math.avec3 : avec3
Kind: static property of pex-math
pex-math.avec4 : avec4
Kind: static property of pex-math
pex-math.quat : quat
Kind: static property of pex-math
pex-math.euler : euler
Kind: static property of pex-math
pex-math.eases : eases
Kind: static property of pex-math
pex-math.utils : utils
Kind: static property of pex-math
- 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
Sets a vector components.
Kind: static method of avec2
| Param | Type |
|---|---|
| a | AVec2 |
| i | number |
| x | number |
| y | number |
Sets a vector to another vector.
Kind: static method of avec2
| Param | Type |
|---|---|
| a | AVec2 |
| i | number |
| b | AVec2 |
| j | number |
Compares two vectors.
Kind: static method of avec2
| Param | Type |
|---|---|
| a | AVec2 |
| i | number |
| b | AVec2 |
| j | number |
Adds a vector to another.
Kind: static method of avec2
| Param | Type |
|---|---|
| a | AVec2 |
| i | number |
| b | AVec2 |
| j | number |
Subtracts a vector from another.
Kind: static method of avec2
| Param | Type |
|---|---|
| a | AVec2 |
| i | number |
| b | AVec2 |
| j | number |
Scales a vector by a number.
Kind: static method of avec2
| Param | Type |
|---|---|
| a | AVec2 |
| i | number |
| s | number |
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 |
Calculates the dot product of two vectors.
Kind: static method of avec2
| Param | Type |
|---|---|
| a | AVec2 |
| i | number |
| b | AVec2 |
| j | number |
Calculates the length of a vector.
Kind: static method of avec2
| Param | Type |
|---|---|
| a | AVec2 |
| i | number |
Calculates the squared length of a vector.
Kind: static method of avec2
| Param | Type |
|---|---|
| a | AVec2 |
| i | number |
Normalises a vector.
Kind: static method of avec2
| Param | Type |
|---|---|
| a | AVec2 |
| i | number |
Calculates the distance between two vectors.
Kind: static method of avec2
| Param | Type |
|---|---|
| a | AVec2 |
| i | number |
| b | AVec2 |
| j | number |
Calculates the squared distance between two vectors.
Kind: static method of avec2
| Param | Type |
|---|---|
| a | AVec2 |
| i | number |
| b | AVec2 |
| j | number |
Limits a vector to a length.
Kind: static method of avec2
| Param | Type |
|---|---|
| a | AVec2 |
| i | number |
| len | number |
Linearly interpolates between two vectors.
Kind: static method of avec2
| Param | Type |
|---|---|
| a | AVec2 |
| i | number |
| b | AVec2 |
| j | number |
| t | number |
Executes a function once for each array element.
Kind: static method of avec2
| Param | Type |
|---|---|
| a | AVec2 |
| callbackFn | iterativeCallback |
avec2.map(a, callbackFn) ⇒ AVec2
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 |
Prints a vector to a string.
Kind: static method of avec2
| Param | Type | Default |
|---|---|---|
| a | AVec2 |
|
| i | number |
|
| [precision] | number |
4 |
- 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
Sets a vector components.
Kind: static method of avec3
| Param | Type |
|---|---|
| a | AVec3 |
| i | number |
| x | number |
| y | number |
| z | number |
Sets a vector to another vector.
Kind: static method of avec3
| Param | Type |
|---|---|
| a | AVec3 |
| i | number |
| b | AVec3 |
| j | number |
Compares two vectors.
Kind: static method of avec3
| Param | Type |
|---|---|
| a | AVec3 |
| i | number |
| b | AVec3 |
| j | number |
Adds a vector to another.
Kind: static method of avec3
| Param | Type |
|---|---|
| a | AVec3 |
| i | number |
| b | AVec3 |
| j | number |
Subtracts a vector from another.
Kind: static method of avec3
| Param | Type |
|---|---|
| a | AVec3 |
| i | number |
| b | AVec3 |
| j | number |
Scales a vector by a number.
Kind: static method of avec3
| Param | Type |
|---|---|
| a | AVec3 |
| i | number |
| s | number |
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 |
Multiplies a vector by a matrix.
Kind: static method of avec3
| Param | Type |
|---|---|
| a | AVec3 |
| i | number |
| m | AMat4 |
| j | number |
Multiplies a vector by a quaternion.
Kind: static method of avec3
| Param | Type |
|---|---|
| a | AVec3 |
| i | number |
| q | AQuat |
| j | number |
Calculates the dot product of two vectors.
Kind: static method of avec3
| Param | Type |
|---|---|
| a | AVec3 |
| i | number |
| b | AVec3 |
| j | number |
Calculates the cross product of two vectors.
Kind: static method of avec3
| Param | Type |
|---|---|
| a | AVec3 |
| i | number |
| b | AVec3 |
| j | number |
Calculates the length of a vector.
Kind: static method of avec3
| Param | Type |
|---|---|
| a | AVec3 |
| i | number |
Calculates the squared length of a vector.
Kind: static method of avec3
| Param | Type |
|---|---|
| a | AVec3 |
| i | number |
Normalises a vector.
Kind: static method of avec3
| Param | Type |
|---|---|
| a | AVec3 |
| i | number |
Calculates the distance between two vectors.
Kind: static method of avec3
| Param | Type |
|---|---|
| a | AVec3 |
| i | number |
| b | AVec3 |
| j | number |
Calculates the squared distance between two vectors.
Kind: static method of avec3
| Param | Type |
|---|---|
| a | AVec3 |
| i | number |
| b | AVec3 |
| j | number |
Limits a vector to a length.
Kind: static method of avec3
| Param | Type |
|---|---|
| a | AVec3 |
| i | number |
| len | number |
Linearly interpolates between two vectors.
Kind: static method of avec3
| Param | Type |
|---|---|
| a | AVec3 |
| i | number |
| b | AVec3 |
| j | number |
| t | number |
Executes a function once for each array element.
Kind: static method of avec3
| Param | Type |
|---|---|
| a | AVec3 |
| callbackFn | iterativeCallback |
avec3.map(a, callbackFn) ⇒ AVec3
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 |
Prints a vector to a string.
Kind: static method of avec3
| Param | Type | Default |
|---|---|---|
| a | AVec3 |
|
| i | number |
|
| [precision] | number |
4 |
Sets a vector components.
Kind: static method of avec4
| Param | Type |
|---|---|
| a | AVec4 |
| i | number |
| x | number |
| y | number |
| z | number |
| w | number |
Sets a vector to another vector.
Kind: static method of avec4
| Param | Type |
|---|---|
| a | AVec4 |
| i | number |
| b | AVec4 |
| j | number |
Compares two vectors.
Kind: static method of avec4
| Param | Type |
|---|---|
| a | AVec4 |
| i | number |
| b | AVec4 |
| j | number |
Adds a vector to another.
Kind: static method of avec4
| Param | Type |
|---|---|
| a | AVec4 |
| i | number |
| b | AVec4 |
| j | number |
Subtracts a vector from another.
Kind: static method of avec4
| Param | Type |
|---|---|
| a | AVec4 |
| i | number |
| b | AVec4 |
| j | number |
Scales a vector by a number.
Kind: static method of avec4
| Param | Type |
|---|---|
| a | AVec4 |
| i | number |
| s | number |
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 |
Multiplies a vector with a matrix.
Kind: static method of avec4
| Param | Type |
|---|---|
| a | AVec4 |
| i | number |
| m | AMat4 |
| j | number |
Linearly interpolates between two vectors.
Kind: static method of avec4
| Param | Type |
|---|---|
| a | AVec4 |
| i | number |
| b | AVec4 |
| j | number |
| t | number |
Executes a function once for each array element.
Kind: static method of avec4
| Param | Type |
|---|---|
| a | AVec4 |
| callbackFn | iterativeCallback |
avec4.map(a, callbackFn) ⇒ AVec4
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 |
Prints a vector to a string.
Kind: static method of avec4
| Param | Type | Default |
|---|---|---|
| a | AVec4 |
|
| i | number |
|
| [precision] | number |
4 |
- eases
- .linear() :
easeFn - .sineIn() :
easeFn - .sineOut() :
easeFn - .sineInOut() :
easeFn - .quadIn() :
easeFn - .quadOut() :
easeFn - .quadInOut() :
easeFn - .cubicIn() :
easeFn - .cubicOut() :
easeFn - .cubicInOut() :
easeFn - .quartIn() :
easeFn - .quartOut() :
easeFn - .quartInOut() :
easeFn - .quintIn() :
easeFn - .quintOut() :
easeFn - .quintInOut() :
easeFn - .expoIn() :
easeFn - .expoOut() :
easeFn - .expoInOut() :
easeFn - .circIn() :
easeFn - .circOut() :
easeFn - .circInOut() :
easeFn - .backIn() :
easeFn - .backOut() :
easeFn - .backInOut() :
easeFn - .elasticIn() :
easeFn - .elasticOut() :
easeFn - .elasticInOut() :
easeFn - .bounceIn() :
easeFn - .bounceOut() :
easeFn - .bounceInOut() :
easeFn - .stepStart() :
easeStepFn - .stepEnd() :
easeStepFn - .stepNone() :
easeStepFn - .stepBoth() :
easeStepFn
- .linear() :
eases.linear() : easeFn
Kind: static method of eases
eases.sineIn() : easeFn
Kind: static method of eases
eases.sineOut() : easeFn
Kind: static method of eases
eases.sineInOut() : easeFn
Kind: static method of eases
eases.quadIn() : easeFn
Kind: static method of eases
eases.quadOut() : easeFn
Kind: static method of eases
eases.quadInOut() : easeFn
Kind: static method of eases
eases.cubicIn() : easeFn
Kind: static method of eases
eases.cubicOut() : easeFn
Kind: static method of eases
eases.cubicInOut() : easeFn
Kind: static method of eases
eases.quartIn() : easeFn
Kind: static method of eases
eases.quartOut() : easeFn
Kind: static method of eases
eases.quartInOut() : easeFn
Kind: static method of eases
eases.quintIn() : easeFn
Kind: static method of eases
eases.quintOut() : easeFn
Kind: static method of eases
eases.quintInOut() : easeFn
Kind: static method of eases
eases.expoIn() : easeFn
Kind: static method of eases
eases.expoOut() : easeFn
Kind: static method of eases
eases.expoInOut() : easeFn
Kind: static method of eases
eases.circIn() : easeFn
Kind: static method of eases
eases.circOut() : easeFn
Kind: static method of eases
eases.circInOut() : easeFn
Kind: static method of eases
eases.backIn() : easeFn
Kind: static method of eases
eases.backOut() : easeFn
Kind: static method of eases
eases.backInOut() : easeFn
Kind: static method of eases
eases.elasticIn() : easeFn
Kind: static method of eases
eases.elasticOut() : easeFn
Kind: static method of eases
eases.elasticInOut() : easeFn
Kind: static method of eases
eases.bounceIn() : easeFn
Kind: static method of eases
eases.bounceOut() : easeFn
Kind: static method of eases
eases.bounceInOut() : easeFn
Kind: static method of eases
eases.stepStart() : easeStepFn
Kind: static method of eases
eases.stepEnd() : easeStepFn
Kind: static method of eases
eases.stepNone() : easeStepFn
Kind: static method of eases
eases.stepBoth() : easeStepFn
Kind: static method of eases
euler.create() ⇒ Euler
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.fromQuat(a, q) ⇒ Euler
Creates euler angles from quaternion. Assumes XYZ order of rotations.
Kind: static method of euler
| Param | Type |
|---|---|
| a | Euler |
| q | Quat |
- 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.create() ⇒ Mat2x3
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 5Equivalent to the column major OpenGL spec:
0 3
1 4
2 5
m00 m10
m01 m11
m02 m12Kind: static method of mat2x3
mat2x3.identity(a) ⇒ Mat2x3
Sets a matrix to the identity matrix.
Kind: static method of mat2x3
| Param | Type |
|---|---|
| a | Mat2x3 |
mat2x3.copy(a) ⇒ Mat2x3
Returns a copy of a matrix.
Kind: static method of mat2x3
| Param | Type |
|---|---|
| a | Mat2x3 |
mat2x3.set(a, b) ⇒ Mat2x3
Sets a matrix from another matrix.
Kind: static method of mat2x3
| Param | Type |
|---|---|
| a | Mat2x3 |
| b | Mat2x3 |
Compares two matrices.
Kind: static method of mat2x3
| Param | Type |
|---|---|
| a | Mat2x3 |
| b | Mat2x3 |
mat2x3.mult(a, b) ⇒ Mat2x3
Multiplies two matrices.
Kind: static method of mat2x3
| Param | Type |
|---|---|
| a | Mat2x3 |
| b | Mat2x3 |
mat2x3.translate(a, v) ⇒ Mat2x3
Translates a matrix by a vector.
Kind: static method of mat2x3
| Param | Type |
|---|---|
| a | Mat2x3 |
| v | Vec2 |
mat2x3.rotate(a, rad) ⇒ Mat2x3
Rotates a matrix by an angle.
Kind: static method of mat2x3
| Param | Type |
|---|---|
| a | Mat2x3 |
| rad | Radians |
mat2x3.scale(a, v) ⇒ Mat2x3
Scales a matrix by a vector.
Kind: static method of mat2x3
| Param | Type |
|---|---|
| a | Mat2x3 |
| v | Vec2 |
- 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.create() ⇒ Mat3
Returns a 3x3 identity matrix.
Row major memory layout:
0 1 2
3 4 5
6 7 8Equivalent to the column major OpenGL spec:
0 3 6
1 4 7
2 5 8
m00 m10 m20
m01 m11 m21
m02 m12 m22Kind: static method of mat3
mat3.identity(a) ⇒ Mat3
Sets a matrix to the identity matrix.
Kind: static method of mat3
| Param | Type |
|---|---|
| a | Mat3 |
mat3.copy(a) ⇒ Mat3
Returns a copy of a matrix.
Kind: static method of mat3
| Param | Type |
|---|---|
| a | Mat3 |
mat3.set(a, b) ⇒ Mat3
Sets a matrix from another matrix.
Kind: static method of mat3
| Param | Type |
|---|---|
| a | Mat3 |
| b | Mat3 |
Compares two matrices.
Kind: static method of mat3
| Param | Type |
|---|---|
| a | Mat3 |
| b | Mat3 |
mat3.mult(a, b) ⇒ Mat3
Multiplies two matrices.
Kind: static method of mat3
| Param | Type |
|---|---|
| a | Mat3 |
| b | Mat3 |
mat3.transpose(a) ⇒ Mat3
Transposes a matrix.
Kind: static method of mat3
| Param | Type |
|---|---|
| a | Mat3 |
mat3.fromQuat(a, q) ⇒ Mat3
Sets matrix to a quaternion.
Kind: static method of mat3
| Param | Type |
|---|---|
| a | Mat3 |
| q | Quat |
mat3.fromMat2x3(a, b) ⇒ Mat3
Sets a 3x3 matrix from a 2x3 matrix.
Kind: static method of mat3
| Param | Type |
|---|---|
| a | Mat3 |
| b | Mat2x3 |
mat3.fromMat4(a, b) ⇒ Mat3
Sets a 3x3 matrix to a 4x4 matrix.
Kind: static method of mat3
| Param | Type |
|---|---|
| a | Mat3 |
| b | 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 - .determinant(a) ⇒
number - .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 - .frustumZO(a, left, right, bottom, top, near, far) ⇒
Mat4 - .perspective(a, fovy, aspectRatio, near, far) ⇒
Mat4 - .perspectiveZO(a, fovy, aspectRatio, near, far) ⇒
Mat4 - .ortho(a, left, right, bottom, top, near, far) ⇒
Mat4 - .orthoZO(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.create() ⇒ Mat4
Returns a 4x4 identity matrix.
Row major memory layout:
0 1 2 3
4 5 6 7
8 9 10 11
12 13 14 15Equivalent 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 m33Kind: static method of mat4
mat4.identity(a) ⇒ Mat4
Sets a matrix to the identity matrix.
Kind: static method of mat4
| Param | Type |
|---|---|
| a | Mat4 |
mat4.copy(a) ⇒ Mat4
Returns a copy of a matrix.
Kind: static method of mat4
| Param | Type |
|---|---|
| a | Mat4 |
mat4.set(a, b) ⇒ Mat4
Sets a matrix from another matrix.
Kind: static method of mat4
| Param | Type |
|---|---|
| a | Mat4 |
| b | Mat4 |
Compares two matrices.
Kind: static method of mat4
| Param | Type |
|---|---|
| a | Mat4 |
| b | Mat4 |
mat4.mult(a, b) ⇒ Mat4
Multiplies two matrices.
Kind: static method of mat4
| Param | Type |
|---|---|
| a | Mat4 |
| b | Mat4 |
mat4.invert(a) ⇒ Mat4
Inverts a matrix.
Kind: static method of mat4
| Param | Type |
|---|---|
| a | Mat4 |
Returns the determinant of a matrix.
Kind: static method of mat4
| Param | Type |
|---|---|
| a | Mat4 |
mat4.transpose(a) ⇒ Mat4
Transposes a matrix.
Kind: static method of mat4
| Param | Type |
|---|---|
| a | Mat4 |
mat4.translate(a, v) ⇒ Mat4
Translates a matrix by a vector.
Kind: static method of mat4
| Param | Type |
|---|---|
| a | Mat4 |
| v | Vec3 |
mat4.rotate(a, r, v) ⇒ Mat4
Rotates a matrix by an angle at an axis.
Kind: static method of mat4
| Param | Type |
|---|---|
| a | Mat4 |
| r | Radians |
| v | Vec3 |
mat4.scale(a, v) ⇒ Mat4
Scales a matrix by a vector.
Kind: static method of mat4
| Param | Type |
|---|---|
| a | Mat4 |
| v | Vec3 |
mat4.fromQuat(a, q) ⇒ Mat4
Sets a matrix to a quaternion.
Kind: static method of mat4
| Param | Type |
|---|---|
| a | Mat4 |
| q | Quat |
mat4.fromTranslationRotationScale(a, v, q, s) ⇒ Mat4
Sets a matrix to the TRS matrix.
Kind: static method of mat4
| Param | Type |
|---|---|
| a | Mat4 |
| v | Vec3 |
| q | Quat |
| s | Vec3 |
mat4.fromMat3(a, b) ⇒ Mat4
Sets a 4x4 matrix to a 3x3 matrix.
Kind: static method of mat4
| Param | Type |
|---|---|
| a | Mat4 |
| b | Mat3 |
mat4.frustum(a, left, right, bottom, top, near, far) ⇒ Mat4
Creates a frustum matrix with depth mapped to [-1, 1] (WebGL/OpenGL).
Kind: static method of mat4
| Param | Type |
|---|---|
| a | Mat4 |
| left | number |
| right | number |
| bottom | number |
| top | number |
| near | number |
| far | number |
mat4.frustumZO(a, left, right, bottom, top, near, far) ⇒ Mat4
Creates a frustum matrix with depth mapped to [0, 1] (WebGPU/DirectX/Metal/Vulkan).
Kind: static method of mat4
| Param | Type |
|---|---|
| a | Mat4 |
| left | number |
| right | number |
| bottom | number |
| top | number |
| near | number |
| far | number |
mat4.perspective(a, fovy, aspectRatio, near, far) ⇒ Mat4
Creates a perspective matrix with depth mapped to [-1, 1] (WebGL/OpenGL).
Kind: static method of mat4
| Param | Type |
|---|---|
| a | Mat4 |
| fovy | Radians |
| aspectRatio | number |
| near | number |
| far | number |
mat4.perspectiveZO(a, fovy, aspectRatio, near, far) ⇒ Mat4
Creates a perspective matrix with depth mapped to [0, 1] (WebGPU/DirectX/Metal/Vulkan).
Kind: static method of mat4
| Param | Type |
|---|---|
| a | Mat4 |
| fovy | Radians |
| aspectRatio | number |
| near | number |
| far | number |
mat4.ortho(a, left, right, bottom, top, near, far) ⇒ Mat4
Creates an orthographic matrix with depth mapped to [-1, 1] (WebGL/OpenGL).
Kind: static method of mat4
| Param | Type |
|---|---|
| a | Mat4 |
| left | number |
| right | number |
| bottom | number |
| top | number |
| near | number |
| far | number |
mat4.orthoZO(a, left, right, bottom, top, near, far) ⇒ Mat4
Creates an orthographic matrix with depth mapped to [0, 1] (WebGPU/DirectX/Metal/Vulkan).
Kind: static method of mat4
| Param | Type |
|---|---|
| a | Mat4 |
| left | number |
| right | number |
| bottom | number |
| top | number |
| near | number |
| far | number |
mat4.lookAt(a, from, to, [up]) ⇒ Mat4
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.fromDirection(a, direction, [up]) ⇒ Mat4
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.fromPointToPoint(a, from, to, [up]) ⇒ Mat4
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
- .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.set ⇒ Quat
Sets a quaternion to another quaternion.
Kind: static constant of quat
| Param | Type |
|---|---|
| a | Quat |
| b | Quat |
Compares two quaternions.
Kind: static constant of quat
| Param | Type |
|---|---|
| a | Quat |
| b | Quat |
quat.toString ⇒ Quat
Prints a quaternion to a string.
Kind: static constant of quat
| Param | Type |
|---|---|
| a | Quat |
| precision | number |
quat.create() ⇒ Quat
Returns a new quat at 0, 0, 0, 1.
Kind: static method of quat
quat.identity(a) ⇒ Quat
Sets a quaternion to the identity quaternion.
Kind: static method of quat
| Param | Type |
|---|---|
| a | Quat |
quat.copy(a) ⇒ Quat
Returns a copy of a quaternion.
Kind: static method of quat
| Param | Type |
|---|---|
| a | Quat |
quat.mult(a, b) ⇒ Quat
Multiplies one quaternion by another.
Kind: static method of quat
| Param | Type |
|---|---|
| a | Quat |
| b | Quat |
quat.invert(a) ⇒ Quat
Inverts a quaternion.
Kind: static method of quat
| Param | Type |
|---|---|
| a | Quat |
quat.conjugate(a) ⇒ Quat
Conjugates a quaternion.
Kind: static method of quat
| Param | Type |
|---|---|
| a | Quat |
quat.length(a) ⇒ Quat
Calculates the length of a quaternion.
Kind: static method of quat
| Param | Type |
|---|---|
| a | Quat |
quat.normalize(a) ⇒ Quat
Normalizes a quaternion.
Kind: static method of quat
| Param | Type |
|---|---|
| a | Quat |
quat.dot(a, b) ⇒ Quat
Calculates the dot product of two quaternions.
Kind: static method of quat
| Param | Type |
|---|---|
| a | Quat |
| b | Quat |
quat.fromEuler(a, e) ⇒ Quat
Set euler angles to a quaternion. Assumes XYZ rotation order.
Kind: static method of quat
| Param | Type |
|---|---|
| a | Quat |
| e | Euler |
quat.fromAxisAngle(a, v, r) ⇒ Quat
Set the angle at an axis of a quaternion.
Kind: static method of quat
| Param | Type |
|---|---|
| a | Quat |
| v | Vec3 |
| r | Radians |
quat.fromAxes(a, x, y, z) ⇒ Quat
Sets a quaternion from orthonormal base xyz.
Kind: static method of quat
| Param | Type |
|---|---|
| a | Quat |
| x | Vec3 |
| y | Vec3 |
| z | Vec3 |
quat.fromMat3(a, m) ⇒ Quat
Sets a quaternion to a 3x3 matrix.
Kind: static method of quat
| Param | Type |
|---|---|
| a | Quat |
| m | Mat3 |
quat.fromMat4(a, m) ⇒ Quat
Sets a quaternion to a 4x4 matrix.
Kind: static method of quat
| Param | Type |
|---|---|
| a | Quat |
| m | Mat4 |
quat.fromDirection(a, direction, [up]) ⇒ Quat
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.fromPointToPoint(a, from, to, [up]) ⇒ Quat
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.slerp(a, b, t) ⇒ Quat
Spherical linear interpolates between two quaternions.
Kind: static method of quat
| Param | Type |
|---|---|
| a | Quat |
| b | Quat |
| t | number |
- utils
- .EPSILON :
number - .HALF_PI :
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 :
Kind: static constant of utils
Kind: static constant of utils
utils.Y_UP : Vec3
Kind: static constant of utils
Linear interpolation between two numbers.
Kind: static method of utils
| Param | Type |
|---|---|
| a | number |
| b | number |
| t | number |
Clamps a number between two numbers.
Kind: static method of utils
| Param | Type |
|---|---|
| n | number |
| min | number |
| max | number |
Smooth Hermite interpolation between 0 and 1
Kind: static method of utils
| Param | Type |
|---|---|
| n | number |
| min | number |
| max | number |
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 |
utils.toRadians(degrees) ⇒ Radians
Transforms degrees into radians.
Kind: static method of utils
| Param | Type |
|---|---|
| degrees | Degrees |
utils.toDegrees(radians) ⇒ Degrees
Transforms radians into degrees.
Kind: static method of utils
| Param | Type |
|---|---|
| radians | Radians |
Check if a number is a power of two
Kind: static method of utils
| Param | Type |
|---|---|
| a | number |
Returns the next highest power of two.
Kind: static method of utils
| Param | Type |
|---|---|
| n | number |
Returns the previous power of two.
Kind: static method of utils
| Param | Type |
|---|---|
| n | number |
- 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.create() ⇒ Vec2
Returns a new vec2 at 0, 0.
Kind: static method of vec2
vec2.copy(a) ⇒ Vec2
Returns a copy of a vector.
Kind: static method of vec2
| Param | Type |
|---|---|
| a | Vec2 |
vec2.set(a, b) ⇒ Vec2
Sets a vector to another vector.
Kind: static method of vec2
| Param | Type |
|---|---|
| a | Vec2 |
| b | Vec2 |
Compares two vectors.
Kind: static method of vec2
| Param | Type |
|---|---|
| a | Vec2 |
| b | Vec2 |
vec2.add(a, b) ⇒ Vec2
Add a vector to another.
Kind: static method of vec2
| Param | Type |
|---|---|
| a | Vec2 |
| b | Vec2 |
vec2.sub(a, b) ⇒ Vec2
Subtracts a vector from another.
Kind: static method of vec2
| Param | Type |
|---|---|
| a | Vec2 |
| b | Vec2 |
vec2.scale(a, s) ⇒ Vec2
Scales a vector by a number.
Kind: static method of vec2
| Param | Type |
|---|---|
| a | Vec2 |
| s | number |
vec2.addScaled(a, b, s) ⇒ Vec2
Adds two vectors after scaling the second one.
Kind: static method of vec2
| Param | Type |
|---|---|
| a | Vec2 |
| b | Vec2 |
| s | number |
Calculates the dot product of two vectors.
Kind: static method of vec2
| Param | Type |
|---|---|
| a | Vec2 |
| b | Vec2 |
Calculates the length of a vector.
Kind: static method of vec2
| Param | Type |
|---|---|
| a | Vec2 |
Calculates the squared length of a vector.
Kind: static method of vec2
| Param | Type |
|---|---|
| a | Vec2 |
vec2.normalize(a) ⇒ Vec2
Normalises a vector.
Kind: static method of vec2
| Param | Type |
|---|---|
| a | Vec2 |
Calculates the distance between two vectors.
Kind: static method of vec2
| Param | Type |
|---|---|
| a | Vec2 |
| b | Vec2 |
Calculates the squared distance between two vectors.
Kind: static method of vec2
| Param | Type |
|---|---|
| a | Vec2 |
| b | Vec2 |
vec2.limit(a, len) ⇒ Vec2
Limits a vector to a length.
Kind: static method of vec2
| Param | Type |
|---|---|
| a | Vec2 |
| len | number |
vec2.lerp(a, b, t) ⇒ Vec2
Linearly interpolates between two vectors.
Kind: static method of vec2
| Param | Type |
|---|---|
| a | Vec2 |
| b | Vec2 |
| t | number |
Prints a vector to a string.
Kind: static method of vec2
| Param | Type | Default |
|---|---|---|
| a | Vec2 |
|
| [precision] | number |
4 |
- 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.create() ⇒ Vec3
Returns a new vec3 at 0, 0, 0.
Kind: static method of vec3
vec3.copy(a) ⇒ Vec3
Returns a copy of a vector.
Kind: static method of vec3
| Param | Type |
|---|---|
| a | Vec3 |
vec3.set(a, b) ⇒ Vec3
Sets a vector to another vector.
Kind: static method of vec3
| Param | Type |
|---|---|
| a | Vec3 |
| b | Vec3 |
Compares two vectors.
Kind: static method of vec3
| Param | Type |
|---|---|
| a | Vec3 |
| b | Vec3 |
vec3.add(a, b) ⇒ Vec3
Adds a vector to another.
Kind: static method of vec3
| Param | Type |
|---|---|
| a | Vec3 |
| b | Vec3 |
vec3.sub(a, b) ⇒ Vec3
Subtracts a vector from another.
Kind: static method of vec3
| Param | Type |
|---|---|
| a | Vec3 |
| b | Vec3 |
vec3.scale(a, s) ⇒ Vec3
Scales a vector by a number.
Kind: static method of vec3
| Param | Type |
|---|---|
| a | Vec3 |
| s | number |
vec3.addScaled(a, b, s) ⇒ Vec3
Adds two vectors after scaling the second one.
Kind: static method of vec3
| Param | Type |
|---|---|
| a | Vec3 |
| b | Vec3 |
| s | number |
vec3.multMat4(a, m) ⇒ Vec3
Multiplies a vector by a matrix.
Kind: static method of vec3
| Param | Type |
|---|---|
| a | Vec3 |
| m | Mat4 |
vec3.multQuat(a, q) ⇒ Vec3
Multiplies a vector by a quaternion.
Kind: static method of vec3
| Param | Type |
|---|---|
| a | Vec3 |
| q | Quat |
Calculates the dot product of two vectors.
Kind: static method of vec3
| Param | Type |
|---|---|
| a | Vec3 |
| b | Vec3 |
vec3.cross(a, b) ⇒ Vec3
Calculates the cross product of two vectors.
Kind: static method of vec3
| Param | Type |
|---|---|
| a | Vec3 |
| b | Vec3 |
Calculates the length of a vector.
Kind: static method of vec3
| Param | Type |
|---|---|
| a | Vec3 |
Calculates the squared length of a vector.
Kind: static method of vec3
| Param | Type |
|---|---|
| a | Vec3 |
vec3.normalize(a) ⇒ Vec3
Normalises a vector.
Kind: static method of vec3
| Param | Type |
|---|---|
| a | Vec3 |
Calculates the distance between two vectors.
Kind: static method of vec3
| Param | Type |
|---|---|
| a | Vec3 |
| b | Vec3 |
Calculates the squared distance between two vectors.
Kind: static method of vec3
| Param | Type |
|---|---|
| a | Vec3 |
| b | Vec3 |
vec3.limit(a, len) ⇒ Vec3
Limits a vector to a length.
Kind: static method of vec3
| Param | Type |
|---|---|
| a | Vec3 |
| len | number |
vec3.lerp(a, b, t) ⇒ Vec3
Linearly interpolates between two vectors.
Kind: static method of vec3
| Param | Type |
|---|---|
| a | Vec3 |
| b | Vec3 |
| t | number |
Prints a vector to a string.
Kind: static method of vec3
| Param | Type | Default |
|---|---|---|
| a | Vec3 |
|
| [precision] | number |
4 |
- 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.create() ⇒ Vec4
Returns a new vec4 at 0, 0, 0, 1.
Kind: static method of vec4
vec4.copy(a) ⇒ Vec4
Returns a copy of a vector.
Kind: static method of vec4
| Param | Type |
|---|---|
| a | Vec4 |
vec4.set(a, b) ⇒ Vec4
Sets a vector to another vector.
Kind: static method of vec4
| Param | Type |
|---|---|
| a | Vec4 |
| b | Vec4 |
Compares two vectors.
Kind: static method of vec4
| Param | Type |
|---|---|
| a | Vec4 |
| b | Vec4 |
vec4.add(a, b) ⇒ Vec4
Adds a vector to another.
Kind: static method of vec4
| Param | Type |
|---|---|
| a | Vec4 |
| b | Vec4 |
vec4.sub(a, b) ⇒ Vec4
Subtracts a vector from another.
Kind: static method of vec4
| Param | Type |
|---|---|
| a | Vec4 |
| b | Vec4 |
vec4.scale(a, s) ⇒ Vec4
Scales a vector by a number.
Kind: static method of vec4
| Param | Type |
|---|---|
| a | Vec4 |
| s | number |
vec4.addScaled(a, b, s) ⇒ Vec4
Adds two vectors after scaling the second one.
Kind: static method of vec4
| Param | Type |
|---|---|
| a | Vec4 |
| b | Vec4 |
| s | number |
vec4.fromVec3(a, b) ⇒ Vec4
Create a vec4 from vec3.
Kind: static method of vec4
| Param | Type |
|---|---|
| a | Vec4 |
| b | Vec3 |
vec4.multMat4(a, m) ⇒ Vec4
Multiplies a vector with a matrix.
Kind: static method of vec4
| Param | Type |
|---|---|
| a | Vec4 |
| m | Mat4 |
vec4.lerp(a, b, t) ⇒ Vec4
Linearly interpolates between two vectors.
Kind: static method of vec4
| Param | Type |
|---|---|
| a | Vec4 |
| b | Vec4 |
| t | number |
Prints a vector to a string.
Kind: static method of vec4
| Param | Type | Default |
|---|---|---|
| a | Vec4 |
|
| [precision] | number |
4 |
TypedArray : Int8Array | Uint8Array | Uint8ClampedArray | Int16Array | Uint16Array | Int32Array | Uint32Array | Float16Array | Float32Array | Float64Array | BigInt64Array | BigUint64Array
AVec2 : TypedArray
AVec3 : TypedArray
AVec4 : TypedArray
AMat4 : TypedArray
AQuat : TypedArray
Callback for iterating typed arrays.
Kind: global typedef
| Param | Type |
|---|---|
| element | Vec2 | Vec3 | Vec4 |
| index | number |
| array | AVec2 | AVec3 | AVec4 |
Ease functions signature.
Kind: global typedef
| Param | Type | Description |
|---|---|---|
| t | number |
Interpolant value |
Ease step functions signature.
Kind: global typedef
| Param | Type | Default | Description |
|---|---|---|---|
| t | number |
Interpolant value | |
| [step] | number |
1 |
Number of steps |
MIT. See license file.