Vectors
A global API which provides functions dedicated to creating and otherwise manipulating vectors
This page is a WIP. It contains all the information in Figura's documentation but we're working on adding more helpful descriptions.
Accessed using the name vectors
The functions in the Vector API never receive self
as a parameter. Because of this they should be called with a .
instead of :
vectors:worldToScreenSpace(vec(1, 2, 3))
vectors.worldToScreenSpace(vec(1, 2, 3))
Vector Creation
vec()
Creates and returns a vector of the appropriate size to hold the arguments passed in
For example; if you call vec(3, 4, 0, 2), then the function will return a Vector4 containing those values
There is a global alias "vec" for this function, meaning the "vectors." can be omitted
- Overload 1
- Overload 2
- Overload 3
Example:
vectors.vec(90, 90, 90)
vec2()
Creates and returns a Vector2 with the given values
Nil values become zero
vec2(x, y)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x | Number | - | - |
y | Number | - | - |
Returns:
Type | Description |
---|---|
Vector2 | - |
Example:
vectors.vec2(90, 90)
vec3()
Creates and returns a Vector3 with the given values
Nil values become zero
vec3(x, y, z)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x | Number | - | - |
y | Number | - | - |
z | Number | - | - |
Returns:
Type | Description |
---|---|
Vector3 | - |
Example:
vectors.vec3(90, 90, 90)
vec4()
Creates and returns a Vector4 with the given values
Nil values become zero
vec4(x, y, z, w)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x | Number | - | - |
y | Number | - | - |
z | Number | - | - |
w | Number | - | - |
Returns:
Type | Description |
---|---|
Vector4 | - |
Example:
vectors.vec4(90, 90, 90, 90)
Colors
hexToRGB()
Parses a Hex string color into an RGB format vector
The hex "#" is optional, and it can have any length, however only the first 6 hex digits are evaluated, short hex (length 3) is also supported
For example, "#42" is the same as "420000", and "F0B" is the same as "FF00BB"
hexToRGB(hex)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
hex | String | - | - |
Returns:
Type | Description |
---|---|
Vector3 | - |
Example:
vectors.hexToRGB("#5bbcf4")
vectors.hexToRGB("SOFT_BLUE")
hsvToRGB()
Converts the given color from HSV format to RGB format
- Overload 1
- Overload 2
Example:
vectors.hsvToRGB(181 / 360, 68 / 100, 66 / 100)
intToRGB()
Converts the given color from Integer format to RGB format
intToRGB(color)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
color | Integer | - | - |
Returns:
Type | Description |
---|---|
Vector3 | - |
Example:
vectors.intToRGB(838860750)
rgbToHSV()
Converts the given color from RGB format to HSV format
- Overload 1
- Overload 2
Example:
vectors.rgbToHSV(81 / 255, 68 / 255, 66 / 255)
rgbToHex()
Converts the given color from RGB format to Hex format
The "#" is not included on the return value
- Overload 1
- Overload 2
Example:
vectors.rgbToHex(81 / 255, 68 / 255, 66 / 255)
rgbToInt()
Converts the given color from RGB format to Integer format
- Overload 1
- Overload 2
Example:
vectors.rgbToInt(50 / 255, 50 / 255, 50 / 255)
Misc
angleToDir()
Converts a pitch/yaw angle (in degrees) into a direction vector
- Overload 1
- Overload 2
Example:
vectors.angleToDir(90, 70)
rotateAroundAxis()
Rotates a vector relative to a rotation vector
- Overload 1
- Overload 2
- Overload 3
- Overload 4
rotateAroundAxis(angle, vec, axis)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
angle | Number | - | - |
vec | Vector3 | - | - |
axis | Vector3 | - | - |
Returns:
Type | Description |
---|---|
Vector3 | - |
rotateAroundAxis(angle, x, y, z, axis)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
angle | Number | - | - |
x | Number | - | - |
y | Number | - | - |
z | Number | - | - |
axis | Vector3 | - | - |
Returns:
Type | Description |
---|---|
Vector3 | - |
Example:
vectors.rotateAroundAxis(180, vec(1, 2, 3), vec(0, 1, 0))
toCameraSpace()
Converts a position in the world into a position relative to the viewer's camera
- Overload 1
- Overload 2
Example:
vectors.toCameraSpace(vec(1, 2, 3))
worldToScreenSpace()
Converts a position in the world into a position relative to the viewer's screen
- Overload 1
- Overload 2
Example:
vectors.worldToScreenSpace(vec(1, 2, 3))