RSX Code Reference
    Preparing search index...
    • rsx
    • Quaternion

    Class Quaternion

    The Quaternion is used to represent orientations and rotations. The class follows the 'copy-on-write' pattern, which means that every operation returns a copy of the quaternion with updated values. It also implies that the values of the quaternion cannot be directly modified.

    The concept of immutability improves sharing of objects as all types in TypeScript are assigned by identity, instead of by-value (e.g. a copy) as in other programming languages like C.

    Index
    • Parameters

      • Optionalx: number
      • Optionaly: number
      • Optionalz: number
      • Optionalw: number

      Returns Quaternion

    _w: number
    _x: number
    _y: number
    _z: number

    Quaternion representing no rotation.

    Quaternion with all zero elements.

    • get backward(): Vector3

      Gets the negative z-axis of the coordinate system transformed by this quaternion.

      Returns Vector3

    • get down(): Vector3

      Gets the negative z-axis of the coordinate system transformed by this quaternion.

      Returns Vector3

    • get forward(): Vector3

      Gets the positive z-axis of the coordinate system transformed by this quaternion.

      Returns Vector3

    • get left(): Vector3

      Gets the positive x-axis of the coordinate system transformed by this quaternion.

      Returns Vector3

    • get right(): Vector3

      Gets the negative x-axis of the coordinate system transformed by this quaternion.

      Returns Vector3

    • get up(): Vector3

      Gets the positive y-axis of the coordinate system transformed by this quaternion.

      Returns Vector3

    • get w(): number

      Returns number

    • set w(value: number): void

      Parameters

      • value: number

      Returns void

    • get x(): number

      Returns number

    • set x(value: number): void

      Parameters

      • value: number

      Returns void

    • get y(): number

      Returns number

    • set y(value: number): void

      Parameters

      • value: number

      Returns void

    • get z(): number

      Returns number

    • set z(value: number): void

      Parameters

      • value: number

      Returns void

    • Clones this instance and returns a new Quaternion with identical values.

      Returns Quaternion

    • Returns a copy of the current Quaternion divided by the factor.

      Parameters

      • factor: number

      Returns Quaternion

    • Clears all elements of the Quaternion to zero.

      Returns Quaternion

      This is not the identity

    • Divides this Quaternion by the given factor and returns it.

      Parameters

      • factor: number

      Returns Quaternion

    • Calculates the inverse of the quaternion. Inverse quaternion has the opposite rotation of the original.

      Returns Quaternion

      This method expects the quaternion to be normalized.

    • Multiply this Quaternion by the given factor and returns it.

      Parameters

      • factor: number

      Returns Quaternion

    • Normalizes the quaternion.

      Returns number

      Length of the quaternion prior to normalization.

    • Calculates a dot product between two quaternions.

      Parameters

      Returns number

      Dot product between the two quaternions.

    • Evaluates the expression and assigns it to the quaternion.

      Parameters

      • fnExpression: () => number

        The expression to evaluate.

      Returns Quaternion

      A reference to this vector

      Make sure to read up on how Vector expressions work in Typescript.

      MathEx.eval for detailed documentation, limitations and considerations.

    • Converts a quaternion into an orthonormal set of axes.

      Returns { xAxis: Vector3; yAxis: Vector3; zAxis: Vector3 }

      An object containing the x, y and z axes.

    • Accesses a specific component of the quaternion.

      Parameters

      • index: number

        Index of the component (0 - x, 1 - y, 2 - z, 3 - w).

      Returns number

      Value of the specific component.

    • Returns a copy of the inverse of the quaternion. Quaternion must be non-zero. Inverse quaternion has the opposite rotation of the original.

      Returns Quaternion

    • Returns whether the provided quaternion, given a error margin, contains the same values as this one.

      Parameters

      • rhs: Immutable<Quaternion>

        The other quaternion to compare

      • Optionalepsilon: number

        Optional. Error margin within which the numbers should be considered equal.

      Returns boolean

      True if equal, false otherwise.

    • Returns whether this quaternion is equal to given one.

      Parameters

      Returns boolean

    • Returns a copy of the current Quaternion multiplied by the factor.

      Parameters

      • factor: number

      Returns Quaternion

    • Applies the quaternion rotation to the specified point or direction.

      Parameters

      Returns Vector3

      Vector rotated by the quaternion.

    • Initializes the quaternion with rotation that rotates from one direction to another.

      Parameters

      • fromDirection: Immutable<Vector3>

        rotation to start at.

      • toDirection: Immutable<Vector3>

        rotation to end at.

      • OptionalfallbackAxis: Immutable<Vector3>

        Optional fallback axis to use if the from/to vectors are almost completely opposite. Fallback axis should be perpendicular to both vectors.

      Returns void

      This method, may introduce roll and is not suitable for all use-cases. To set the look rotation for a camera or character, use setLookRotation instead.

    • Assigns the value to the element at the specified index.

      Parameters

      • index: number
      • value: number

      Returns void

    • Sets all elements of the Quaternion.

      Parameters

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

      Returns Quaternion

    • Creates a quaternion that orients an object so it faces in the provided direction.

      Parameters

      Returns void

      If forward and up are collinear, this method will fallback to using setDeltaRotation, which may introduce roll. In such cases, consider providing a different up vector.

    • Converts this instance to an array with 4 elements.

      Returns [number, number, number, number]

    • Converts the quaternion rotation into axis/angle rotation.

      Returns { angle: rsx.Degree; axis: Vector3 }

      An object containing the axis and angle in degrees.

    • Converts the quaternion rotation into euler angle (pitch/yaw/roll) rotation.

      Returns Vector3

      rotation as euler angles, in degrees.

    • Converts a quaternion rotation into a rotation matrix.

      Returns Matrix3

      Matrix representing the rotation.

    • Returns a string representation of an object.

      Returns string

    • Creates a quaternion from a rotation matrix.

      Parameters

      Returns Quaternion

      Newly created quaternion that has equivalent rotation as the provided rotation matrix.

    • Creates a quaternion with rotation that rotates from one direction to another.

      Parameters

      • fromDirection: Immutable<Vector3>

        rotation to start at.

      • toDirection: Immutable<Vector3>

        rotation to end at.

      • fallbackAxis: Immutable<Vector3>

        Fallback axis to use if the from/to vectors are almost completely opposite. Fallback axis should be perpendicular to both vectors.

      Returns Quaternion

      Quaternion that rotates an object from fromDirection to toDirection

    • Returns the inverse of the quaternion. Inverse quaternion has the opposite rotation of the original.

      Parameters

      Returns Quaternion

      Inverse of the provided quaternion.

      Quaternion must be non-zero

    • Determines whether both Quaternions are equal within an error margin.

      Parameters

      • lhs: Immutable<Quaternion>

        First quaternion to compare.

      • rhs: Immutable<Quaternion>

        Second quaternion to compare.

      • Optionalepsilon: number

        Optional. Error margin within which the numbers should be considered equal.

      Returns boolean

      True if equal, false otherwise.

    • Performs a spherical interpolation between two quaternions.

      Parameters

      • from: Immutable<Quaternion>

        Start quaternion.

      • to: Immutable<Quaternion>

        End quaternion.

      • t: number

        Interpolation factor in range [0...1] that determines how much to interpolate between from and to.

      • OptionalshortestPath: boolean

        true to take the shortest or longest path. Default: true.

      Returns Quaternion

      Interpolated quaternion representing a rotation between from and to.

    • Creates a quaternion with rotation that rotates from one direction to another.

      Parameters

      • fromDirection: Immutable<Vector3>

        rotation to start at.

      • toDirection: Immutable<Vector3>

        rotation to end at.

      • OptionalfallbackAxis: Immutable<Vector3>

        Fallback axis to use if the from/to vectors are almost completely opposite. Fallback axis should be perpendicular to both vectors.

      Returns Quaternion

      Quaternion that rotates an object from fromDirection to toDirection

      This method, may introduce roll and is not suitable for all use-cases. To set the look rotation for a camera or character, use withLookRotation instead.