@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
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
readonlyplanes: readonly [Plane,Plane,Plane,Plane,Plane,Plane]
Accessors
bottom
Get Signature
get bottom():
Plane
Returns
far
Get Signature
get far():
Plane
Returns
left
Get Signature
get left():
Plane
Returns
near
Get Signature
get near():
Plane
Returns
right
Get Signature
get right():
Plane
Returns
top
Get Signature
get top():
Plane
Returns
Methods
containsPoint()
containsPoint(
point):boolean
Tests if a point is inside the frustum.
Parameters
point
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
Returns
boolean
cullSphere()
cullSphere(
center,radius):boolean
Fast sphere culling test (just checks if outside).
Parameters
center
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
Returns
intersectsCorners()
intersectsCorners(
corners):FrustumIntersection
Tests if an oriented bounding box (8 corners) is inside the frustum.
Parameters
corners
Vec3[]
Returns
intersectsSphere()
intersectsSphere(
center,radius):FrustumIntersection
Tests if a sphere intersects or is inside the frustum.
Parameters
center
radius
number
Returns
setFromViewProjectionMut()
setFromViewProjectionMut(
viewProjection):this
Updates this frustum from a view-projection matrix (no allocations).
Parameters
viewProjection
Returns
this
toString()
toString():
string
Returns
string
fromPerspective()
staticfromPerspective(fovY,aspect,near,far,viewMatrix):Frustum
Creates a frustum from perspective parameters.
Parameters
fovY
number
aspect
number
near
number
far
number
viewMatrix
Returns
Frustum
fromViewProjection()
staticfromViewProjection(viewProjection):Frustum
Creates a frustum from a view-projection matrix. The matrix should be the combined projection * view matrix.
Parameters
viewProjection
Returns
Frustum
fromViewProjectionOut()
staticfromViewProjectionOut(viewProjection,out):Frustum
Updates an existing frustum from a view-projection matrix (no allocations).
Parameters
viewProjection
out
Frustum
Returns
Frustum