pub struct Frustum { /* private fields */ }Expand description
Six-plane view frustum extracted from a view-projection matrix.
Constructed via from_view_projection,
then queried with one of the intersection methods. The plane order is
[left, right, bottom, top, near, far] and is accessible through
planes() or the PLANE_* index constants.
§When to rebuild
Rebuild every frame (or whenever the camera moves). Construction is six normalisations – negligible compared to the tile-selection loop it gates.
Implementations§
Source§impl Frustum
impl Frustum
Sourcepub fn from_view_projection(vp: &DMat4) -> Self
pub fn from_view_projection(vp: &DMat4) -> Self
Extract the 6 frustum planes from a combined view-projection matrix.
Uses the Gribb/Hartmann row-combination method:
left = row3 + row0 right = row3 - row0
bottom = row3 + row1 top = row3 - row1
near = row3 + row2 far = row3 - row2Each raw plane (a, b, c, d) is then normalised by dividing by
sqrt(a^2 + b^2 + c^2) so that distance_to_point returns a
true metric distance. Degenerate planes (norm < 1e-15) are left
as all-zeros, which makes them pass all intersection tests (safe
conservative default).
Sourcepub fn planes(&self) -> &[Plane; 6]
pub fn planes(&self) -> &[Plane; 6]
Access the six frustum planes: [left, right, bottom, top, near, far].
Sourcepub fn contains_point(&self, point: &WorldCoord) -> bool
pub fn contains_point(&self, point: &WorldCoord) -> bool
Test whether a single point is inside the frustum.
Returns true if the point is on the inside (or boundary) of
every frustum plane. Useful for quick single-coordinate checks
such as cursor hit-testing or model anchor visibility.
Sourcepub fn intersects_sphere(&self, center: &WorldCoord, radius: f64) -> bool
pub fn intersects_sphere(&self, center: &WorldCoord, radius: f64) -> bool
Test whether a bounding sphere intersects the frustum.
Returns true if the sphere (defined by a centre point and
radius in meters) is at least partially inside. Preferred over
AABB for rotated 3D models where the axis-aligned box would be
excessively loose.
When radius == 0.0 this degrades to a point-containment test.
Conservative: may return true for spheres that only overlap a
frustum corner region without actually intersecting the volume.
Sourcepub fn intersects_aabb(&self, bounds: &WorldBounds) -> bool
pub fn intersects_aabb(&self, bounds: &WorldBounds) -> bool
Test whether an axis-aligned bounding box intersects the frustum.
Uses the “p-vertex” (positive vertex) optimisation: for each plane, only the single AABB corner most aligned with the plane normal is tested. If that corner is outside, the entire box is outside.
Returns true if the AABB is at least partially inside.
Conservative: may return true for boxes near frustum corners that
are geometrically outside the exact frustum volume.