An object with several math utility functions.
Converts the angular value to range [0, 2π)
.
v3d.MathUtils.angleToRange_0_2Pi(0.5 * Math.PI) // → 1.570796 = 1/2 π
v3d.MathUtils.angleToRange_0_2Pi(-0.5 * Math.PI) // → 4.712388 = 3/2 π
v3d.MathUtils.angleToRange_0_2Pi(2 * Math.PI) // → 0
v3d.MathUtils.angleToRange_0_2Pi(3 * Math.PI) // → 3.141592 = π
v3d.MathUtils.angleToRange_0_2Pi(10 * Math.PI) // → 0
Converts the angular value to range [-π, π)
.
value — Value to be clamped.
min — Minimum value.
max — Maximum value.
Clamps the value to be between min and max.
angle — angle to be clamped.
minAngle — minimum angle.
maxAngle — maximum angle.
Clamps the angular value to be between minAngle and maxAngle.
Converts degrees to radians.
Computes the Euclidean modulo of m % n, that is:
((n % m) + m) % m
valueFrom — previous value.
valueTo — new value.
sampleTime — sample time (time constant).
time — time passed.
Perform exponential smoothing of the float value.
valueFrom — previous value.
valueTo — new value.
sampleTime — sample time (time constant).
time — time passed.
clampDelta — clamping threshold.
Perform exponential smoothing of the float value clamping small values less than clampDelta
.
Generate a UUID (universally unique identifier).
Return true
if n is a power of 2.
x — Start point.
y — End point.
value — A value between start and end.
Returns the percentage in the closed interval [0, 1]
of the given value between the start and end point.
Calculate 32-bit hash value for the given string.
x — Start point.
y — End point.
t — interpolation factor in the closed interval [0, 1]
.
Returns a value linearly interpolated from two known points based on the given interval: t = 0 will return x and t = 1 will return y.
x — Current point.
y — Target point.
lambda — A higher lambda value will make the movement more sudden, and a lower value will make the movement more gradual.
dt — Delta time in seconds.
Smoothly interpolate a number from x toward y in a spring-like manner using the dt to maintain frame rate independent movement. For details, see here.
x — Value to be mapped.
a1 — Minimum value for range A.
a2 — Maximum value for range A.
b1 — Minimum value for range B.
b2 — Maximum value for range B.
Linear mapping of x from range [a1, a2] to range [b1, b2].
x — The value to pingpong.
length — The positive value the function will pingpong to. Default is 1
.
Returns a value that alternates between 0 and length : Float.
Returns the smallest power of 2 that is greater than or equal to n.
Returns the largest power of 2 that is less than or equal to n.
Converts radians to degrees.
Random float in the interval [low, high].
Random float in the interval [- range / 2, range / 2].
Random integer in the interval [low, high].
Deterministic pseudo-random float in the interval [0, 1]
. The integer seed is optional.
x — The value to evaluate based on its position between min and max.
min — Any x value below min will be 0
.
max — Any x value above max will be 1
.
Returns a value between 0-1 that represents the percentage that x has moved between min and max, but smoothed or slowed down the closer X is to the min and max.
See Smoothstep for details.
x — The value to evaluate based on its position between min and max.
min — Any x value below min will be 0
.
max — Any x value above max will be 1
.
Returns a value between 0-1. A variation on smoothstep that has zero 1st and 2nd order derivatives at x=0 and x=1.
q — the quaternion to be set
a — the rotation applied to the first axis, in radians
b — the rotation applied to the second axis, in radians
c — the rotation applied to the third axis, in radians
order — a string specifying the axes order: 'XYX'
, 'XZX'
, 'YXY'
, 'YZY'
, 'ZXZ'
, or 'ZYZ'
.
Sets quaternion q from the intrinsic Proper Euler Angles defined by angles a, b, and c, and order order.
Rotations are applied to the axes in the order specified by order: rotation by angle a is applied first, then by angle b, then by angle c. Angles are in radians.
For more info on how to obtain the source code of this module see this page.