Skip to content

@web-engine-dev/math


@web-engine-dev/math / Frustum

Class: Frustum ​

A view frustum defined by 6 planes. Used for frustum culling. Planes face inward (positive half-space is inside the frustum).

Example ​

ts
const viewProj = projMatrix.mulMat(viewMatrix);
const frustum = Frustum.fromViewProjection(viewProj);

// Cull objects outside the frustum
if (frustum.intersectsBox(object.bounds) !== FrustumIntersection.Outside) {
  render(object);
}

Constructors ​

Constructor ​

new Frustum(planes): Frustum

Creates a frustum from 6 planes. Order: left, right, bottom, top, near, far.

Parameters ​

planes ​

[Plane, Plane, Plane, Plane, Plane, Plane]

Returns ​

Frustum

Properties ​

planes ​

readonly planes: readonly [Plane, Plane, Plane, Plane, Plane, Plane]

Accessors ​

bottom ​

Get Signature ​

get bottom(): Plane

Returns ​

Plane


far ​

Get Signature ​

get far(): Plane

Returns ​

Plane


left ​

Get Signature ​

get left(): Plane

Returns ​

Plane


near ​

Get Signature ​

get near(): Plane

Returns ​

Plane


Get Signature ​

get right(): Plane

Returns ​

Plane


top ​

Get Signature ​

get top(): Plane

Returns ​

Plane

Methods ​

containsPoint() ​

containsPoint(point): boolean

Tests if a point is inside the frustum.

Parameters ​

point ​

Vec3

Returns ​

boolean


cullBox() ​

cullBox(box): boolean

Fast AABB culling test (just checks if outside). This is the most common operation for frustum culling.

Parameters ​

box ​

AABB

Returns ​

boolean


cullSphere() ​

cullSphere(center, radius): boolean

Fast sphere culling test (just checks if outside).

Parameters ​

center ​

Vec3

radius ​

number

Returns ​

boolean


getCorners() ​

getCorners(): Vec3[]

Computes the 8 corners of the frustum. Useful for debug visualization.

Returns ​

Vec3[]


intersectsBox() ​

intersectsBox(box): FrustumIntersection

Tests if an AABB intersects or is inside the frustum. Zero-allocation: uses inline scalar math instead of constructing Vec3.

Parameters ​

box ​

AABB

Returns ​

FrustumIntersection


intersectsCorners() ​

intersectsCorners(corners): FrustumIntersection

Tests if an oriented bounding box (8 corners) is inside the frustum.

Parameters ​

corners ​

Vec3[]

Returns ​

FrustumIntersection


intersectsSphere() ​

intersectsSphere(center, radius): FrustumIntersection

Tests if a sphere intersects or is inside the frustum.

Parameters ​

center ​

Vec3

radius ​

number

Returns ​

FrustumIntersection


setFromViewProjectionMut() ​

setFromViewProjectionMut(viewProjection): this

Updates this frustum from a view-projection matrix (no allocations).

Parameters ​

viewProjection ​

Mat4

Returns ​

this


toString() ​

toString(): string

Returns ​

string


fromPerspective() ​

static fromPerspective(fovY, aspect, near, far, viewMatrix): Frustum

Creates a frustum from perspective parameters.

Parameters ​

fovY ​

number

aspect ​

number

near ​

number

far ​

number

viewMatrix ​

Mat4

Returns ​

Frustum


fromViewProjection() ​

static fromViewProjection(viewProjection): Frustum

Creates a frustum from a view-projection matrix. The matrix should be the combined projection * view matrix.

Parameters ​

viewProjection ​

Mat4

Returns ​

Frustum


fromViewProjectionOut() ​

static fromViewProjectionOut(viewProjection, out): Frustum

Updates an existing frustum from a view-projection matrix (no allocations).

Parameters ​

viewProjection ​

Mat4

out ​

Frustum

Returns ​

Frustum

Proprietary software. All rights reserved.