Skip to main content

sm.quat

Associated object type: Quat

A quaternion is used to represent rotation as a generalization of complex numbers.

To create one, use sm.quat.new.

warning

It is uncommon to modify individual X, Y, Z, W components directly.
To create a new quaternion, consider using sm.vec3.getRotation.

Functions

angleAxis

sm.quat.angleAxis( angle, axis )

Creates a new quaternion from angle and axis.

note

The angle is counterclockwise.

Arguments:
  • angle [ number ]: The rotation angle in radians.
  • axis [ Vec3 ]: The axis vector to rotate around.
Returns:
  • [ Quat ]: The quaternion for rotating angle radians around an axis.

fromEuler

sm.quat.fromEuler( euler )

Create a new quaternion from an euler angle vector.

Arguments:
  • euler [ Vec3 ]: The euler angle vector.
Returns:

getAt

sm.quat.getAt( quat )

Returns the quaternion's at vector.

This does the same as doing quat * sm.vec3.new( 0, 0, 1 ).

Arguments:
  • quat [ Quat ]: The quaternion.
Returns:

getRight

sm.quat.getRight( quat )

Returns the quaternion's right vector.

This does the same as doing quat * sm.vec3.new( 1, 0, 0 ).

Arguments:
  • quat [ Quat ]: The quaternion.
Returns:

getUp

sm.quat.getUp( quat )

Returns the quaternion's up vector.

This does the same as doing quat * sm.vec3.new( 0, 1, 0 ).

Arguments:
  • quat [ Quat ]: The quaternion.
Returns:

identity

sm.quat.identity()

Creates a new identity quaternion.

Returns:
  • [ Quat ]: The created quaternion.

inverse

sm.quat.inverse( quat )

Inverts the quaternion.

Arguments:
  • quat [ Quat ]: The quaternion.
Returns:
  • [ Quat ]: The inverted quaternion.

lookRotation

sm.quat.lookRotation( at, up )
warning

This function is deprecated.

Creates a new quaternion from direction vectors.

Arguments:
  • at [ Vec3 ]: The forward vector.
  • up [ Vec3 ]: The up vector.
Returns:

new

sm.quat.new( x, y, z, w )

Creates a new quaternion.

Arguments:
  • x [ number ]: The X value.
  • y [ number ]: The Y value.
  • z [ number ]: The Z value.
  • w [ number ]: The W value.
Returns:
  • [ Quat ]: The created quaternion.

round90

sm.quat.round90( quat )

Rounds the quaternion rotation into 90 degree steps.

Arguments:
  • quat [ Quat ]: The quaternion.
Returns:
  • [ Quat ]: The rounded quaternion.

slerp

sm.quat.slerp( quat1, quat2, t )

Performs a spherical linear interpolation between two quaternion.

Arguments:
  • quat1 [ Quat ]: The first quaternion.
  • quat2 [ Quat ]: The second quaternion.
  • t [ number ]: The Interpolation amount between the two inputs.
Returns:
  • [ Quat ]: The interpolated quaternion.