Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Vec4

Representation of four-dimensional vectors.

Hierarchy

Index

Constructors

constructor

  • newVec4(other: Vec4): Vec4
  • newVec4(x?: undefined | number, y?: undefined | number, z?: undefined | number, w?: undefined | number): Vec4

Properties

w

w: number

w component.

x

x: number

x component.

y

y: number

y component.

z

z: number

z component.

Static NEGONE

NEGONE: {} = Object.freeze(new Vec4(-1, -1, -1, -1))

Type declaration

Static ONE

ONE: {} = Object.freeze(new Vec4(1, 1, 1, 1))

Type declaration

Static ZERO

ZERO: {} = Object.freeze(new Vec4(0, 0, 0, 0))

Type declaration

Methods

add

  • add(other: Vec4): this

add4f

  • add4f(x: number, y: number, z: number, w: number): this
  • Adds the current vector with another one and return this

    Parameters

    • x: number

      The x value of specified vector

    • y: number

      The y value of specified vector

    • z: number

      The z value of specified vector

    • w: number

      The w value of specified vector

    Returns this

clampf

  • clampf(minInclusive: Vec4, maxInclusive: Vec4): this
  • Clamp the vector between minInclusive and maxInclusive.

    Parameters

    • minInclusive: Vec4

      Minimum value allowed

    • maxInclusive: Vec4

      Maximum value allowed

    Returns this

    this

clone

cross

  • cross(vector: Vec4): this

divide

  • divide(other: Vec4): this
  • Element-wisely divides this vector with another one, and return this.

    Parameters

    • other: Vec4

      specified vector

    Returns this

divide4f

  • divide4f(x: number, y: number, z: number, w: number): this
  • Element-wisely divides this vector with another one, and return this.

    Parameters

    • x: number

      The x value of specified vector

    • y: number

      The y value of specified vector

    • z: number

      The z value of specified vector

    • w: number

      The w value of specified vector

    Returns this

dot

  • dot(vector: Vec4): number
  • Calculates the dot product with another vector

    Parameters

    Returns number

    当前向量与指定向量点乘的结果。

equals

  • equals(other: Vec4, epsilon?: number): boolean
  • Check whether the vector approximately equals another one.

    Parameters

    • other: Vec4

      Specified vector

    • Default value epsilon: number = EPSILON

      The error allowed. It`s should be a non-negative number.

    Returns boolean

    Returns true when the components of both vectors are equal within the specified range of error; otherwise it returns false.

equals4f

  • equals4f(x: number, y: number, z: number, w: number, epsilon?: number): boolean
  • Check whether the vector approximately equals another one.

    Parameters

    • x: number

      The x value of specified vector

    • y: number

      The y value of specified vector

    • z: number

      The z value of specified vector

    • w: number

      The w value of specified vector

    • Default value epsilon: number = EPSILON

      The error allowed. It`s should be a non-negative number.

    Returns boolean

    Returns true when the components of both vectors are equal within the specified range of error; otherwise it returns false.

length

  • length(): number

lengthSqr

  • lengthSqr(): number

lerp

  • lerp(to: Vec4, ratio: number): this
  • Calculate linear interpolation result between this vector and another one with given ratio.

    Parameters

    • to: Vec4

      Target vector

    • ratio: number

      The interpolation coefficient.The range is [0,1].

    Returns this

multiply

  • multiply(other: Vec4): this
  • Multiplies the current vector with another one and return this

    Parameters

    • other: Vec4

      specified vector

    Returns this

multiply4f

  • multiply4f(x: number, y: number, z: number, w: number): this
  • Multiplies the current vector with another one and return this

    Parameters

    • x: number

      The x value of specified vector

    • y: number

      The y value of specified vector

    • z: number

      The z value of specified vector

    • w: number

      The w value of specified vector

    Returns this

multiplyScalar

  • multiplyScalar(scalar: number): this
  • Multiplies the current vector with a number, and returns this.

    Parameters

    • scalar: number

      scalar number

    Returns this

negative

  • negative(): this

normalize

  • normalize(): this

set

  • set(other: Vec4): any
  • set(x?: undefined | number, y?: undefined | number, z?: undefined | number, w?: undefined | number): any
  • Set the current vector value with the given vector.

    Parameters

    • other: Vec4

      Specified vector

    Returns any

    this

  • Set the value of each component of the current vector.

    Parameters

    • Optional x: undefined | number

      x value

    • Optional y: undefined | number

      y value

    • Optional z: undefined | number

      z value

    • Optional w: undefined | number

      w value

    Returns any

    this

strictEquals

  • strictEquals(other: Vec4): boolean
  • Check whether the current vector strictly equals another Vec4.

    Parameters

    • other: Vec4

      specified vector

    Returns boolean

    Returns true when the components of both vectors are equal within the specified range of error; otherwise it returns false.

strictEquals4f

  • strictEquals4f(x: number, y: number, z: number, w: number): boolean
  • Check whether the current vector strictly equals another Vec4.

    Parameters

    • x: number

      The x value of specified vector

    • y: number

      The y value of specified vector

    • z: number

      The z value of specified vector

    • w: number

      The w value of specified vector

    Returns boolean

    Returns true when the components of both vectors are equal within the specified range of error; otherwise it returns false.

subtract

  • subtract(other: Vec4): this

subtract4f

  • subtract4f(x: number, y: number, z: number, w: number): this
  • Subtracts one vector from this, and returns this.

    Parameters

    • x: number

      The x value of specified vector

    • y: number

      The y value of specified vector

    • z: number

      The z value of specified vector

    • w: number

      The w value of specified vector

    Returns this

toString

  • toString(): string

transformMat4

  • transformMat4(matrix: Mat4): this

