Really basic 3D vector class used for vector calculations

Constructors

  • Vec3 constructor

    Parameters

    • x: number = 0

      X component of our Vec3

    • y: number = x

      Y component of our Vec3

    • z: number = x

      Z component of our Vec3

    Returns Vec3

Properties

type: string

The type of the Vec3

_x: number

X component of our Vec3

_y: number

Y component of our Vec3

_z: number

Z component of our Vec3

Accessors

Methods

  • Called when at least one component of the Vec3 has changed

    Parameters

    • callback: (() => void)

      callback to run when at least one component of the Vec3 has changed

        • (): void
        • Returns void

    Returns Vec3

  • Set the Vec3 from values

    Parameters

    • x: number = 0

      new X component to set

    • y: number = x

      new Y component to set

    • z: number = x

      new Z component to set

    Returns Vec3

    • this Vec3 after being set
  • Add a scalar to all the components of this Vec3

    Parameters

    • value: number = 0

      number to add

    Returns Vec3

    • this Vec3 after addition
  • Subtract a scalar to all the components of this Vec3

    Parameters

    • value: number = 0

      number to subtract

    Returns Vec3

    • this Vec3 after subtraction
  • Multiply all components of this Vec3 with a scalar

    Parameters

    • value: number = 1

      number to multiply with

    Returns Vec3

    • this Vec3 after multiplication
  • Divide all components of this Vec3 with a scalar

    Parameters

    • value: number = 1

      number to divide with

    Returns Vec3

    • this Vec3 after division
  • Get the euclidian distance between this Vec3 and another Vec3

    Parameters

    • vector: Vec3 = ...

      Vec3 to use for distance calculation

    Returns number

    • euclidian distance
  • Calculate the dot product of 2 Vec3

    Parameters

    • vector: Vec3 = ...

      Vec3 to use for dot product

    Returns number

    • dot product of the 2 Vec3
  • Calculate the linear interpolation of this Vec3 by given Vec3 and alpha, where alpha is the percent distance along the line

    Parameters

    • vector: Vec3 = ...

      Vec3 to interpolate towards

    • alpha: number = 1

      interpolation factor in the [0, 1] interval

    Returns Vec3

    • this Vec3 after linear interpolation
  • Rotate a Vec3 around and axis by a given angle

    Parameters

    • axis: Vec3 = ...

      normalized Vec3 around which to rotate

    • angle: number = 0

      angle (in radians) to rotate

    • quaternion: Quat = ...

      optional quaternion to use for rotation computations

    Returns Vec3

    • this Vec3 with the rotation applied
  • Transforms the direction of this vector by a Mat4 (the upper left 3 x 3 subset) and then normalizes the result.

    Parameters

    • matrix: Mat4

      Mat4 to use for transformation.

    Returns Vec3

    • this Vec3 with the transformation applied.