PokéRogue
    Preparing search index...

    A quaternion representing a rotation in 3D space. Quaternions avoid gimbal lock and provide smooth interpolation between orientations. The quaternion is stored as four components (x, y, z, w). Use the identity method to reset to the identity quaternion (0, 0, 0, 1), which represents no rotation. Commonly used with Matrix4 for 3D transformations in WebGL rendering.

    Index
    • Parameters

      • Optionalx: number

        The x component. Default 0.

      • Optionaly: number

        The y component. Default 0.

      • Optionalz: number

        The z component. Default 0.

      • Optionalw: number

        The w component. Default 1.

      Returns Quaternion

    onChangeCallback: Function

    This callback is invoked, if set, each time a value in this quaternion is changed. The callback is passed one argument, a reference to this quaternion.

    w: number

    The w component of this Quaternion.

    x: number

    The x component of this Quaternion.

    y: number

    The y component of this Quaternion.

    z: number

    The z component of this Quaternion.

    • Add a given Quaternion or Vector to this Quaternion. Addition is component-wise.

      Parameters

      Returns Quaternion

      This Quaternion.

    • Calculates and sets the w component of this Quaternion based on the current x, y, and z components, so that the Quaternion has unit length. Assumes the x, y, and z values are already known and that their combined squared length does not exceed 1.undefined

      Returns Quaternion

      This Quaternion.

    • Converts this Quaternion to its conjugate by negating the x, y, and z components while leaving w unchanged. For a unit quaternion, the conjugate is equivalent to the inverse and represents the opposite rotation.undefined

      Returns Quaternion

      This Quaternion.

    • Copy the components of a given Quaternion or Vector into this Quaternion.

      Parameters

      Returns Quaternion

      This Quaternion.

    • Calculate the dot product of this Quaternion and the given Quaternion or Vector.

      Parameters

      • v: Vector4 | Quaternion

        The Quaternion or Vector to dot product with this Quaternion.

      Returns number

      The dot product of this Quaternion and the given Quaternion or Vector.

    • Sets this Quaternion from the rotation represented by the given Matrix3, using the algorithm from Ken Shoemake's 1987 SIGGRAPH article "Quaternion Calculus and Fast Animation".

      Parameters

      • mat: Matrix3

        The Matrix3 to convert from.

      Returns Quaternion

      This Quaternion.

    • Resets this Quaternion to the identity quaternion (0, 0, 0, 1), which represents no rotation.undefined

      Returns Quaternion

      This Quaternion.

    • Calculates the multiplicative inverse of this Quaternion and sets the result. The inverse undoes the rotation represented by this Quaternion. If the Quaternion has zero length, no change is made.undefined

      Returns Quaternion

      This Quaternion.

    • Calculate the length of this Quaternion.undefined

      Returns number

      The length of this Quaternion.

    • Calculate the length of this Quaternion squared.undefined

      Returns number

      The length of this Quaternion, squared.

    • Linearly interpolate this Quaternion towards the given Quaternion or Vector.

      Parameters

      • v: Vector4 | Quaternion

        The Quaternion or Vector to interpolate towards.

      • Optionalt: number

        The percentage of interpolation. Default 0.

      Returns Quaternion

      This Quaternion.

    • Multiply this Quaternion by the given Quaternion or Vector.

      Parameters

      Returns Quaternion

      This Quaternion.

    • Normalizes this Quaternion, scaling it to unit length. If the Quaternion has zero length, no change is made.undefined

      Returns Quaternion

      This Quaternion.

    • Rotate this Quaternion on the X axis.

      Parameters

      • rad: number

        The rotation angle in radians.

      Returns Quaternion

      This Quaternion.

    • Rotate this Quaternion on the Y axis.

      Parameters

      • rad: number

        The rotation angle in radians.

      Returns Quaternion

      This Quaternion.

    • Rotate this Quaternion on the Z axis.

      Parameters

      • rad: number

        The rotation angle in radians.

      Returns Quaternion

      This Quaternion.

    • Sets this Quaternion to represent the shortest arc rotation from unit vector a to unit vector b. This is the minimum rotation needed to align a with b. Both vectors must be normalized before calling this method.

      Parameters

      • a: Vector3

        The starting unit vector.

      • b: Vector3

        The target unit vector.

      Returns Quaternion

      This Quaternion.

    • Scale this Quaternion by the given value.

      Parameters

      • scale: number

        The value to scale this Quaternion by.

      Returns Quaternion

      This Quaternion.

    • Set the components of this Quaternion and optionally call the onChangeCallback.

      Parameters

      • Optionalx: number | object

        The x component, or an object containing x, y, z, and w components. Default 0.

      • Optionaly: number

        The y component. Default 0.

      • Optionalz: number

        The z component. Default 0.

      • Optionalw: number

        The w component. Default 0.

      • Optionalupdate: boolean

        Call the onChangeCallback? Default true.

      Returns Quaternion

      This Quaternion.

    • Sets this Quaternion from the given view, right, and up axis vectors. The three vectors are written into a temporary Matrix3, which is then converted to a normalized quaternion. All three vectors should be mutually orthogonal unit vectors.

      Parameters

      Returns Quaternion

      This Quaternion.

    • Sets this Quaternion to represent a rotation of rad radians around the given normalized axis vector.

      Parameters

      • axis: Vector3

        The normalized axis vector around which to rotate.

      • rad: number

        The rotation angle in radians.

      Returns Quaternion

      This Quaternion.

    • Sets this Quaternion from the given Euler object. The conversion respects the Euler's rotation order (e.g., 'XYZ', 'YXZ', 'ZXY', 'ZYX', 'YZX', 'XZY'), producing the equivalent quaternion rotation.

      Parameters

      • euler: Euler

        The Euler object to convert from.

      • Optionalupdate: boolean

        Run the onChangeCallback? Default true.

      Returns Quaternion

      This Quaternion.

    • Sets the rotation of this Quaternion from the given Matrix4.

      Parameters

      • mat4: Matrix4

        The Matrix4 to set the rotation from.

      Returns Quaternion

      This Quaternion.

    • Performs a spherical linear interpolation (slerp) between this Quaternion and the given Quaternion or Vector. Unlike lerp, slerp interpolates along the shortest arc on the unit sphere, maintaining constant angular velocity and producing smooth, natural-looking rotations.

      Parameters

      • b: Vector4 | Quaternion

        The Quaternion or Vector to interpolate towards.

      • t: number

        The interpolation factor, typically in the range [0, 1].

      Returns Quaternion

      This Quaternion.

    • Subtract a given Quaternion or Vector from this Quaternion. Subtraction is component-wise.

      Parameters

      Returns Quaternion

      This Quaternion.