UWAL / MathUtils
Description
A set of mathematical variables and functions for general-purpose usage.
Variables
HPI
const HPI: number;Half PI, defined as Math.PI / 2.
TAU
const TAU: number;Double PI, defined as Math.PI * 2.
Functions
Clamp()
function Clamp(
value,
min?,
max?): number;Constrain a number between min and max values (inclusive).
Parameters
| Parameter | Type | Default value | Description |
|---|---|---|---|
value | number | undefined | Value to constrain. |
min? | number | 0 | Lower limit. |
max? | number | 1 | Upper limit. |
Returns
number
Random()
function Random(min?, max?): number;Get a pseudorandom float between min (inclusive) and max (exclusive). When max is omitted, it defaults to min while min = 0.
Parameters
| Parameter | Type | Default value | Description |
|---|---|---|---|
min? | number | 1 | Lower or upper limit. |
max? | number | undefined | Upper limit. |
Returns
number
RandomInt()
function RandomInt(min, max?): number;Get a pseudorandom integer between min and max values (inclusive). When max is omitted, it defaults to min while min = 0.
Parameters
| Parameter | Type | Description |
|---|---|---|
min | number | Lower or upper limit. |
max? | number | Upper limit. |
Returns
number
SmoothStep()
function SmoothStep(
value,
min?,
max?): number;Perform Hermite interpolation between two values. Adapted from GLSL's smoothstep function.
Parameters
| Parameter | Type | Default value | Description |
|---|---|---|---|
value | number | undefined | Value to interpolate. |
min? | number | 0 | Lower limit. |
max? | number | 1 | Upper limit. |
Returns
number
SmootherStep()
function SmootherStep(
value,
min?,
max?): number;A variation on the SmoothStep function that has zero 1st and 2nd order derivatives at x = 0 and x = 1. Adapted from three.js' smootherstep function.
Parameters
| Parameter | Type | Default value | Description |
|---|---|---|---|
value | number | undefined | Value to interpolate. |
min? | number | 0 | Lower limit. |
max? | number | 1 | Upper limit. |
Returns
number
CopyMat4Rotation()
function CopyMat4Rotation(src, dst?): Float32Array<ArrayBufferLike>;Copy the matrix rotation component into the given 4x4 matrix. Adapted from three.js' extractRotation method.
Parameters
| Parameter | Type | Description |
|---|---|---|
src | Float32Array<ArrayBufferLike> | Matrix to extract rotation. |
dst? | Float32Array<ArrayBufferLike> | Destination matrix. |
Returns
Float32Array<ArrayBufferLike>
GetMat4Rotation()
function GetMat4Rotation(
src,
dst?,
order?): Float32Array<ArrayBufferLike>;Get matrix rotation as Euler angles, assuming the upper 3x3 matrix is a pure rotation matrix. Adapted from OGL's fromRotationMatrix function.
Parameters
| Parameter | Type | Default value | Description |
|---|---|---|---|
src | Float32Array<ArrayBufferLike> | undefined | Matrix to extract rotation. |
dst? | Float32Array<ArrayBufferLike> | ... | Destination vector. |
order? | string | "XYZ" | Rotation order. |
Returns
Float32Array<ArrayBufferLike>
Throws
ERROR.INVALID_ROTATION_ORDER if the order argument is not valid.
GetMat4Scale()
function GetMat4Scale(src): number;Get maximum scale on a matrix axis. Adapted from OGL's getMaxScaleOnAxis function.
Parameters
| Parameter | Type | Description |
|---|---|---|
src | Float32Array<ArrayBufferLike> | Matrix to extract scale. |
Returns
number