Skip to main content

Quat

Associated namespace: sm.quat

A userdata object representing a quaternion.

Member Values

x

Quat.x (number): The X component value.

y

Quat.y (number): The Y component value.

z

Quat.z (number): The Z component value.

w

Quat.w (number): The W component value.

Operators

OperatorDescription
Quat * QuatReturns the Hamilton product of two quaternions.
Quat * Vec3Applies rotation to a vector.
Quat == QuatChecks if two quaternions are equal.
note

This information might be useful when multiplying a quaternion with another.

The wikipedia page linked above uses the w, xi, yj, zk representation, while the game uses xi, yj, zk, w.

Quat1 * Quat2 is equal to:

sm.quat.new(
Quat1.w * Quat2.x + Quat1.x * Quat2.w + Quat1.y * Quat2.z - Quat1.z * Quat2.y,
Quat1.w * Quat2.y - Quat1.x * Quat2.z + Quat1.y * Quat2.w + Quat1.z * Quat2.x,
Quat1.w * Quat2.z + Quat1.x * Quat2.y - Quat1.y * Quat2.x + Quat1.z * Quat2.w,
Quat1.w * Quat2.w - Quat1.x * Quat2.x - Quat1.y * Quat2.y - Quat1.z * Quat2.z
)

Also, (Quat1 * Quat2) * Vec3 is equal to Quat1 * (Quat2 * Vec3)