/** * An oriented bounding box is a box that can be rotated and translated in 3D space. It is defined * by a world transform and half extents. Unlike an axis-aligned bounding box, an OBB can be * oriented arbitrarily. * * The constructor takes a {@link Mat4} holding the box's position and rotation, then its half * extents. Scale is assumed to be one, so size the box with the half extents rather than the * matrix. {@link worldTransform} can be reassigned at any time and the setter copies the matrix, so * assigning an entity's world transform each frame gives a box that follows it. The tests * {@link containsPoint}, {@link intersectsRay} and {@link intersectsBoundingSphere} return a * boolean and allocate nothing. * * @example * // A 2 x 1 x 4 box that follows an entity * const box = new OrientedBox(entity.getWorldTransform(), new Vec3(1, 0.5, 2)); * * // later, after the entity has moved * box.worldTransform = entity.getWorldTransform(); * if (box.containsPoint(player.getPosition())) { * // the player is inside the box * } * @category Math */ export class OrientedBox { /** * Create a new OrientedBox instance. * * @param {Mat4} [worldTransform] - Transform that has the orientation and position of the box. * Scale is assumed to be one. Defaults to identity matrix. * @param {Vec3} [halfExtents] - Half the distance across the box in each local axis. Defaults * to (0.5, 0.5, 0.5). */ constructor(worldTransform?: Mat4, halfExtents?: Vec3); /** @private */ private halfExtents; /** * @type {Mat4} * @private */ private _modelTransform; /** * @type {Mat4} * @private */ private _worldTransform; /** * @type {BoundingBox} * @private */ private _aabb; /** * Sets the world transform of the OBB. * * @type {Mat4} */ set worldTransform(value: Mat4); /** * Gets the world transform of the OBB. * * @type {Mat4} */ get worldTransform(): Mat4; /** * Test if a ray intersects with the OBB. * * @param {Ray} ray - Ray to test against (direction must be normalized). * @param {Vec3} [point] - If there is an intersection, the intersection point will be copied * into here. * @returns {boolean} True if there is an intersection. */ intersectsRay(ray: Ray, point?: Vec3): boolean; /** * Test if a point is inside an OBB. * * @param {Vec3} point - Point to test. * @returns {boolean} True if the point is inside the OBB and false otherwise. */ containsPoint(point: Vec3): boolean; /** * Test if a Bounding Sphere is overlapping, enveloping, or inside this OBB. * * @param {BoundingSphere} sphere - Bounding Sphere to test. * @returns {boolean} True if the Bounding Sphere is overlapping, enveloping or inside this OBB * and false otherwise. */ intersectsBoundingSphere(sphere: BoundingSphere): boolean; } import { Mat4 } from '../math/mat4.js'; import { Ray } from './ray.js'; import { Vec3 } from '../math/vec3.js'; import { BoundingSphere } from './bounding-sphere.js';