Scriptable Parser for Portal 2 Demos
    Preparing search index...

    Class Vector

    VScript-like 3D vector implementation.

    Index

    Constructors

    Methods

    • Scales the vector's components by the given factor. Does not modify the vector.

      Parameters

      • factor: number

        Factor by which to scale the vector.

      Returns Vector

      A new, scaled vector.

    • Calculates the length of the vector squared, ignoring the Z axis.

      Returns number

      The vector's length when projected onto the Z plane, squared.

    • Calculates the length of the vector, ignoring the Z axis.

      Returns number

      The vector's length when projected onto the Z plane.

    • Normalizes the vector in-place, turning it into a unit vector.

      Returns number

      The vector's length before normalizing.

    • Computes the cross product between this vector and another vector.

      Parameters

      • other: Vector

        The vector with which to compute the cross product.

      Returns Vector

      A new vector - the cross product of this vector and the other vector.

    • Computes the dot product between this vector and another vector.

      Parameters

      • other: Vector

        The vector with which to compute the dot product.

      Returns number

      The dot product of this vector and the other vector.

    • Converts the vector to a pretty-printable string.

      Returns string

      A string in the form "(x y z)", with each component fixed to 3 digits of precision after the decimal point.

    • Converts the vector to a "keyvalue string". Makes more sense in VScript, where setting vector keyvalues from strings is normal.

      Technically, the VScript version of this function adds an extra bracket to the output. I'm not replicating that here, as it's very clearly unintentional.

      Returns string

      A string in the form "x y z", not truncated.

    • Similar to the Array map method, applies a function to each element of the vector.

      Parameters

      • callback: (value: number, index?: number) => number

        Function to call for each element of the vector. The function is provided the value and index of the current component.

      Returns Vector

      A new vector, gained from applying the callback to each element.

    • Rotates the coordinate vector by a given set of Euler angles.

      Parameters

      • angles: Vector

        Euler angles (pitch, yaw, roll) to rotate by, in radians.

      Returns Vector

      A new, rotated vector. Original vector is not modified.

    • Converts direction vector(s) to a vector of pitch/yaw/roll angles. The vector on which this method is called is treated as the forward-vector.

      Parameters

      • Optionalup: Vector

        Up-vector, optional. If provided, used for calculating roll.

      Returns Vector

      A new vector containing Euler angles in radians, in the form (pitch, yaw, roll). Original vector is not modified.

    • For a set of Euler angles in the form (pitch, yaw, roll) in radians, returns forward-, left-, and up-vectors.

      Returns { forward: Vector; up: Vector }

      Set of forward- and up-facing unit vectors representing the input angles. Original vector is not modified.

    • Rotates this vector as a set of (pitch, yaw, roll) Euler angles in radians by another set of such angles.

      Parameters

      • rotation: Vector

        Set of Euler angles of form (pitch, yaw, roll) in radians, to rotate by.

      Returns Vector

      A new vector containing a rotated set of angles.