Skip to main content

Frustum

Struct Frustum 

Source
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

Source

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 - row2

Each 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).

Source

pub fn planes(&self) -> &[Plane; 6]

Access the six frustum planes: [left, right, bottom, top, near, far].

Source

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.

Source

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.

Source

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.

Trait Implementations§

Source§

impl Clone for Frustum

Source§

fn clone(&self) -> Frustum

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Frustum

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.