sm.vec3
Associated object type: 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 bezier3 closestAxis getRotation lerp new one zero
sm.vec3.bezier2(c0, c1, c2, t)
Quadratic Bezier interpolation. Three dimensional bezier curve.
Parameters:
Type | Name | Description |
Vec3 | c0 | The start point. |
Vec3 | c1 | The control point. |
Vec3 | c2 | The end point. |
number | t | The interpolation step. |
Returns:
Type | Description |
Vec3 | The interpolated value between two values. |
sm.vec3.bezier3(c0, c1, c2, c3, t)
Cubic Bezier interpolation. Three dimensional bezier curve.
Parameters:
Type | Name | Description |
number | c0 | The start point. |
number | c1 | The first control point. |
number | c2 | The second control point. |
number | c3 | The end point. |
number | t | The interpolation step. |
Returns:
Type | Description |
number | The interpolated value between two values. |
sm.vec3.closestAxis(vector)
Finds the closest axis-aligned vector from the given vector
Parameters:
Type | Name | Description |
Vec3 | vector | The vector. |
Returns:
Type | Description |
Vec3 | The axis-aligned vector. |
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)
-- {, x = -1, y = 0, z = 0}
Parameters:
Type | Name | Description |
Vec3 | v1 | The first vector. |
Vec3 | v2 | The second vector. |
Returns:
Type | Description |
Quat | The transformation. |
sm.vec3.lerp(v1, v2, t)
Performs a linear interpolation between two vectors.
Parameters:
Type | Name | Description |
Vec3 | v1 | The first vector. |
Vec3 | v2 | The second vector. |
number | t | Interpolation amount between the two inputs. |
Returns:
Type | Description |
Vec3 | Interpolated vector. |
sm.vec3.new(x, y, z)
Creates a new vector.
Parameters:
Type | Name | Description |
number | x | The X value. |
number | y | The Y value. |
number | z | The Z value. |
Returns:
Type | Description |
Vec3 | The created vector. |
sm.vec3.one()
Creates a new vector with 1 in x, y, x.
Returns:
Type | Description |
Vec3 | The one vector. |
sm.vec3.zero()
Creates a new vector with 0 in x, y, x.
Returns:
Type | Description |
Vec3 | The zero vector. |