Class: Vec3
Defined in: math/vector3.ts:23
Static operations on Vector3. Mutating operations (set, add,
subtract, multiply, multiplyComponents, divide, normalize,
floorComponents) mutate their target argument in place and return it,
rather than allocating a new Vector3. Read-only operations (magnitude,
magnitudeSquared, equals, toString, toFloat32Array) and clone
never mutate their arguments.
Constructors
Constructor
new Vec3():
Vec3
Returns
Vec3
Accessors
backward
Get Signature
get
staticbackward():Vector3
Defined in: math/vector3.ts:84
A unit vector pointing backward (0, 0, -1). A fresh vector is created on every access, so it's always safe to mutate.
Returns
down
Get Signature
get
staticdown():Vector3
Defined in: math/vector3.ts:52
A unit vector pointing downward (0, -1, 0). A fresh vector is created on every access, so it's always safe to mutate.
Returns
forward
Get Signature
get
staticforward():Vector3
Defined in: math/vector3.ts:76
A unit vector pointing forward (0, 0, 1). A fresh vector is created on every access, so it's always safe to mutate.
Returns
left
Get Signature
get
staticleft():Vector3
Defined in: math/vector3.ts:60
A unit vector pointing left (-1, 0, 0). A fresh vector is created on every access, so it's always safe to mutate.
Returns
one
Get Signature
get
staticone():Vector3
Defined in: math/vector3.ts:36
A vector with components of 1 (1, 1, 1). A fresh vector is created on every access, so it's always safe to mutate.
Returns
right
Get Signature
get
staticright():Vector3
Defined in: math/vector3.ts:68
A unit vector pointing right (1, 0, 0). A fresh vector is created on every access, so it's always safe to mutate.
Returns
up
Get Signature
get
staticup():Vector3
Defined in: math/vector3.ts:44
A unit vector pointing upward (0, 1, 0). A fresh vector is created on every access, so it's always safe to mutate.
Returns
zero
Get Signature
get
staticzero():Vector3
Defined in: math/vector3.ts:28
A zero vector (0, 0, 0). A fresh vector is created on every access, so it's always safe to mutate.
Returns
Methods
add()
staticadd(target,value):Vector3
Defined in: math/vector3.ts:108
Adds another vector into target, mutating it in place.
Parameters
target
The vector to mutate.
value
The vector to add.
Returns
target, for chaining.
clone()
staticclone(vector):Vector3
Defined in: math/vector3.ts:225
Creates a deep copy of a vector.
Parameters
vector
The vector to copy.
Returns
A new Vector3 with the same component values.
divide()
staticdivide(target,scalar):Vector3
Defined in: math/vector3.ts:164
Divides target by a scalar value, mutating it in place.
Parameters
target
The vector to mutate.
scalar
number
The scalar value to divide by.
Returns
target, for chaining.
equals()
staticequals(a,b):boolean
Defined in: math/vector3.ts:244
Checks if two vectors are equal.
Parameters
a
The first vector.
b
The second vector.
Returns
boolean
True if the vectors have the same components, false otherwise.
floorComponents()
staticfloorComponents(target):Vector3
Defined in: math/vector3.ts:212
Rounds target's components down to the nearest integer, mutating it in place.
Parameters
target
The vector to mutate.
Returns
target, for chaining.
magnitude()
staticmagnitude(vector):number
Defined in: math/vector3.ts:187
Calculates the magnitude (length) of a vector.
Parameters
vector
The vector.
Returns
number
The magnitude of the vector.
magnitudeSquared()
staticmagnitudeSquared(vector):number
Defined in: math/vector3.ts:178
Calculates the squared magnitude of a vector. This is faster than Vec3.magnitude as it avoids the square root.
Parameters
vector
The vector.
Returns
number
The squared magnitude of the vector.
multiply()
staticmultiply(target,scalar):Vector3
Defined in: math/vector3.ts:136
Multiplies target by a scalar value, mutating it in place.
Parameters
target
The vector to mutate.
scalar
number
The scalar value to multiply by.
Returns
target, for chaining.
multiplyComponents()
staticmultiplyComponents(target,value):Vector3
Defined in: math/vector3.ts:150
Multiplies target's components by another vector's components, mutating it in place.
Parameters
target
The vector to mutate.
value
The vector to multiply components with.
Returns
target, for chaining.
normalize()
staticnormalize(target):Vector3
Defined in: math/vector3.ts:197
Normalizes target to unit length in the same direction, mutating it in place.
Parameters
target
The vector to mutate.
Returns
target, for chaining.
Throws
An error if target has zero length, since its direction is undefined.
set()
staticset(target,value):Vector3
Defined in: math/vector3.ts:94
Sets a vector's components to match another vector, mutating it in place.
Parameters
target
The vector to mutate.
value
The vector to copy components from.
Returns
target, for chaining.
subtract()
staticsubtract(target,value):Vector3
Defined in: math/vector3.ts:122
Subtracts another vector from target, mutating it in place.
Parameters
target
The vector to mutate.
value
The vector to subtract.
Returns
target, for chaining.
toFloat32Array()
statictoFloat32Array(vector):Float32Array
Defined in: math/vector3.ts:253
Converts a vector to a glsl-compatible float32 array.
Parameters
vector
The vector.
Returns
Float32Array
The 3d vector array (e.g. [5, 3, 8] for { x: 5, y: 3, z: 8 }).
toString()
statictoString(vector):string
Defined in: math/vector3.ts:234
Returns a string representation of a vector.
Parameters
vector
The vector.
Returns
string
A string in the format "(x, y, z)" with components rounded to 1 decimal place.