Small World Engine API Reference - v0.76.20
    Preparing search index...

    Class Quaternion

    A class representing a quaternion for rotations.

    Index
    • Creates a new Quaternion.

      Parameters

      • x: number = 0

        The x component. Defaults to 0.

      • y: number = 0

        The y component. Defaults to 0.

      • z: number = 0

        The z component. Defaults to 0.

      • w: number = 1

        The w component. Defaults to 1.

      Returns Quaternion

    w: number

    The w component.

    x: number

    The x component.

    y: number

    The y component.

    z: number

    The z component.

    • Resets the quaternion to the identity rotation.

      Returns this

      this

    • Calculates the Euclidean length of the quaternion.

      Returns number

      The length.

    • Normalizes the quaternion to a unit length of 1.

      Returns this

      this

    • Sets the components of the quaternion.

      Parameters

      • x: number

        The x component.

      • y: number

        The y component.

      • z: number

        The z component.

      • w: number

        The w component.

      Returns this

      this

    • Sets the quaternion from axis and angle.

      Parameters

      • axis: Vector3D

        The rotation axis (must be normalized).

      • angle: number

        The rotation angle in radians.

      Returns this

      this

    • Spherically interpolates this quaternion toward another by a factor t, taking the shortest arc (flips q if the two quaternions are more than 90 degrees apart). Falls back to linear interpolation + normalize when the two rotations are nearly identical, where slerp's formula becomes numerically unstable (division by a near-zero sinHalfTheta).

      Parameters

      • q: Quaternion

        The target quaternion.

      • t: number

        The interpolation factor, typically in [0, 1] (0 = stays at this, 1 = becomes q).

      Returns this

      this