playcanvas
Version:
PlayCanvas WebGL game engine
78 lines (77 loc) • 2.87 kB
TypeScript
/**
* @import { BoundingSphere } from './bounding-sphere.js'
* @import { Mat4 } from '../math/mat4.js'
* @import { Vec3 } from '../math/vec3.js'
*/
/**
* A frustum is a shape that defines the viewing space of a camera. It can be used to determine
* visibility of points and bounding spheres. Typically, you would not create a Frustum shape
* directly, but instead query {@link CameraComponent#frustum}.
*
* @category Math
*/
export class Frustum {
/**
* The six planes that make up the frustum.
*
* @type {Plane[]}
*/
planes: Plane[];
/**
* Returns a clone of the specified frustum.
*
* @returns {Frustum} A duplicate frustum.
* @example
* const frustum = new pc.Frustum();
* const clone = frustum.clone();
*/
clone(): Frustum;
/**
* Copies the contents of a source frustum to a destination frustum.
*
* @param {Frustum} src - A source frustum to copy to the destination frustum.
* @returns {Frustum} Self for chaining.
* @example
* const src = entity.camera.frustum;
* const dst = new pc.Frustum();
* dst.copy(src);
*/
copy(src: Frustum): Frustum;
/**
* Updates the frustum shape based on the supplied 4x4 matrix.
*
* @param {Mat4} matrix - The matrix describing the shape of the frustum.
* @example
* // Create a perspective projection matrix
* const projection = pc.Mat4();
* projection.setPerspective(45, 16 / 9, 1, 1000);
*
* // Create a frustum shape that is represented by the matrix
* const frustum = new pc.Frustum();
* frustum.setFromMat4(projection);
*/
setFromMat4(matrix: Mat4): void;
/**
* Tests whether a point is inside the frustum. Note that points lying in a frustum plane are
* considered to be outside the frustum.
*
* @param {Vec3} point - The point to test.
* @returns {boolean} True if the point is inside the frustum, false otherwise.
*/
containsPoint(point: Vec3): boolean;
/**
* Tests whether a bounding sphere intersects the frustum. If the sphere is outside the
* frustum, zero is returned. If the sphere intersects the frustum, 1 is returned. If the
* sphere is completely inside the frustum, 2 is returned. Note that a sphere touching a
* frustum plane from the outside is considered to be outside the frustum.
*
* @param {BoundingSphere} sphere - The sphere to test.
* @returns {number} 0 if the bounding sphere is outside the frustum, 1 if it intersects the
* frustum and 2 if it is contained by the frustum.
*/
containsSphere(sphere: BoundingSphere): number;
}
import { Plane } from './plane.js';
import type { Mat4 } from '../math/mat4.js';
import type { Vec3 } from '../math/vec3.js';
import type { BoundingSphere } from './bounding-sphere.js';