magic-pixels
    Preparing search index...

    Class Quaternion

    A rotation as a unit quaternion (x, y, z, w): the rotation by angle around a unit axis is (axis * sin(angle / 2), cos(angle / 2)).

    Multiplying two quaternions composes their rotations in the same order as matrices (a.multiply(b) applies b first), and slerp interpolates between two rotations along the shortest arc. Operations work in place and return this; use clone() first if the original is still needed.

    The methods that produce a rotation (setFromAxisAngle, setFromEuler, setFromRotationMatrix, slerp) return a unit quaternion for unit inputs. After many multiply calls, normalize() removes accumulated rounding error.

    Index
    • Parameters

      • x: number = 0

        vector part, X

      • y: number = 0

        vector part, Y

      • z: number = 0

        vector part, Z

      • w: number = 1

        scalar part; the identity rotation is (0, 0, 0, 1)

      Returns Quaternion

    w: number = 1

    scalar part; the identity rotation is (0, 0, 0, 1)

    x: number = 0

    vector part, X

    y: number = 0

    vector part, Y

    z: number = 0

    vector part, Z

    • Replace by the inverse rotation. For a unit quaternion that is the conjugate (-x, -y, -z, w); a non-unit quaternion is also divided by its squared length.

      Returns this

    • Scale to unit length. The zero quaternion becomes the identity.

      Returns this

    • Parameters

      • x: number
      • y: number
      • z: number
      • w: number

      Returns this

    • Set to the rotation by angle radians around axis.

      Parameters

      • axis: Vector

        a unit vector

      • angle: number

        in radians, counter-clockwise when looking down the axis

      Returns this

    • Set from Euler angles in radians, applied in XYZ order: the same rotation as Mat4.compose(position, rotation, scale) builds.

      Parameters

      Returns this

    • Set from the rotation part of a matrix. The matrix must be a pure rotation (orthonormal axes, no scaling); a Mat4 may carry a translation, which is ignored.

      Parameters

      Returns this

    • Spherical linear interpolation: move this rotation towards other along the shortest arc, at constant angular speed.

      Parameters

      • other: Quaternion

        the rotation at t = 1

      • t: number

        interpolation factor from 0 (this) to 1 (other)

      Returns this

    • Write the equivalent Euler angles in radians, XYZ order, into target. Angles are in the range -π..π (y in -π/2..π/2), so a rotation that was set from Euler angles outside that range comes back wrapped.

      Parameters

      Returns Vector

      target

    • Parameters

      • values: ArrayLike<number>

        [x, y, z, w], as stored in a glTF node

      • offset: number = 0

        index of x in values

      Returns Quaternion