
Mirror Engine API / Frustum
Class: Frustum
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 CameraComponent#frustum.
Constructors
new Frustum()
new Frustum(): Frustum
Create a new Frustum instance.
Returns
Example
const frustum = new Frustum()
Properties
planes
planes: Plane[] = [];
The six planes that make up the frustum.
Methods
clone()
clone(): Frustum
Returns a clone of the specified frustum.
Returns
A duplicate frustum.
Example
const frustum = new Frustum()
const clone = frustum.clone()
containsPoint()
containsPoint(point: Vec3): boolean
Tests whether a point is inside the frustum. Note that points lying in a frustum plane are considered to be outside the frustum.
Parameters
point
The point to test.
Returns
boolean
True if the point is inside the frustum, false otherwise.
containsSphere()
containsSphere(sphere: BoundingSphere): number
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.
Parameters
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.
copy()
copy(src: Frustum): Frustum
Copies the contents of a source frustum to a destination frustum.
Parameters
src
A source frustum to copy to the destination frustum.
Returns
Self for chaining.
Example
const src = entity.camera.frustum
const dst = new Frustum()
dst.copy(src)
setFromMat4()
setFromMat4(matrix: Mat4): void
Updates the frustum shape based on the supplied 4x4 matrix.
Parameters
matrix
The matrix describing the shape of the frustum.
Returns
void
Example
// Create a perspective projection matrix
const projection = Mat4()
projection.setPerspective(45, 16 / 9, 1, 1000)
// Create a frustum shape that is represented by the matrix
const frustum = new Frustum()
frustum.setFromMat4(projection)