RSX Code Reference
    Preparing search index...

    Class Vector4

    The Vector4 implements a fixed-size four-dimensional vector with a homogenous w coordinate. The class follows the 'copy-on-write' pattern, which means that every operation such as Vector4#normalized or Vector4.add returns a copy of the vector with updates values. It also implies that the values of the vector 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 Vector4

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

    A Vector with all components set to one.

    A Vector with the W component set to one and the rest set to zero.

    A Vector with the X component set to one and the rest set to zero.

    A Vector with the Y component set to one and the rest set to zero.

    A Vector with the Z component set to one and the rest set to zero.

    A Vector with all components set to zero.

    • get elementCount(): number

      Gets the number of elements in this vector.

      Returns number

    • 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

    • Returns a copy of the current vector added by the given scalar.

      Parameters

      • rhs: number

      Returns Vector4

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

      Returns Vector4

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

      Parameters

      • factor: number

      Returns Vector4

    • Adds a scalar to this one and returns it.

      Parameters

      • rhs: number

      Returns Vector4

    • Clears all elements of the vector to zero.

      Returns Vector4

    • Divides this vector by a factor.

      Parameters

      • factor: number

      Returns Vector4

    • Performs scalar multiplication of this vector and returns it.

      Parameters

      • factor: number

      Returns Vector4

    • Normalizes the vector.

      Returns number

    • Subtracts a scalar from this one and returns it.

      Parameters

      • rhs: number

      Returns Vector4

    • Calculates the inner product of this and the other vector.

      Parameters

      Returns number

      Inner product between the two vectors.

    • Evaluates the expression and assigns it to the vector.

      Parameters

      • fnExpression: () => number

        The expression to evaluate.

      Returns Vector4

      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.

    • Accesses a specific component of the vector.

      Parameters

      • index: number

        Index of the component.

      Returns number

      Value of the specific component.

    • Returns whether the provided vector, given a error margin, has the same vector components values as this one.

      Parameters

      • rhs: Immutable<Vector4>

        The other Vector4 to compare with.

      • Optionalepsilon: number

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

      Returns boolean

      True if equal, false otherwise.

    • Returns whether the given vector contains the same vector components values as this one.

      Parameters

      Returns boolean

    • Returns the length of the vector.

      Returns number

    • Returns the squared length of the vector.

      Returns number

    • Returns a copy of this vector multiplied by the factor.

      Parameters

      • factor: number

      Returns Vector4

    • Returns a normalized copy of the vector.

      Returns Vector4

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

      Parameters

      • index: number
      • value: number

      Returns void

    • Assigns the specified values.

      Parameters

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

      Returns void

    • Returns a copy of the current vector subtracted by the given vector.

      Parameters

      • rhs: number

      Returns Vector4

    • Converts this instance to an array with 4 elements.

      Returns [number, number, number, number]

    • Returns a string representation of an object.

      Returns string

    • Compares two 4D vectors with an error margin.

      Parameters

      • lhs: Immutable<Vector4>

        First vector to compare.

      • rhs: Immutable<Vector4>

        Second vector to compare.

      • Optionalepsilon: number

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

      Returns boolean

      True if equal, false otherwise.