sm.vec3
A vector is used to represent position and direction in 3D space, using X, Y and Z coordinates.
To create one, use sm.vec3.new.
Functions
bezier2
sm.vec3.bezier2( c0, c1, c2, t )
Quadratic Bezier interpolation. Three dimensional bezier curve.
Parameters:
| Name | Type | Description |
|---|---|---|
c0 |
Vec3 | The start point. |
c1 |
Vec3 | The control point. |
c2 |
Vec3 | The end point. |
t |
number | The interpolation step. |
Returns:
| Type | Description |
|---|---|
| Vec3 | The interpolated value between two values. |
bezier3
sm.vec3.bezier3( c0, c1, c2, c3, t )
Cubic Bezier interpolation. Three dimensional bezier curve.
Parameters:
| Name | Type | Description |
|---|---|---|
c0 |
number | The start point. |
c1 |
number | The first control point. |
c2 |
number | The second control point. |
c3 |
number | The end point. |
t |
number | The interpolation step. |
Returns:
| Type | Description |
|---|---|
| number | The interpolated value between two values. |
closestAxis
sm.vec3.closestAxis( vector )
Finds the closest axis-aligned vector from the given vector
Parameters:
| Name | Type | Description |
|---|---|---|
vector |
Vec3 | The vector. |
Returns:
| Type | Description |
|---|---|
| Vec3 | The axis-aligned vector. |
fuzzyEquals
sm.vec3.fuzzyEquals( v1, v2 )
Compare vectors with threshold FLT_EPSILON.
Parameters:
Returns:
| Type | Description |
|---|---|
| boolean | The result of the comparison. |
getDistance
sm.vec3.getDistance( vector, vector )
Get the distance between 2 vectors
Parameters:
Returns:
| Name | Type | Description |
|---|---|---|
distance |
number | The distance between the vectors |
getDistanceSquared
sm.vec3.getDistanceSquared( vector, vector )
Get the distance between 2 vectors
Parameters:
Returns:
| Name | Type | Description |
|---|---|---|
distance |
number | The squared distance between the vectors |
getRotation
sm.vec3.getRotation( v1, v2 )
Returns a quaternion representing the rotation from one vector to another.
The quaternion can then be multiplied with any vector to rotate it in the same fashion.
v1 = sm.vec3.new(1,0,0)
v2 = sm.vec3.new(0,1,0)
trans = sm.vec3.getRotation(v1, v2)
-- `trans` now rotates a vector 90 degrees
print(trans * v2)
-- {<Vec3>, x = -1, y = 0, z = 0}
Parameters:
Returns:
| Type | Description |
|---|---|
| Quat | The transformation. |
lerp
sm.vec3.lerp( v1, v2, t )
Performs a linear interpolation between two vectors.
Parameters:
| Name | Type | Description |
|---|---|---|
v1 |
Vec3 | The first vector. |
v2 |
Vec3 | The second vector. |
t |
number | Interpolation amount between the two inputs. |
Returns:
| Type | Description |
|---|---|
| Vec3 | Interpolated vector. |
new - Vec3
sm.vec3.new( vector )
Creates a new vector from an existing one.
Parameters:
| Name | Type | Description |
|---|---|---|
vector |
Vec3 | The original vector. |
Returns:
| Type | Description |
|---|---|
| Vec3 | The created vector. |
new - number
sm.vec3.new( x, y, z )
Creates a new vector.
Parameters:
| Name | Type | Description |
|---|---|---|
x |
number | The X value. |
y |
number | The Y value. |
z |
number | The Z value. |
Returns:
| Type | Description |
|---|---|
| Vec3 | The created vector. |
one
sm.vec3.one( )
Creates a new vector with 1 in x, y, x.
Returns:
| Type | Description |
|---|---|
| Vec3 | The one vector. |
zero
sm.vec3.zero( )
Creates a new vector with 0 in x, y, x.
Returns:
| Type | Description |
|---|---|
| Vec3 | The zero vector. |