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
  • fromEuler
  • getAt
  • getRight
  • getUp
  • identity
  • inverse
  • lookRotation
  • new
  • round90
  • slerp

  • sm.quat.angleAxis(angle, axis)

    Creates a new quaternion from angle and axis.

    Parameters:

    TypeNameDescription
    numberangleThe rotation angle in radians.
    Vec3axisThe axis vector to rotate around.

    Returns:

    TypeDescription
    QuatThe quaternion for rotating angle radians around axis.

    sm.quat.fromEuler(euler)

    Create a new quaternion from an euler angle vector.

    Parameters:

    TypeNameDescription
    Vec3eulerThe euler angle vector.

    Returns:

    TypeDescription
    QuatThe quaternion.

    sm.quat.getAt(quaternion)

    Returns the quaternions at vector.

    Parameters:

    TypeNameDescription
    QuatquaternionThe quaternion.

    Returns:

    TypeDescription
    Vec3The at vector.

    sm.quat.getRight(quaternion)

    Returns the quaternions right vector.

    Parameters:

    TypeNameDescription
    QuatquaternionThe quaternion.

    Returns:

    TypeDescription
    Vec3The right vector.

    sm.quat.getUp(quaternion)

    Returns the quaternions up vector.

    Parameters:

    TypeNameDescription
    QuatquaternionThe quaternion.

    Returns:

    TypeDescription
    Vec3The up vector.

    sm.quat.identity()

    Creates a new identity quaternion.

    Returns:

    TypeDescription
    QuatThe created quaternion.

    sm.quat.inverse(quaternion)

    Inverts the quaternion.

    Parameters:

    TypeNameDescription
    QuatquaternionThe quaternion.

    Returns:

    TypeDescription
    QuatThe inverted quaternion.

    sm.quat.lookRotation(at, up)

    Create a new quaternion from direction vectors. DEPRECATED

    Parameters:

    TypeNameDescription
    Vec3atThe forward vector.
    Vec3upThe up vector.

    Returns:

    TypeDescription
    QuatThe quaternion.

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

    Creates a new quaternion.

    Parameters:

    TypeNameDescription
    numberxThe X value.
    numberyThe Y value.
    numberzThe Z value.
    numberwThe W value.

    Returns:

    TypeDescription
    QuatThe created quaternion.

    sm.quat.round90(quaternion)

    Rounds the quaternion rotation into 90 degree steps

    Parameters:

    TypeNameDescription
    QuatquaternionThe quaternion.

    Returns:

    TypeDescription
    QuatThe rounded quaternion.

    sm.quat.slerp(quaternion1, quaternion2, t)

    Performs a spherical linear interpolation between two quaternion.

    Parameters:

    TypeNameDescription
    Quatquaternion1The first quaternion.
    Quatquaternion2The second quaternion.
    numbertInterpolation amount between the two inputs.

    Returns:

    TypeDescription
    QuatThe interpolated quaternion.