Skip to main content

Vectors

A global API which provides functions dedicated to creating and otherwise manipulating vectors

warning

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

info

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

vec(x, y)

Parameters:

NameTypeDescriptionDefault
xNumber--
yNumber--

Returns:

TypeDescription
Vector2-

Example:

vectors.vec(90, 90, 90)

vec2()

Creates and returns a Vector2 with the given values

Nil values become zero

vec2(x, y)

Parameters:

NameTypeDescriptionDefault
xNumber--
yNumber--

Returns:

TypeDescription
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:

NameTypeDescriptionDefault
xNumber--
yNumber--
zNumber--

Returns:

TypeDescription
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:

NameTypeDescriptionDefault
xNumber--
yNumber--
zNumber--
wNumber--

Returns:

TypeDescription
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:

NameTypeDescriptionDefault
hexString--

Returns:

TypeDescription
Vector3-

Example:

vectors.hexToRGB("#5bbcf4")
vectors.hexToRGB("SOFT_BLUE")

hsvToRGB()

Converts the given color from HSV format to RGB format

hsvToRGB(hsv)

Parameters:

NameTypeDescriptionDefault
hsvVector3--

Returns:

TypeDescription
Vector3-

Example:

vectors.hsvToRGB(181 / 360, 68 / 100, 66 / 100)

intToRGB()

Converts the given color from Integer format to RGB format

intToRGB(color)

Parameters:

NameTypeDescriptionDefault
colorInteger--

Returns:

TypeDescription
Vector3-

Example:

vectors.intToRGB(838860750)

rgbToHSV()

Converts the given color from RGB format to HSV format

rgbToHSV(rgb)

Parameters:

NameTypeDescriptionDefault
rgbVector3--

Returns:

TypeDescription
Vector3-

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

rgbToHex(rgb)

Parameters:

NameTypeDescriptionDefault
rgbVector3--

Returns:

TypeDescription
String-

Example:

vectors.rgbToHex(81 / 255, 68 / 255, 66 / 255)

rgbToInt()

Converts the given color from RGB format to Integer format

rgbToInt(rgb)

Parameters:

NameTypeDescriptionDefault
rgbVector3--

Returns:

TypeDescription
Integer-

Example:

vectors.rgbToInt(50 / 255, 50 / 255, 50 / 255)

Misc

angleToDir()

Converts a pitch/yaw angle (in degrees) into a direction vector

angleToDir(vec)

Parameters:

NameTypeDescriptionDefault
vecVector2--

Returns:

TypeDescription
Vector3-

Example:

vectors.angleToDir(90, 70)

rotateAroundAxis()

Rotates a vector relative to a rotation vector

rotateAroundAxis(angle, vec, axis)

Parameters:

NameTypeDescriptionDefault
angleNumber--
vecVector3--
axisVector3--

Returns:

TypeDescription
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

toCameraSpace(vec)

Parameters:

NameTypeDescriptionDefault
vecVector3--

Returns:

TypeDescription
Vector3-

Example:

vectors.toCameraSpace(vec(1, 2, 3))

worldToScreenSpace()

Converts a position in the world into a position relative to the viewer's screen

worldToScreenSpace(vec)

Parameters:

NameTypeDescriptionDefault
vecVector3--

Returns:

TypeDescription
Vector4-

Example:

vectors.worldToScreenSpace(vec(1, 2, 3))