vec3
Interface representing a 3D vector. A 3D vector is represented by (x, y, z) coordinates, and can represent a point in space, a directional vector, or other types of data with three ordered dimensions. 3D vectors can be multiplied by 4x4 matrices (Mat4) using homogeneous coordinate math, enabling efficient 3D geometry computation. Vec3 objects are created with the ecs.math.vec3 Vec3Factory, or through operations on other Vec3 objects.
Source
The Vec3Source interface represents any object that has x, y, and z properties and hence can be used as a data source to create a Vec3. In addition, Vec3Source can be used as an argument to Vec3 algorithms, meaning that any object with {x: number, y: number, z: number} properties can be used.
Properties
Vec3 has the following enumerable properties:
readonly x: number
Access the x component of the vector.
readonly y: number
Access the y component of the vector.
readonly z: number
Access the z component of the vector.
Factory
from
Create a Vec3 from a Vec3, or other object with x, y properties.
ecs.math.vec3.from({x, y}: {x: number, y: number, z: number}}) // -> vec3
one
Create a vec3 where all elements are set to one. This is equivalent to vec3.from({x: 1, y: 1, z: 1})
.
ecs.math.vec3.one() // -> vec3
scale
Create a vec3 with all elements set to the scale value s. This is equivalent to vec3.from({x: s, y: s, z: s})
.
ecs.math.vec3.scale(s: number) // -> vec3
xyz
Create a Vec3 from x, y, z values. This is equivalent to vec3.from({x, y, z})
.
ecs.math.vec3.xyz(x: number, y: number, z: number) // -> vec3
zero
Create a vec3 where all elements are set to zero. This is equivalent to vec3.from({x: 0, y: 0, z: 0})
.
ecs.math.vec3.zero() // -> vec3
Immutable
The following methods perform computations based on the current value of a Vec3, but do not modify its contents. Methods that return Vec3 types return new objects. Immutable APIs are typically safer, more readable, and less error-prone than mutable APIs, but may be inefficient in situations where thousands of objects are allocated each frame.
If garbage collection impacts performance, consider using the Mutable API described below.
clone
Create a new vector with the same components as this vector.
existingVec3.clone() // -> vec3
cross
Compute the cross product of this vector and another vector.
existingVec3.cross(v: Vec3Source) // -> vec3