How To

Mirror Engine API / Ray
Class: Ray
An infinite ray.
Constructors
new Ray()
new Ray(origin?: Vec3, direction?: Vec3): Ray
Creates a new Ray instance. The ray is infinite, starting at a given origin and pointing in a given direction.
Parameters
origin?
The starting point of the ray. The constructor copies this parameter. Defaults to the origin (0, 0, 0).
direction?
The direction of the ray. The constructor copies this parameter. Defaults to a direction down the world negative Z axis (0, 0, -1).
Returns
Example
// Create a new ray starting at the position of this entity and pointing down
// the entity's negative Z axis
const ray = new Ray(this.entity.getPosition(), this.entity.forward)
Properties
direction
readonly direction: Vec3;
The direction of the ray.
origin
readonly origin: Vec3;
The starting point of the ray.
Methods
clone()
clone(): Ray
Returns a clone of the Ray.
Returns
A duplicate Ray.
copy()
copy(src: Ray): Ray
Copies the contents of a source Ray.
Parameters
src
The Ray to copy from.
Returns
Self for chaining.
set()
set(origin: Vec3, direction: Vec3): Ray
Sets origin and direction to the supplied vector values.
Parameters
origin
The starting point of the ray.
direction
The direction of the ray.
Returns
Self for chaining.