Skip to main content

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

sm.vec3.bezier2( c0, c1, c2, t )

Quadratic Bezier interpolation. Three dimensional bezier curve.

Arguments:
  • c0 [ Vec3 ]: The start point.
  • c1 [ Vec3 ]: The control point.
  • c2 [ Vec3 ]: The end point.
  • t [ number ]: The interpolation step.
Returns:
  • [ Vec3 ]: The interpolated vector.

bezier3

sm.vec3.bezier3( c0, c1, c2, c3, t )

Cubic Bezier interpolation. Three dimensional bezier curve.

Arguments:
  • c0 [ Vec3 ]: The start point.
  • c1 [ Vec3 ]: The first control point.
  • c2 [ Vec3 ]: The second control point.
  • c3 [ Vec3 ]: The end point.
  • t [ number ]: The interpolation step.
Returns:
  • [ Vec3 ]: The interpolated vector.

closestAxis

sm.vec3.closestAxis( vec )

Finds the closest axis-aligned vector from the given vector.

Arguments:
Returns:
  • [ Vec3 ]: The axis-aligned vector.

getRotation

sm.vec3.getRotation( vec1, vec2 )

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.

Arguments:
  • vec1 [ Vec3 ]: The first vector.
  • vec2 [ Vec3 ]: The second vector.
Returns:
  • [ Quat ]: The transformation.
Example
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 }

lerp

sm.vec3.lerp( vec1, vec2, t )

Performs a linear interpolation between two vectors.

Arguments:
  • vec1 [ Vec3 ]: The first vector.
  • vec2 [ Vec3 ]: The second vector.
  • t [ number ]: The interpolation amount between the two inputs.
Returns:
  • [ Vec3 ]: The interpolated vector.

new

sm.vec3.new( x, y, z )

Creates a new vector.

Arguments:
  • x [ number ]: The X value.
  • y [ number ]: The Y value.
  • z [ number ]: The Z value.
Returns:
  • [ Vec3 ]: The created vector.

one

sm.vec3.one()

Creates a new vector with 1 in X, Y and Z.

Returns:
  • [ Vec3 ]: The created vector.

zero

sm.vec3.zero()

Creates a new vector with 0 in X, Y and Z.

Returns:
  • [ Vec3 ]: The created vector.