Math¶
Overview¶
The math module provides multiple primitives types such as Vector as well as various utility functions for calculating values.
Functions¶
lerp¶
function lerp(start : Float, final : Float, t : Float) -> Float
function lerp(start : Vector2, final : Vector2, t : Float) -> Vector2
function lerp(start : Vector3, final : Vector3, t : Float) -> Vector3
function lerp(start : Vector4, final : Vector4, t : Float) -> Vector4
function lerp(start : Matrix33, final : Matrix33, t : Float) -> Matrix33
Calculates a linearly interpolated value based on starting and final values and an interpolation factor.
Warning
The interpolation factor used must be in a 0..1 range for this to yield a valid result.
| Parameter | Type | Description |
|---|---|---|
| start | Float/Vector2/Vector3/Vector4/Matrix33 | Starting value used in interpolation. |
| final | Float/Vector2/Vector3/Vector4/Matrix33 | Final value used in interpolation. |
| t | Float | Interpolation percentage between start and end values. |
| Returns | Description |
|---|---|
| Float/Vector2/Vector3/Vector4/Matrix33 | Resulting value from interpolating between start and end. |
Example
slerp¶
function slerp(start : Vector3, final : Vector3, t : Float) -> Vector3
function slerp(start : Quaternion, final : Quaternion, t : Float) -> Quaternion
Calculates a spherically interpolated value based on starting and final values and an interpolation factor.
Info
This is generally used for rotations, where just using linear interpolation instead would yield non-normalised results, resulting in an invalid rotation value.
Warning
The interpolation factor used must be in a 0..1 range for this to yield a valid result.
| Parameter | Type | Description |
|---|---|---|
| start | Vector3/Quaternion | Starting value used in interpolation. |
| final | Vector3/Quaternion | Final value used in interpolation. |
| t | Float | Interpolation percentage between start and end values. |
| Returns | Description |
|---|---|
| Vector3/Quaternion | Resulting value from interpolating between start and end. |
Example
clamp¶
Limits a value to the provided range.
| Parameter | Type | Description |
|---|---|---|
| value | Float | Value to clamp. |
| min | Float | Minimum value that can be returned. |
| max | Float | Maximum value that can be returned. |
| Returns | Description |
|---|---|
| Float | The resulting value clamped to the provided min and max range. |
Example
random¶
Calculates a random value in the specified range.
| Parameter | Type | Description |
|---|---|---|
| min | Float | Minimum value that can be returned. |
| max | Float | Maximum value that can be returned. |
| Returns | Description |
|---|---|
| Float | The randomly calculated value within the specified range |