Static add

  • add<Out>(out: Out, a: Out, b: Out): Out
  • Element-wise vector addition and save the results to out vector object

    Type parameters

    Parameters

    • out: Out
    • a: Out
    • b: Out

    Returns Out

Static ceil

  • ceil<Out>(out: Out, a: Out): Out
  • Rounds up by elements of the vector and save the results to out vector object

    Type parameters

    Parameters

    • out: Out
    • a: Out

    Returns Out

Static clone

  • clone<Out>(a: Out): Vec4

Static copy

  • copy<Out>(out: Out, a: Out): Out

Static distance

  • distance<Out>(a: Out, b: Out): number

Static divide

  • divide<Out>(out: Out, a: Out, b: Out): Out
  • Element-wise vector division and save the results to out vector object

    Type parameters

    Parameters

    • out: Out
    • a: Out
    • b: Out

    Returns Out

Static dot

  • dot<Out>(a: Out, b: Out): number

Static equals

  • equals<Out>(a: Out, b: Out, epsilon?: number): boolean
  • Check whether the two given vectors are approximately equivalent

    Type parameters

    Parameters

    • a: Out
    • b: Out
    • Default value epsilon: number = EPSILON

    Returns boolean

Static floor

  • floor<Out>(out: Out, a: Out): Out
  • Element-wise rounds down of the current vector and save the results to the out vector

    Type parameters

    Parameters

    • out: Out
    • a: Out

    Returns Out

Static fromArray

  • fromArray<Out>(out: Out, arr: IWritableArrayLike<number>, ofs?: number): Out
  • Converts the given array to a vector

    Type parameters

    Parameters

    • out: Out
    • arr: IWritableArrayLike<number>
    • Default value ofs: number = 0

      Array Start Offset

    Returns Out

Static inverse

  • inverse<Out>(out: Out, a: Out): Out
  • Sets each element to its inverse value, zero value will become Infinity

    Type parameters

    Parameters

    • out: Out
    • a: Out

    Returns Out

Static inverseSafe

  • inverseSafe<Out>(out: Out, a: Out): Out

Static len

  • len<Out>(a: Out): number

Static lengthSqr

  • lengthSqr<Out>(a: Out): number

Static lerp

  • lerp<Out>(out: Out, a: Out, b: Out, t: number): Out
  • Calculates the linear interpolation between two vectors with a given ratio

    Type parameters

    Parameters

    • out: Out
    • a: Out
    • b: Out
    • t: number

    Returns Out

Static max

  • max<Out>(out: Out, a: Out, b: Out): Out
  • Calculates the maximum values by elements of the vector and save the results to the out vector

    Type parameters

    Parameters

    • out: Out
    • a: Out
    • b: Out

    Returns Out

Static min

  • min<Out>(out: Out, a: Out, b: Out): Out
  • Calculates the minimum values by elements of the vector and save the results to the out vector

    Type parameters

    Parameters

    • out: Out
    • a: Out
    • b: Out

    Returns Out

Static multiply

  • multiply<Out>(out: Out, a: Out, b: Out): Out
  • Element-wise vector multiplication and save the results to out vector object

    Type parameters

    Parameters

    • out: Out
    • a: Out
    • b: Out

    Returns Out

Static multiplyScalar

  • multiplyScalar<Out>(out: Out, a: Out, b: number): Out
  • Vector scalar multiplication and save the results to out vector object

    Type parameters

    Parameters

    • out: Out
    • a: Out
    • b: number

    Returns Out

Static negate

  • negate<Out>(out: Out, a: Out): Out

Static normalize

  • normalize<Out>(out: Out, a: Out): Out

Static random

  • random<Out>(out: Out, scale?: undefined | number): Out
  • Generates a uniformly distributed random vector points from center to the surface of the unit sphere

    Type parameters

    Parameters

    • out: Out
    • Optional scale: undefined | number

      vector length

    Returns Out

Static round

  • round<Out>(out: Out, a: Out): Out

Static scaleAndAdd

  • scaleAndAdd<Out>(out: Out, a: Out, b: Out, scale: number): Out
  • Element-wise multiplication and addition with the equation: a + b * scale

    Type parameters

    Parameters

    • out: Out
    • a: Out
    • b: Out
    • scale: number

    Returns Out

Static set

  • set<Out>(out: Out, x: number, y: number, z: number, w: number): Out
  • Sets the out vector with the given x, y, z and w values

    Type parameters

    Parameters

    • out: Out
    • x: number
    • y: number
    • z: number
    • w: number

    Returns Out

Static squaredDistance

  • squaredDistance<Out>(a: Out, b: Out): number

Static strictEquals

  • strictEquals<Out>(a: Out, b: Out): boolean

Static subtract

  • subtract<Out>(out: Out, a: Out, b: Out): Out
  • Element-wise vector subtraction and save the results to out vector object

    Type parameters

    Parameters

    • out: Out
    • a: Out
    • b: Out

    Returns Out

Static toArray

  • toArray<Out>(out: Out, v: IVec4Like, ofs?: number): Out
  • Converts the given vector to an array

    Type parameters

    • Out: IWritableArrayLike<number>

    Parameters

    • out: Out
    • v: IVec4Like
    • Default value ofs: number = 0

      Array Start Offset

    Returns Out

Static transformAffine

  • transformAffine<Out, VecLike, MatLike>(out: Out, v: VecLike, m: MatLike): Out

Static transformMat4

  • transformMat4<Out, MatLike>(out: Out, a: Out, m: MatLike): Out

Static transformQuat

  • transformQuat<Out, QuatLike>(out: Out, a: Out, q: QuatLike): Out

Generated using TypeDoc