Skip to main content

Frustum

Struct Frustum 

Source
pub struct Frustum { /* private fields */ }
Expand description

Six normalized inward-facing planes using WebGPU’s 0..1 clip-depth convention.

Implementations§

Source§

impl Frustum

Source

pub fn from_matrix(matrix: [f32; 16]) -> Result<Self, RenderError>

Extract from a finite column-major world-to-clip matrix, with explicit normalization.

Examples found in repository?
examples/lod.rs (lines 45-62)
13fn main() -> Result<(), RenderError> {
14    let mut levels = [
15        LodLevel {
16            index_count: 24,
17            first_index: 0,
18            base_vertex: 0,
19            geometric_error: 0.,
20            resident: true,
21        },
22        LodLevel {
23            index_count: 6,
24            first_index: 24,
25            base_vertex: 9,
26            geometric_error: 0.22,
27            resident: true,
28        },
29        LodLevel {
30            index_count: 3,
31            first_index: 30,
32            base_vertex: 13,
33            geometric_error: 0.3,
34            resident: true,
35        },
36    ];
37    let view = LodView {
38        eye: [0.; 3],
39        forward: [0., 0., -1.],
40        near_distance: 0.1,
41        focal_pixels: 256.,
42        viewport_half_diagonal: 363.,
43        maximum_error_pixels: 32.,
44    };
45    let frustum = Frustum::from_matrix([
46        1.,
47        0.,
48        0.,
49        0.,
50        0.,
51        1.,
52        0.,
53        0.,
54        0.,
55        0.,
56        100. / (-99.9),
57        -1.,
58        0.,
59        0.,
60        10. / (-99.9),
61        0.,
62    ])?;
63    let objects = [[-1.2, 0., -2.], [0., 0., -5.], [6., 0., -10.]].map(|center| LodObject {
64        bounds: BoundingSphere {
65            center,
66            radius: 0.5,
67        },
68        max_scale: 1.,
69    });
70    for resident in [true, false, true] {
71        levels[1].resident = resident;
72        let choices = objects
73            .into_iter()
74            .map(|object| choose_lod(&levels, object, view, frustum))
75            .collect::<Result<Vec<_>, _>>()?;
76        println!("middle_resident={resident} choices={choices:?}");
77    }
78    Ok(())
79}
Source

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

Normalized planes, ordered left/right/bottom/top/near/far.

Source

pub fn intersects(&self, sphere: BoundingSphere) -> Result<bool, RenderError>

Conservative CPU reference, including a scale-aware rounding margin.

Trait Implementations§

Source§

impl Clone for Frustum

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Copy for Frustum

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 = !

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

fn try_from(value: U) -> Result<T, !>

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.