sm.util
Offers various math-related functions.
Functions:
axesToQuat bezier2 bezier3 clamp easing lerp positiveModulo smootherstep smoothstep
sm.util.axesToQuat(xAxis, yAxis)
Constructs a quaternion from a X and Z axis
Parameters:
Type | Name | Description |
Vec3 | xAxis | The X axis. |
Vec3 | yAxis | The Z axis. |
Returns:
Type | Description |
Quat | rotation The quaternion. |
sm.util.bezier2(c0, c1, c2, t)
Quadratic Bezier interpolation. One dimensional bezier curve.
Parameters:
Type | Name | Description |
number | c0 | The start value. |
number | c1 | The control point. |
number | c2 | The end value. |
number | t | The interpolation step. |
Returns:
Type | Description |
number | The interpolated value between two values. |
sm.util.bezier3(c0, c1, c2, c3, t)
Cubic Bezier interpolation. One dimensional bezier curve.
Parameters:
Type | Name | Description |
number | c0 | The start value. |
number | c1 | The first control point. |
number | c2 | The second control point. |
number | c3 | The end value. |
number | t | The interpolation step. |
Returns:
Type | Description |
number | The interpolated value between two values. |
sm.util.clamp(value, min, max)
Restricts a value to a given range.
Parameters:
Type | Name | Description |
number | value | The value. |
number | min | The lower limit. |
number | max | The upper limit. |
Returns:
Type | Description |
number | The clamped value. |
sm.util.easing(easing, p)
Applies an easing function to a given input.
Easing function names:
linear |
easeInQuad |
easeOutQuad |
easeInOutQuad |
easeInCubic |
easeOutCubic |
easeInOutCubic |
easeInQuart |
easeOutQuart |
easeInOutQuart |
easeInQuint |
easeOutQuint |
easeInOutQuint |
easeInSine |
easeOutSine |
easeInOutSine |
easeInCirc |
easeOutCirc |
easeInOutCirc |
easeInExpo |
easeOutExpo |
easeInOutExpo |
easeInElastic |
easeOutElastic |
easeInOutElastic |
easeInBack |
easeOutBack |
easeInOutBack |
easeInBounce |
easeOutBounce |
easeInOutBounce |
Parameters:
Type | Name | Description |
string | easing | The easing function name. |
number | p | The easing function input. |
Returns:
Type | Description |
number | The output. |
sm.util.lerp(a, b, t)
Linear interpolation between two values. This is known as a lerp.
Parameters:
Type | Name | Description |
number | a | The first value. |
number | b | The second value. |
number | t | The interpolation step. |
Returns:
Type | Description |
number | The interpolated value between two values. |
sm.util.positiveModulo(x, n)
Returns the positive remainder after division of x by n.
Parameters:
Type | Name | Description |
integer | x | The number. |
integer | n | The modulo value. |
Returns:
Type | Description |
number | The value. |
sm.util.smootherstep(edge0, edge1, x)
An improved version of the smoothstep function which has zero 1st and 2nd order derivatives at `x = edge0` and `x = edge1`.
Parameters:
Type | Name | Description |
number | edge0 | The value of the lower edge of the Hermite function. |
number | edge1 | The value of the upper edge of the Hermite function. |
number | x | The source value for interpolation. |
Returns:
Type | Description |
number | The value. |
sm.util.smoothstep(edge0, edge1, x)
Performs smooth Hermite interpolation between 0 and 1 when `edge0 < x < edge1`. This is useful in cases where a threshold function with a smooth transition is desired.
Parameters:
Type | Name | Description |
number | edge0 | The value of the lower edge of the Hermite function. |
number | edge1 | The value of the upper edge of the Hermite function. |
number | x | The source value for interpolation. |
Returns:
Type | Description |
number | The value. |