Defines commonly used math utility functions, constants and global vectors.
Game/Scripts/Utils/Math.lua
Game/Scripts/common.lua
The following globals should be used to avoid temporary Lua memory allocations:
Global Name | Description |
---|---|
g_Vectors.v000 | basic zero vector |
g_Vectors.v001 | positive z-axis direction vector |
g_Vectors.v010 | positive y-axis direction vector |
g_Vectors.v100 | positive x-axis direction vector |
g_Vectors.v101 | x and z-axis direction vector |
g_Vectors.v110 | x and y-axis direction vector |
g_Vectors.v111 | x, y and z-axis vector |
g_Vectors.up | positive z-axis direction vector |
g_Vectors.down | negative z-axis direction vector |
g_Vectors.temp | temporary zero vector |
g_Vectors.tempColor | temporary zero vector, commonly used for passing rgb color values |
g_Vectors.temp_v1 | temporary zero vector |
g_Vectors.temp_v2 | temporary zero vector |
g_Vectors.temp_v3 | temporary zero vector |
g_Vectors.temp_v4 | temporary zero vector |
g_Vectors.vecMathTemp1 | temporary zero vector |
g_Vectors.vecMathTemp2 | temporary zero vector |
Constant Name | Description |
---|---|
g_Rad2Deg | basic radian to degree conversion value |
g_Deg2Rad | basic degree to radian conversion value |
g_Pi | basic Pi constant based on math.pi |
g_2Pi | basic double Pi constant based on math.pi |
g_Pi2 | basic half Pi constant based on math.pi |
Returns true if all vector components of the given vector a are null.
Parameters | Description |
---|---|
a | vector to check if it's components are null |
Returns true if any vector components of the given vector a is not null.
Parameters | Description |
---|---|
a | vector to check if any of it's components are not null |
Returns the squared length of the given vector a.
Parameters | Description |
---|---|
a | vector to get the squared length from |
Returns the length of the given vector a.
Parameters | Description |
---|---|
a | vector to get the length from |
Returns the squared distance between vector a and vector b.
Parameters | Description |
---|---|
a | vector a |
b | vector b |
Returns the squared distance between vector a and vector b in 2D space (without z-component).
Parameters | Description |
---|---|
a | vector a |
b | vector b |
Returns the distance between vector a and vector b.
Parameters | Description |
---|---|
a | vector a |
b | vector b |
Returns the dot product between vector a and vector b.
Parameters | Description |
---|---|
a | vector a |
b | vector b |
Returns the dot product between vector a and vector b in 2D space (without z-component).
Parameters | Description |
---|---|
a | vector a |
b | vector b |
Logs a given vector to console.
Parameters | Description |
---|---|
name | description name of the vector |
v | vector v |
LogVec("Local Actor Position", g_localActor:GetPos())
Console output:
<Lua> Local Actor Position = (1104.018066 1983.247925 112.769440)
Sets all vector components of the given vector dest to zero.
Parameters | Description |
---|---|
dest | vector dest |
Copies the components of the vector src to the vector dest.
Parameters | Description |
---|---|
dest | destination vector |
src | source vector |
Adds up the components of vector a and vector b.
Parameters | Description |
---|---|
a | vector a |
b | vector b |
Negates all components of the given vector a.
Parameters | Description |
---|---|
a | vector a |
Copies the componentwise subtraction of vector b and vector a to vector dest.
Parameters | Description |
---|---|
dest | destination vector |
a | vector a |
b | vector b |
Copies the componentwise addition of vector b and vector a to vector dest.
Parameters | Description |
---|---|
dest | destination vector |
a | vector a |
b | vector b |
Returns the difference between vector a and vector b.
Parameters | Description |
---|---|
a | vector a |
b | vector b |
Copies the componentwise difference between vector a and vector b to vector dest.
Parameters | Description |
---|---|
dest | destination vector |
a | vector a |
b | vector b |
Returns the product of vector a and vector b.
Parameters | Description |
---|---|
a | vector a |
b | vector b |
Copies the product of vector a and vector b to vector dest.
Parameters | Description |
---|---|
dest | destination vector |
a | vector a |
b | vector b |
Scales the given vector a by the factor of b.
Parameters | Description |
---|---|
a | vector a |
b | scalar b |
Returns a new vector based on a copy of the scaled vector a by the factor b.
Parameters | Description |
---|---|
a | vector a |
b | scalar b |
Copies the scaled vector a by the factor of b to vector dest.
Parameters | Description |
---|---|
dest | destination vector |
a | vector a |
b | scalar b |
Returns the normalized vector a.
Parameters | Description |
---|---|
a | vector a |
Rotates vector v by 90 degree around the z-axis.
Parameters | Description |
---|---|
v | vector v |
Rotates vector v by -90 degree around the z-axis.
Parameters | Description |
---|---|
v | vector v |
Copies the result of the cross product between vector p and vector q to vector dest.
Parameters | Description |
---|---|
dest | destination vector |
p | vector p |
q | vector q |
Copies the result of the vector rotation of vector p around vector r by the given angle to vector dest.
Parameters | Description |
---|---|
dest | destination vector |
p | vector p |
r | vector r |
angle | rotation angle |
Copies the result of the vector projection of vector P to the surface with the given normal N to vector dest.
Parameters | Description |
---|---|
dest | destination vector |
P | vector pP |
N | surface normal |
Returns the distance between the point a and the line between p and q.
Parameters | Description |
---|---|
a | vector a |
p | vector p |
q | vector q |
Linear interpolation between color/vector a and color/vector b with the factor of k.
Parameters | Description |
---|---|
a | color/vector a |
b | color/vector b |
k | factor k |
Linear interpolation between scalar a and scalar b with the factor of k.
Parameters | Description |
---|---|
a | scalar a |
b | scalar b |
k | factor k |
Returns the maximum of a and b.
Parameters | Description |
---|---|
a | scalar a |
b | scalar b |
Returns the minimum of a and b.
Parameters | Description |
---|---|
a | scalar a |
b | scalar b |
Clamps the number _n between _min and _max.
Parameters | Description |
---|---|
_n | number to clamp |
_min | lower limit to clamp |
_max | upper limit to clamp |
Interpolates the given number actual to the given goal by the given speed.
Parameters | Description |
---|---|
actual | number actual |
goal | number goal |
speed | interpolation speed |
Returns the sign of a given number (0 returns 0).
Parameters | Description |
---|---|
a | number a |
Returns the sign of a given number (0 returns 1).
Parameters | Description |
---|---|
a | number a |
Returns the square of a given number.
Parameters | Description |
---|---|
a | number a |
Returns a random float between a and b.
Parameters | Description |
---|---|
a | number a |
b | number b |
Returns a if c is not nil, otherwise it returns b.
Parameters | Description |
---|---|
c | condition value c |
a | value a |
b | value b |