dot big bang

Developer API
Menu

Class Vector4

All
  • Public
  • Public/Protected
  • All

Hierarchy

  • Vector4

Index

Constructors

constructor

  • new Vector4(x?: number, y?: number, z?: number, w?: number): Vector4
  • Creates a new Vector4

    Parameters

    • Optional x: number

      The x component of the vector. Default is 0.

    • Optional y: number

      The y component of the vector. Default is 0.

    • Optional z: number

      The z component of the vector. Default is 0.

    • Optional w: number

      The z component of the vector. Default is 0.

    Returns Vector4

Properties

w

w: number

The w component of the vector.

x

x: number

The x component of the vector.

y

y: number

The y component of the vector.

z

z: number

The z component of the vector.

Methods

add

  • Adds the vector v to this vector.

    Parameters

    • v: Vector4

      The vector to add to this one.

    Returns Vector4

addScalar

  • Adds the scalar value s to the x, y, z and w components of this vector.

    Parameters

    • s: number

      The scalar value to add.

    Returns Vector4

addScaledVector

  • Adds the vector v multiplied by the scalar s to this vector.

    Parameters

    • v: Vector4

      The vector to scale by s and add to this vector.

    • s: number

      The scale factor to apply to v before adding it to this vector.

    Returns Vector4

addVectors

  • Sets this vector to a + b.

    Parameters

    • a: Vector4

      The vector to add to b before setting the result to this vector.

    • b: Vector4

      The vector to add to a before setting the result to this vector.

    Returns Vector4

applyMatrix4

  • Multiplies this vector by m

    Parameters

    • m: Matrix4

      The matrix to apply to this vector.

    Returns Vector4

ceil

  • Rounds this vector's components up to the nearest integer value.

    Returns Vector4

clamp

  • If this vector's x, y, z or w value is greater than the max vector's x, y, z or w value, it is replaced by the corresponding value. If this vector's x, y, z or w value is less than the min vector's x, y, z or w value, it is replaced by the corresponding value.

    Parameters

    • min: Vector4

      The vector with the minimum x, y and z values used for clamping this vector.

    • max: Vector4

      The vector with the maximum x, y and z values used for clamping this vector.

    Returns Vector4

clampScalar

  • clampScalar(minVal: number, maxVal: number): Vector4
  • If this vector's x, y, z or w values are greater than the max value, they are replaced by the maxVal value. If this vector's x, y, z or w values are less than the min value, they are replaced by the minVal value.

    Parameters

    • minVal: number

      The minimum value used for clamping this vector.

    • maxVal: number

      The maximum value used for clamping this vector.

    Returns Vector4

clone

  • Returns a new vector with the same x, y, z and w values as this one.

    Returns Vector4

copy

  • Copies the provided vector v into this one.

    Parameters

    Returns Vector4

divideScalar

  • Divides this vector by the scalar s. Each component of this vector is divided by the same value s. Set this vector to (0, 0, 0, 0) if s == 0.

    Parameters

    • s: number

      The value to divide each component of this vector with.

    Returns Vector4

dot

  • Calculates the dot product of this vector and v.

    Parameters

    • v: Vector4

      The other vector to calculate the dot product with.

    Returns number

equals

  • Checks for strict equality of this vector and v.

    Parameters

    • v: Vector4

      The other vector to compare this one to.

    Returns boolean

floor

  • Rounds this vector's components down to the nearest integer value.

    Returns Vector4

fromArray

  • fromArray(array: number[], offset?: number): Vector4
  • Sets this vector's x value to be array[offset+0], y value to be array[offset+1] z value to be array[offset+2] and w value to be array[offset+3].

    Parameters

    • array: number[]

      The array of format [x, y, z, w] used to construct this vector.

    • Optional offset: number

      An offset into the array from where to start reading the components.

    Returns Vector4

getComponent

  • getComponent(index: number): number
  • Gets the value of the index-th component of the vector. Index 0 corresponds to the x component, 1 is y, 2 is z and 3 is w.

    Parameters

    • index: number

      The index (0, 1, 2 or 3) of the component to get.

    Returns number

length

  • length(): number
  • Computes the Euclidean length (straight-line length) from (0, 0, 0, 0) to this vector's (x, y, z, w). If you are comparing the lengths of vectors, you should compare the length squared instead as it is slightly more efficient to calculate.

    Returns number

lengthManhattan

  • lengthManhattan(): number

lengthSq

  • lengthSq(): number
  • Computes the square of the Euclidean length (straight-line length) from (0, 0, 0, 0) to this vector's (x, y, z, w). If you are comparing the lengths of vectors, you should compare the length squared instead as it is slightly more efficient to calculate.

    Returns number

