Class Scalar
Hierarchy
- Scalar
Index
Properties
Static Two PiSearch playground for TwoPi
Two pi constants convenient for computation.
Methods
Static ClampSearch playground for Clamp
-
Returns the value itself if it's between min and max. Returns min if the value is lower than min. Returns max if the value is greater than max.
Parameters
-
value: number
the value to clmap
-
Optional min: number
the min value to clamp to (default: 0)
-
Optional max: number
the max value to clamp to (default: 1)
Returns number
the clamped value
-
Static Delta AngleSearch playground for DeltaAngle
-
Calculates the shortest difference between two given angles given in degrees.
Parameters
-
current: number
current angle in degrees
-
target: number
target angle in degrees
Returns number
the delta
-
Static DenormalizeSearch playground for Denormalize
-
Denormalize the value from 0.0 and 1.0 using min and max values
Parameters
-
normalized: number
value to denormalize
-
min: number
max to denormalize between
-
max: number
min to denormalize between
Returns number
the denormalized value
-
Static HermiteSearch playground for Hermite
-
Returns a new scalar located for "amount" (float) on the Hermite spline defined by the scalars "value1", "value3", "tangent1", "tangent2".
Parameters
-
value1: number
spline value
-
tangent1: number
spline value
-
value2: number
spline value
-
tangent2: number
spline value
-
amount: number
input value
Returns number
hermite result
-
Static ILog2Search playground for ILog2
-
the floor part of a log2 value.
Parameters
-
value: number
the value to compute log2 of
Returns number
the log2 of value.
-
Static Inverse LerpSearch playground for InverseLerp
-
Calculates the linear parameter t that produces the interpolant value within the range [a, b].
Parameters
-
a: number
start value
-
b: number
target value
-
value: number
value between a and b
Returns number
the inverseLerp value
-
Static LerpSearch playground for Lerp
-
Creates a new scalar with values linearly interpolated of "amount" between the start scalar and the end scalar.
Parameters
-
start: number
start value
-
end: number
target value
-
amount: number
amount to lerp between
Returns number
the lerped value
-
Static Lerp AngleSearch playground for LerpAngle
-
Same as Lerp but makes sure the values interpolate correctly when they wrap around 360 degrees. The parameter t is clamped to the range [0, 1]. Variables a and b are assumed to be in degrees.
Parameters
-
start: number
start value
-
end: number
target value
-
amount: number
amount to lerp between
Returns number
the lerped value
-
Static Log2Search playground for Log2
-
the log2 of value.
Parameters
-
value: number
the value to compute log2 of
Returns number
the log2 of value.
-
Static Move TowardsSearch playground for MoveTowards
-
Moves a value current towards target.
This is essentially the same as Mathf.Lerp but instead the function will ensure that the speed never exceeds maxDelta. Negative values of maxDelta pushes the value away from target.
Parameters
-
current: number
current value
-
target: number
target value
-
maxDelta: number
max distance to move
Returns number
resulting value
-
Static Move Towards AngleSearch playground for MoveTowardsAngle
-
Same as MoveTowards but makes sure the values interpolate correctly when they wrap around 360 degrees.
Variables current and target are assumed to be in degrees. For optimization reasons, negative values of maxDelta are not supported and may cause oscillation. To push current away from a target angle, add 180 to that angle instead.
Parameters
-
current: number
current value
-
target: number
target value
-
maxDelta: number
max distance to move
Returns number
resulting angle
-
Static NormalizeSearch playground for Normalize
-
Normalize the value between 0.0 and 1.0 using min and max values
Parameters
-
value: number
value to normalize
-
min: number
max to normalize between
-
max: number
min to normalize between
Returns number
the normalized value
-
Static Normalize RadiansSearch playground for NormalizeRadians
-
Returns the angle converted to equivalent value between -Math.PI and Math.PI radians.
Parameters
-
angle: number
The angle to normalize in radian.
Returns number
The converted angle.
-
Static Percent ToRangeSearch playground for PercentToRange
-
This function returns number that corresponds to the percentage in a given range.
PercentToRange(0.34,0,100) will return 34.
Parameters
-
percent: number
to convert to number
-
min: number
min range
-
max: number
max range
Returns number
the number
-
Static Ping PongSearch playground for PingPong
-
PingPongs the value t, so that it is never larger than length and never smaller than 0.
Parameters
-
tx: number
value
-
length: number
length
Returns number
The returned value will move back and forth between 0 and length
-
Static Random RangeSearch playground for RandomRange
-
Returns a random float number between and min and max values
Parameters
-
min: number
min value of random
-
max: number
max value of random
Returns number
random value
-
Static Range ToPercentSearch playground for RangeToPercent
-
This function returns percentage of a number in a given range.
RangeToPercent(40,20,60) will return 0.5 (50%) RangeToPercent(34,0,100) will return 0.34 (34%)
Parameters
-
number: number
to convert to percentage
-
min: number
min range
-
max: number
max range
Returns number
the percentage
-
Static RepeatSearch playground for Repeat
-
Loops the value, so that it is never larger than length and never smaller than 0.
This is similar to the modulo operator but it works with floating point numbers. For example, using 3.0 for t and 2.5 for length, the result would be 0.5. With t = 5 and length = 2.5, the result would be 0.0. Note, however, that the behaviour is not defined for negative numbers as it is for the modulo operator
Parameters
-
value: number
the value
-
length: number
the length
Returns number
the looped value
-
Static SignSearch playground for Sign
-
Returns -1 if value is negative and +1 is value is positive.
Parameters
-
value: number
the value
Returns number
the value itself if it's equal to zero.
-
Static Smooth StepSearch playground for SmoothStep
-
Interpolates between min and max with smoothing at the limits.
This function interpolates between min and max in a similar way to Lerp. However, the interpolation will gradually speed up from the start and slow down toward the end. This is useful for creating natural-looking animation, fading and other transitions.
Parameters
-
from: number
from
-
to: number
to
-
tx: number
value
Returns number
the smooth stepped value
-
Static To HexSearch playground for ToHex
-
Returns a string : the upper case translation of the number i to hexadecimal.
Parameters
-
i: number
number
Returns string
the upper case translation of the number i to hexadecimal.
-
Static Within EpsilonSearch playground for WithinEpsilon
-
Boolean : true if the absolute difference between a and b is lower than epsilon (default = 1.401298E-45)
Parameters
-
a: number
number
-
b: number
number
-
Optional epsilon: number
(default = 1.401298E-45)
Returns boolean
true if the absolute difference between a and b is lower than epsilon (default = 1.401298E-45)
-
Scalar computation library