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

local quat = sm.quat.angleAxis(angle, axis)

Creates a new quaternion from an angle and an axis.

note

The angle is counterclockwise.

Parameters:

  • angle (number): The angle, in radians.
  • axis (Vec3): The axis to rotate around.

Returns:

  • quat (Quat): The rotation quaternion.

fromEuler

local quat = sm.quat.fromEuler(euler)

Creates a new quaternion from euler angles.

Parameters:

  • euler (Vec3): The euler angles vector.

Returns:

  • quat (Quat): The rotation quaternion.

getAt

local at = sm.quat.getAt(quat)

Returns the quaternion's at (forward) vector.

This is equal to doing quat * sm.vec3.new(0, 0, 1).

note

Due to a bug in the API, the output of getAt and getUp are switched!

Parameters:

  • quat (Quat): The quaternion.

Returns:

  • at (Vec3): The at (forward) vector.

getRight

local right = sm.quat.getRight(quat)

Returns the quaternion's right vector.

This is equal to doing quat * sm.vec3.new(1, 0, 0).

Parameters:

  • quat (Quat): The quaternion.

Returns:

  • right (Vec3): The right vector.

getUp

local up = sm.quat.getUp(quat)

Returns the quaternion's up vector.

This is equal to doing quat * sm.vec3.new(0, 1, 0).

note

Due to a bug in the API, the output of getUp and getAt are switched!

Parameters:

  • quat (Quat): The quaternion.

Returns:

  • up (Vec3): The up vector.

getW

local w = sm.quat.getW(quat)

Returns the W component of the given quaternion.
This does the same as accessing Quat.w, but can have better performance in certain cases.

Parameters:

  • quat (Quat): The quaternion.

Returns:

  • w (number): The W component value.

getX

local x = sm.quat.getX(quat)

Returns the X component of the given quaternion.
This does the same as accessing Quat.x, but can have better performance in certain cases.

Parameters:

  • quat (Quat): The quaternion.

Returns:

  • x (number): The X component value.

getY

local y = sm.quat.getY(quat)

Returns the Y component of the given quaternion.
This does the same as accessing Quat.y, but can have better performance in certain cases.

Parameters:

  • quat (Quat): The quaternion.

Returns:

  • y (number): The Y component value.

getZ

local z = sm.quat.getZ(quat)

Returns the Z component of the given quaternion.
This does the same as accessing Quat.z, but can have better performance in certain cases.

Parameters:

  • quat (Quat): The quaternion.

Returns:

  • z (number): The Z component value.

identity

local identity = sm.quat.identity()

Creates a new identity quaternion.

Returns:

  • identity (Quat): The identity quaternion.

inverse

local inverse = sm.quat.inverse(quat)

Inverts the quaternion.

Parameters:

  • quat (Quat): The quaternion.

Returns:

  • inverse (Quat): The inverted quaternion.

lookRotation

local quat = sm.quat.lookRotation(at, up)
warning

This function is deprecated.

Creates a new quaternion from direction vectors.

Parameters:

  • at (Vec3): The at (forward) direction.
  • up (Vec3): The up direction.

Returns:

  • quat (Quat): The rotation quaternion.

new

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

Creates a new quaternion.

Parameters:

  • x (number): The X value.
  • y (number): The Y value.
  • z (number): The Z value.
  • w (number): The W value.

Returns:

  • quat (Quat): The rotation quaternion.

round90

local rounded = sm.quat.round90(quat)

Rounds the quaternion rotation into 90 degree steps.

Parameters:

  • quat (Quat): The quaternion.

Returns:

  • rounded (Quat): The rounded quaternion.

slerp

local interpolated = sm.quat.slerp(from, to, t)

Performs a Spherical Linear Interpolation between two quaternions.

Parameters:

  • from (Quat): The quaternion to interpolate from.
  • to (Quat): The quaternion to interpolate to.
  • t (number): The interpolation fraction.

Returns:

  • interpolated (Quat): The interpolated quaternion.

setW

sm.quat.setW(quat, w)

Sets the W component of the given quaternion.
This does the same as setting Quat.w, but can have better performance in certain cases.

Parameters:

  • quat (Quat): The quaternion.
  • w (number): The W component value.

setX

sm.quat.setX(quat, x)

Sets the X component of the given quaternion.
This does the same as setting Quat.x, but can have better performance in certain cases.

Parameters:

  • quat (Quat): The quaternion.
  • x (number): The X component value.

setY

sm.quat.setY(quat, y)

Sets the Y component of the given quaternion.
This does the same as setting Quat.y, but can have better performance in certain cases.

Parameters:

  • quat (Quat): The quaternion.
  • y (number): The Y component value.

setZ

sm.quat.setZ(quat, z)

Sets the Z component of the given quaternion.
This does the same as setting Quat.z, but can have better performance in certain cases.

Parameters:

  • quat (Quat): The quaternion.
  • z (number): The Z component value.