lerp

  • Linearly interpolates between this vector and v by alpha amount (alpha=0 returns this vector, while alpha=1 returns v) and stores the result into this vector.

    Parameters

    • v: Vector4

      The vector to interpolate this one towards.

    • alpha: number

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

    Returns Vector4

lerpVectors

  • Linearly interpolates between v1 and v2 by alpha amount (alpha=0 returns v1, while alpha=1 returns v2) and stores the result into this vector.

    Parameters

    • v1: Vector4

      The starting vector (returned when alpha equals 0).

    • v2: Vector4

      The vector to interpolate towards (returned when alpha equals 1).

    • alpha: number

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

    Returns Vector4

max

  • If this vector's x, y, z or w value is less than v's x, y, z or w value, replaces that value with the corresponding max value.

    Parameters

    Returns Vector4

min

  • If this vector's x, y, z or w value is greater than v's x, y, z or w value, replaces that value with the corresponding min value.

    Parameters

    • v: Vector4

      The vector with the values to compare to.

    Returns Vector4

multiplyScalar

  • multiplyScalar(s: number): Vector4
  • Multiplies this vector by the scalar s. Each component of this vector is multiplied by the same value s.

    Parameters

    • s: number

      The value to multiply each component of this vector by.

    Returns Vector4

negate

  • Inverts this vector, i.e. sets x=-x, y=-y, z=-z and w=-w.

    Returns Vector4

normalize

  • Converts this vector to a unit vector, that is, sets it equal to a vector with the same direction as this one, but with a length of 1.

    Returns Vector4

round

  • Rounds this vector's components to the nearest integer value.

    Returns Vector4

roundToZero

  • Rounds this vector's components towards zero (up if negative, down if positive) to an integer value.

    Returns Vector4

set

  • set(x: number, y: number, z: number, w: number): Vector4
  • Sets the x, y, z and w components of this vector to the provided ones.

    Parameters

    • x: number

      The x component of the vector.

    • y: number

      The y component of the vector.

    • z: number

      The z component of the vector.

    • w: number

      The w component of the vector.

    Returns Vector4

setAxisAngleFromQuaternion

  • Sets this vector to the computed axis-angle representation of the rotation defined by the quaternion q. The axis is stored in (x, y, z) components of the vector, and the rotation in radians is stored in component w.

    Parameters

    • q: Quaternion

      The quaternion to represent as an axis-angle in this vector.

    Returns Vector4

setAxisAngleFromRotationMatrix

  • Sets this vector to the computed axis-angle representation of the rotation defined by the matrix m. The upper left 3x3 part of m is assumed to be a pure rotation matrix (i.e, unscaled). The axis is stored in (x, y, z) components of the vector, and the rotation in radians is stored in component w.

    Parameters

    Returns Vector4

setComponent

  • setComponent(index: number, value: number): void
  • Sets the index-th component of this vector to the provided value. Index 0 corresponds to the x component, 1 is y, 2 is z and 3 is w.

    Parameters

    • index: number

      The index (0, 1, 2 or 3) of the component to set.

    • value: number

      The value to set the component of this vector to.

    Returns void

setLength

  • setLength(length: number): Vector4
  • Set this vector to a vector with the same direction as this one, but a length of l.

    Parameters

    • length: number

    Returns Vector4

setScalar

  • setScalar(scalar: number): Vector4
  • Sets the x, y, z and w components of this vector to the same scalar value.

    Parameters

    • scalar: number

      The value to set all the components of this vector to.

    Returns Vector4

setW

  • Sets this vector's w component to the provided value.

    Parameters

    • w: number

      The value to set the w component to.

    Returns Vector4

setX

  • Sets this vector's x component to the provided value.

    Parameters

    • x: number

      The value to set the x component to.

    Returns Vector4

setY

  • Sets this vector's y component to the provided value.

    Parameters

    • y: number

      The value to set the y component to.

    Returns Vector4

setZ

  • Sets this vector's z component to the provided value.

    Parameters

    • z: number

      The value to set the z component to.

    Returns Vector4

sub

  • Subtracts the vector v from this vector.

    Parameters

    • v: Vector4

      The vector to subtract from this vector.

    Returns Vector4

subScalar

  • Subtracts the scalar s from this vector's x, y and z components.

    Parameters

    • s: number

      The value to subtract to the x, y and z components of this vector.

    Returns Vector4

subVectors

  • Sets this vector to a - b.

    Parameters

    • a: Vector4

      The vector from which b is subtracted before setting the result to this vector.

    • b: Vector4

      The vector to subtract from a before setting the result to this vector.

    Returns Vector4

toArray

  • toArray(array?: number[], offset?: number): number[]
  • Returns the components of this vector in an array of format [x, y, z, w].

    Parameters

    • Optional array: number[]

      The array to store the compoments of the vector in. If not specified, a new array will be created.

    • Optional offset: number

      An offset into the array where to write the elements of this vector.

    Returns number[]