Math types
Vectors, rotations, transforms, colors, and time.
Vec3
Class
A simple Vector type which holds 3 Numbers, X+ is Forward, Y+ is Right, Z+ is Up
Properties
| Property | Type | Description |
|---|---|---|
x |
number |
The X Component of the Vector, Positive is Forward |
y |
number |
The Y Component of the Vector, Positive is Right |
z |
number |
The Z Component of the Vector, Positive is Up |
Methods
| Method | Description |
|---|---|
projectOnTo |
Projects self onto a |
length |
Gets the magnitude of the vector |
squaredLength |
Gets the squared magnitude of the vector |
normalize |
Creates a unit vector of length 1 |
getSafeNormal |
Creates a unit vector of length 1. Returns zero vector by default if vector length is too small to safely normalize. |
isNormalized |
Checks whether the vector is normalized |
getMax |
Get the maximum value of the vector's components |
getMin |
Get the minimum value of the vector's components |
getAbsMax |
Get the maximum absolute value of the vector's components |
getAbsMin |
Get the minimum absolute value of the vector's components |
getAbs |
Get a copy of this vector with absolute value of each component |
isNearlyZero |
Checks whether a vector is near to zero within a reasonable tolerance |
isZero |
Checks whether all components of a vector are exactly zero |
getSignVector |
Get a copy of the vector as sign only. Each component ise set to +1 or -1, with the sign of zero treated as +1 |
rotateAngleAxis |
Rotates self by degrees around axis. Assumes axis is normalized |
rotateAngleAxisRad |
Rotates self by radians around axis. Assumes axis is normalized |
containsNan |
Utility to check if there are any non-finite values (NaN or Inf) in this vector |
dot |
Calculate the dot product of two vectors |
cross |
Calculate the cross product of two vectors |
distance |
Calculate the distance between two vectors |
lerp |
Interpolates between two points start and end with 0 <= t <= 1 |
projectOnTo
Projects self onto a
Parameters
| Name | Type |
|---|---|
a |
Vec3 |
Returns: Vec3
length
Gets the magnitude of the vector
Returns: number
squaredLength
Gets the squared magnitude of the vector
Returns: number
normalize
Creates a unit vector of length 1
Returns: Vec3
getSafeNormal
Creates a unit vector of length 1. Returns zero vector by default if vector length is too small to safely normalize.
Returns: Vec3
isNormalized
Checks whether the vector is normalized
Returns: boolean
getMax
Get the maximum value of the vector's components
Returns: number
getMin
Get the minimum value of the vector's components
Returns: number
getAbsMax
Get the maximum absolute value of the vector's components
Returns: number
getAbsMin
Get the minimum absolute value of the vector's components
Returns: number
getAbs
Get a copy of this vector with absolute value of each component
Returns: Vec3
isNearlyZero
Checks whether a vector is near to zero within a reasonable tolerance
Returns: boolean
isZero
Checks whether all components of a vector are exactly zero
Returns: boolean
getSignVector
Get a copy of the vector as sign only. Each component ise set to +1 or -1, with the sign of zero treated as +1
Returns: Vec3
rotateAngleAxis
Rotates self by degrees around axis. Assumes axis is normalized
Parameters
| Name | Type |
|---|---|
degrees |
number |
axis |
Vec3 |
Returns: Vec3
rotateAngleAxisRad
Rotates self by radians around axis. Assumes axis is normalized
Parameters
| Name | Type |
|---|---|
radians |
number |
axis |
Vec3 |
Returns: Vec3
containsNan
Utility to check if there are any non-finite values (NaN or Inf) in this vector
Returns: boolean
dot
Calculate the dot product of two vectors
Parameters
| Name | Type |
|---|---|
rhs |
Vec3 |
Returns: number
cross
Calculate the cross product of two vectors
Parameters
| Name | Type |
|---|---|
rhs |
Vec3 |
Returns: Vec3
distance
Calculate the distance between two vectors
Parameters
| Name | Type |
|---|---|
rhs |
Vec3 |
Returns: number
lerp
Interpolates between two points start and end with 0 <= t <= 1
Parameters
| Name | Type |
|---|---|
_end |
Vec3 |
t |
number |
Returns: Vec3
Static properties
| Property | Type | Description |
|---|---|---|
zeroVector |
Vec3 |
Zero vector (0,0,0) |
oneVector |
Vec3 |
One vector (1,1,1) |
upVector |
Vec3 |
Up vector (0,0,1) |
downVector |
Vec3 |
down vector (0,0,-1) |
leftVector |
Vec3 |
Left vector (0,-1,0) |
rightVector |
Vec3 |
Right vector (0,1,0) |
forwardVector |
Vec3 |
Forward vector (1,0,0) |
backwardVector |
Vec3 |
Backward vector (-1,0,0) |
Static functions
| Method | Description |
|---|---|
dot |
Calculate the dot product of two vectors |
cross |
Calculate the cross product of two vectors |
distance |
Calculate the distance between two vectors |
lerp |
Interpolates between two points start and end with 0 <= t <= 1 |
dot
Calculate the dot product of two vectors
Parameters
| Name | Type |
|---|---|
lhs |
Vec3 |
rhs |
Vec3 |
Returns: number
cross
Calculate the cross product of two vectors
Parameters
| Name | Type |
|---|---|
lhs |
Vec3 |
rhs |
Vec3 |
Returns: Vec3
distance
Calculate the distance between two vectors
Parameters
| Name | Type |
|---|---|
lhs |
Vec3 |
rhs |
Vec3 |
Returns: number
lerp
Interpolates between two points start and end with 0 <= t <= 1
Parameters
| Name | Type |
|---|---|
start |
Vec3 |
_end |
Vec3 |
t |
number |
Returns: Vec3
Vec2
Class
A simple Vector type which holds 3 Numbers, X+ is Forward, Y+ is Right, Z+ is Up
Properties
| Property | Type | Description |
|---|---|---|
x |
number |
The X Component of the Vector, Positive is Forward |
y |
number |
The Y Component of the Vector, Positive is Right |
Methods
| Method | Description |
|---|---|
length |
Gets the magnitude of the vector |
squaredLength |
Gets the squared magnitude of the vector |
normalize |
Creates a unit vector of length 1 |
getSafeNormal |
Creates a unit vector of length 1. Returns zero vector by default if vector length is too small to safely normalize. |
isNormalized |
Checks whether the vector is normalized |
getMax |
Get the maximum value of the vector's components |
getMin |
Get the minimum value of the vector's components |
getAbsMax |
Get the maximum absolute value of the vector's components |
getAbsMin |
Get the minimum absolute value of the vector's components |
getAbs |
Get a copy of this vector with absolute value of each component |
isNearlyZero |
Checks whether a vector is near to zero within a reasonable tolerance |
isZero |
Checks whether all components of a vector are exactly zero |
getSignVector |
Get a copy of the vector as sign only. Each component ise set to +1 or -1, with the sign of zero treated as +1 |
containsNan |
Utility to check if there are any non-finite values (NaN or Inf) in this vector |
dot |
Calculate the dot product of two vectors |
distance |
Calculate the distance between two vectors |
lerp |
Interpolates between two points start and end with 0 <= t <= 1 |
length
Gets the magnitude of the vector
Returns: number
squaredLength
Gets the squared magnitude of the vector
Returns: number
normalize
Creates a unit vector of length 1
Returns: Vec2
getSafeNormal
Creates a unit vector of length 1. Returns zero vector by default if vector length is too small to safely normalize.
Returns: Vec2
isNormalized
Checks whether the vector is normalized
Returns: boolean
getMax
Get the maximum value of the vector's components
Returns: number
getMin
Get the minimum value of the vector's components
Returns: number
getAbsMax
Get the maximum absolute value of the vector's components
Returns: number
getAbsMin
Get the minimum absolute value of the vector's components
Returns: number
getAbs
Get a copy of this vector with absolute value of each component
Returns: Vec2
isNearlyZero
Checks whether a vector is near to zero within a reasonable tolerance
Returns: boolean
isZero
Checks whether all components of a vector are exactly zero
Returns: boolean
getSignVector
Get a copy of the vector as sign only. Each component ise set to +1 or -1, with the sign of zero treated as +1
Returns: Vec2
containsNan
Utility to check if there are any non-finite values (NaN or Inf) in this vector
Returns: boolean
dot
Calculate the dot product of two vectors
Parameters
| Name | Type |
|---|---|
rhs |
Vec3 |
Returns: number
distance
Calculate the distance between two vectors
Parameters
| Name | Type |
|---|---|
rhs |
Vec3 |
Returns: number
lerp
Interpolates between two points start and end with 0 <= t <= 1
Parameters
| Name | Type |
|---|---|
_end |
Vec3 |
t |
number |
Returns: Vec2
Static properties
| Property | Type | Description |
|---|---|---|
zeroVector |
Vec2 |
Zero vector (0,0) |
oneVector |
Vec2 |
One vector (1,1) |
unitDiagonal |
Vec2 |
Normalized one vector (sqrt(2),sqrt(2)) |
unitY |
Vec2 |
Unit Y vector (0,1) |
unitX |
Vec2 |
Unit X vector (0,1) |
Static functions
| Method | Description |
|---|---|
dot |
Calculate the dot product of two vectors |
distance |
Calculate the distance between two vectors |
lerp |
Interpolates between two points start and end with 0 <= t <= 1 |
dot
Calculate the dot product of two vectors
Parameters
| Name | Type |
|---|---|
lhs |
Vec2 |
rhs |
Vec3 |
Returns: number
distance
Calculate the distance between two vectors
Parameters
| Name | Type |
|---|---|
lhs |
Vec2 |
rhs |
Vec3 |
Returns: number
lerp
Interpolates between two points start and end with 0 <= t <= 1
Parameters
| Name | Type |
|---|---|
start |
Vec2 |
_end |
Vec3 |
t |
number |
Returns: Vec2
Quat
Class
A simple Quaternion type which holds 4 Numbers
Properties
| Property | Type | Description |
|---|---|---|
x |
number |
The X Component of the Quaternion |
y |
number |
The Y Component of the Quaternion |
z |
number |
The Z Component of the Quaternion |
w |
number |
The W Component of the Quaternion |
Methods
| Method | Description |
|---|---|
euler |
Convert a Quaternion into floating-point Euler angles (in degrees) |
getForwardVector |
Get the forward direction (X axis) after it has been rotated by this Quaternion |
getRightVector |
Get the right direction (Y axis) after it has been rotated by this Quaternion |
getUpVector |
Get the up direction (Z axis) after it has been rotated by this Quaternion |
rotateVector |
Rotate a vector by this quaternion |
inverse |
The inverse rotation of this quaternion |
normalize |
Normalize this quaternion if it is large enough. If it is too small, returns an identity quaternion. |
euler
Convert a Quaternion into floating-point Euler angles (in degrees)
Returns: Vec3
getForwardVector
Get the forward direction (X axis) after it has been rotated by this Quaternion
Returns: Vec3
getRightVector
Get the right direction (Y axis) after it has been rotated by this Quaternion
Returns: Vec3
getUpVector
Get the up direction (Z axis) after it has been rotated by this Quaternion
Returns: Vec3
rotateVector
Rotate a vector by this quaternion
Parameters
| Name | Type |
|---|---|
vector |
Vec3 |
Returns: Vec3
inverse
The inverse rotation of this quaternion
Returns: Quat
normalize
Normalize this quaternion if it is large enough. If it is too small, returns an identity quaternion.
Returns: Quat
Static properties
| Property | Type | Description |
|---|---|---|
identity |
Quat |
The identity quaternion, one with no rotation (0,0,0,1) |
Static functions
| Method | Description |
|---|---|
fromEuler |
Convert (roll, pitch, yaw) Euler angles (in degrees) into a Quaternion. |
fromDirection |
Return the Quaternion orientation corresponding to the direction in which the vector points. |
fromXZ |
Create a quaternion from forward and up vectors |
findBetweenVectors |
Finds the smallest rotation between two vectors |
slerp |
Spherical linear interpolation between a and b by 0 <= t <= 1 |
fromEuler
Convert (roll, pitch, yaw) Euler angles (in degrees) into a Quaternion.
Parameters
| Name | Type |
|---|---|
Roll |
number |
Pitch |
number |
Yaw |
number |
Returns: Quat
fromDirection
Return the Quaternion orientation corresponding to the direction in which the vector points.
Parameters
| Name | Type |
|---|---|
FromDirection |
Vec3 |
Returns: Quat
fromXZ
Create a quaternion from forward and up vectors
Parameters
| Name | Type |
|---|---|
Forward |
Vec3 |
Up |
Vec3 |
Returns: Quat
findBetweenVectors
Finds the smallest rotation between two vectors
Parameters
| Name | Type |
|---|---|
Start |
Vec3 |
_end |
Vec3 |
Returns: Quat
slerp
Spherical linear interpolation between a and b by 0 <= t <= 1
Parameters
| Name | Type |
|---|---|
From |
Quat |
To |
Quat |
T |
number |
Returns: Quat
Transform
Class
A simple Transform type which holds 3 Numbers, X+ is Forward, Y+ is Right, Z+ is Up
Properties
| Property | Type | Description |
|---|---|---|
position |
Vec3 |
The position of the transform |
rotation |
Quat |
The rotation of the transform |
scale |
Vec3 |
The scale of the transform |
Static properties
| Property | Type | Description |
|---|---|---|
identity |
Transform |
Identity transform |
DateTime
Class
A simple DateTime type which holds 3 Numbers, X+ is Forward, Y+ is Right, Z+ is Up
Properties
| Property | Type | Description |
|---|---|---|
ticks |
number |
The number of ticks (100 ns) since January 1 0001 |
Static functions
| Method | Description |
|---|---|
getCurrentTime |
Get the current time |
getCurrentTime
Get the current time
Returns: DateTime
Color
Class
A simple Color type which holds 4 Numbers
Properties
| Property | Type | Description |
|---|---|---|
R |
number |
The X Component of the Color |
G |
number |
The Y Component of the Color |
B |
number |
The Z Component of the Color |
W |
number |
The W Component of the Color |
Static properties
| Property | Type | Description |
|---|---|---|
White |
Color |
Gets the White Color |
Black |
Color |
Gets the Black Color |
Transparent |
Color |
Gets the Transparent Color |
Red |
Color |
Gets the Red Color |
Green |
Color |
Gets the Green Color |
Blue |
Color |
Gets the Blue Color |
Yellow |
Color |
Gets the Yellow Color |
Cyan |
Color |
Gets the Cyan Color |
Magenta |
Color |
Gets the Magenta Color |
Orange |
Color |
Gets the Orange Color |
Purple |
Color |
Gets the Purple Color |
Turquoise |
Color |
Gets the Turquoise Color |
Silver |
Color |
Gets the Silver Color |
Emerald |
Color |
Gets the Emerald Color |
LinearColor
Class
A simple LinearColor type which holds 4 Numbers
Properties
| Property | Type | Description |
|---|---|---|
R |
number |
The X Component of the LinearColor |
G |
number |
The Y Component of the LinearColor |
B |
number |
The Z Component of the LinearColor |
W |
number |
The W Component of the LinearColor |
A |
number |
The alpha (W) Component of the LinearColor |
Static properties
| Property | Type | Description |
|---|---|---|
White |
LinearColor |
The X Component of the LinearColor |