/** * An infinite ray. Rays are commonly used for picking, raycasting and intersection tests. * * A ray is an {@link origin} and a {@link direction}. It performs no intersection itself: pass it * to the `intersectsRay` method of a {@link BoundingBox}, {@link BoundingSphere}, * {@link OrientedBox}, {@link Plane} or {@link Tri}. Keep the direction normalized, as those tests * require it. The constructor copies the vectors it is given, and {@link set} updates both in * place. * * @example * // A ray from the camera through a screen position * const ray = new Ray(); * entity.camera.screenToWorld(x, y, entity.camera.nearClip, ray.origin); * entity.camera.screenToWorld(x, y, entity.camera.farClip, ray.direction); * ray.direction.sub(ray.origin).normalize(); * @category Math */ export class Ray { /** * Creates a new Ray instance. The ray is infinite, starting at a given origin and pointing in * a given direction. * * @param {Vec3} [origin] - The starting point of the ray. The constructor copies * this parameter. Defaults to the origin (0, 0, 0). * @param {Vec3} [direction] - The direction of the ray. The constructor copies * this parameter. Defaults to a direction down the world negative Z axis (0, 0, -1). * @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); */ constructor(origin?: Vec3, direction?: Vec3); /** * The starting point of the ray. * * @readonly * @type {Vec3} */ readonly origin: Vec3; /** * The direction of the ray. * * @readonly * @type {Vec3} */ readonly direction: Vec3; /** * Sets origin and direction to the supplied vector values. * * @param {Vec3} origin - The starting point of the ray. * @param {Vec3} direction - The direction of the ray. * @returns {Ray} Self for chaining. */ set(origin: Vec3, direction: Vec3): Ray; /** * Copies the contents of a source Ray. * * @param {Ray} src - The Ray to copy from. * @returns {Ray} Self for chaining. */ copy(src: Ray): Ray; /** * Returns a clone of the Ray. * * @returns {this} A duplicate Ray. */ clone(): this; } import { Vec3 } from '../math/vec3.js';