sm.util
The util library offers various math-related functions.
Functions
axesToQuat
sm.util.axesToQuat( xAxis, zAxis )
Constructs a quaternion from an X and Z axis.
Arguments:Returns:
- [ Quat ]: The created quaternion.
bezier2
sm.util.bezier2( c0, c1, c2, t )
Quadratic Bezier interpolation. One dimensional bezier curve.
Arguments:c0[ number ]: The start value.c1[ number ]: The control point.c2[ number ]: The the end value.t[ number ]: The interpolation step.
- [ number ]: The interpolated value.
bezier2
sm.util.bezier2( c0, c1, c2, c3, t )
Cubic Bezier interpolation. One dimensional bezier curve.
Arguments:c0[ number ]: The start value.c1[ number ]: The first control point.c2[ number ]: The second control point.c3[ number ]: The the end value.t[ number ]: The interpolation step.
- [ number ]: The interpolated value.
clamp
sm.util.clamp( value, min, max )
Restricts a value to a given range.
Arguments:value[ number ]: The value.min[ number ]: The lower limit.max[ number ]: The upper limit.
- [ number ]: The clamped value.
easing
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 |
easing[ string ]: The easing function name.p[ number ]: The easing function input.
- [ number ]: The output.
lerp
sm.util.lerp( a, b, t )
Linear interpolation between two values. This is known as a lerp.
Arguments:a[ number ]: The first value.b[ number ]: The second value.t[ number ]: The interpolation step.
- [ number ]: The interpolated value.
positiveModulo
sm.util.positiveModulo( x, n )
Returns the positive remainder after division of x by n.
x[ integer ]: The number.n[ integer ]: The modulo value.
- [ number ]: The value.
smootherstep
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.
edge0[ number ]: The value of the lower edge of the Hermite function.edge1[ number ]: The value of the upper edge of the Hermite function.x[ number ]: The source value for interpolation.
- [ number ]: The value.
smoothstep
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.
edge0[ number ]: The value of the lower edge of the Hermite function.edge1[ number ]: The value of the upper edge of the Hermite function.x[ number ]: The source value for interpolation.
- [ number ]: The value.