Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Vec3

Representation of 3D vectors and points.

Hierarchy

Index

Constructors

constructor

  • newVec3(v: Vec3): Vec3
  • newVec3(x?: undefined | number, y?: undefined | number, z?: undefined | number): Vec3

Properties

x

x: number

x component.

y

y: number

y component.

z

z: number

z component.

Static FORWARD

FORWARD: Readonly<Vec3> = Object.freeze(new Vec3(0, 0, -1))

Static NEG_ONE

NEG_ONE: Readonly<Vec3> = Object.freeze(new Vec3(-1, -1, -1))

Static ONE

ONE: Readonly<Vec3> = Object.freeze(new Vec3(1, 1, 1))

Static RIGHT

RIGHT: Readonly<Vec3> = Object.freeze(new Vec3(1, 0, 0))

Static UNIT_X

UNIT_X: Readonly<Vec3> = Object.freeze(new Vec3(1, 0, 0))

Static UNIT_Y

UNIT_Y: Readonly<Vec3> = Object.freeze(new Vec3(0, 1, 0))

Static UNIT_Z

UNIT_Z: Readonly<Vec3> = Object.freeze(new Vec3(0, 0, 1))

Static UP

UP: Readonly<Vec3> = Object.freeze(new Vec3(0, 1, 0))

Static ZERO

ZERO: Readonly<Vec3> = Object.freeze(new Vec3(0, 0, 0))

Methods

add

  • add(other: Vec3): this

add3f

  • add3f(x: number, y: number, z: 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

    Returns this

clampf

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

    Parameters

    • minInclusive: Vec3

      Minimum value allowed

    • maxInclusive: Vec3

      Maximum value allowed

    Returns this

    this

clone

cross

  • cross(other: Vec3): this

divide

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

    Parameters

    • other: Vec3

      specified vector

    Returns this

divide3f

  • divide3f(x: number, y: number, z: 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

    Returns this

dot

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

    Parameters

    • other: Vec3

      specified vector

    Returns number

    The result of calculates the dot product with another vector

equals

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

    Parameters

    • other: Vec3

      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.

equals3f

  • equals3f(x: number, y: number, z: 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

    • 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: Vec3, ratio: number): this
  • Calculate linear interpolation result between this vector and another one with given ratio.

    Parameters

    • to: Vec3

      Target vector

    • ratio: number

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

    Returns this

multiply

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

    Parameters

    • other: Vec3

      specified vector

    Returns this

multiply3f

  • multiply3f(x: number, y: number, z: 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

    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: Vec3): any
  • set(x?: undefined | number, y?: undefined | number, z?: undefined | number): any
  • Set the current vector value with the given vector.

    Parameters

    • other: Vec3

      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

    Returns any

    this

strictEquals

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

    Parameters

    • other: Vec3

      specified vector

    Returns boolean

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

strictEquals3f

  • strictEquals3f(x: number, y: number, z: number): boolean
  • Check whether the current vector strictly equals another Vec3.

    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

    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: Vec3): this

subtract3f

  • subtract3f(x: number, y: number, z: 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

    Returns this

toString

  • toString(): string

transformMat4

  • transformMat4(matrix: Mat4): this
  • Transforms the vec3 with a mat4. 4th vector component is implicitly '1'

    Parameters

    • matrix: Mat4

      matrix to transform with

    Returns this

Static add

Static angle

Static ceil

Static clone

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

Static copy

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

Static cross

Static distance

Static divide

Static dot

Static equals

Static floor

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 invert

Static invertSafe

  • invertSafe<Out>(out: Out, a: IVec3Like): Out

Static len

Static lengthSqr

Static lerp

Static max

Static min

Static multiply

Static multiplyScalar

  • multiplyScalar<Out, Vec3Like>(out: Out, a: Vec3Like, b: number): Out

Static negate

Static normalize

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

Static project

Static projectOnPlane

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 rotateX

Static rotateY

Static rotateZ

Static round

Static scaleAndAdd

Static set

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

    Type parameters

    Parameters

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

    Returns Out

Static squaredDistance

Static strictEquals

Static subtract

Static toArray

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

    Type parameters

    • Out: IWritableArrayLike<number>

    Parameters

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

      Array Start Offset

    Returns Out

Static transformAffine

Static transformInverseRTS

Static transformMat3

Static transformMat4

Static transformMat4Normal

Static transformQuat

Static transformRTS

Static zero

  • zero<Out>(out: Out): Out

Generated using TypeDoc