pub struct Frustum { /* private fields */ }Expand description
Six normalized inward-facing planes using WebGPU’s 0..1 clip-depth convention.
Implementations§
Source§impl Frustum
impl Frustum
Sourcepub fn from_matrix(matrix: [f32; 16]) -> Result<Self, RenderError>
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}Sourcepub fn planes(&self) -> &[[f32; 4]; 6]
pub fn planes(&self) -> &[[f32; 4]; 6]
Normalized planes, ordered left/right/bottom/top/near/far.
Sourcepub fn intersects(&self, sphere: BoundingSphere) -> Result<bool, RenderError>
pub fn intersects(&self, sphere: BoundingSphere) -> Result<bool, RenderError>
Conservative CPU reference, including a scale-aware rounding margin.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Frustum
impl RefUnwindSafe for Frustum
impl Send for Frustum
impl Sync for Frustum
impl Unpin for Frustum
impl UnsafeUnpin for Frustum
impl UnwindSafe for Frustum
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more