sm.vec3.getRotation

Returns a quaternion representing the rotation from one vector to another.

Kind: Function

Environments: Game, Terrain

Game

sm.vec3.getRotation( v1, v2 )

Open the full Game reference

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:

Name Type Description
v1 Vec3 The first vector.
v2 Vec3 The second vector.

Returns:

Type Description
Quat The transformation.

Terrain

sm.vec3.getRotation( v1, v2 )

Open the full Terrain reference

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:

Name Type Description
v1 Vec3 The first vector.
v2 Vec3 The second vector.

Returns:

Type Description
Quat The transformation.