mechthild/core/src/scene.rs
wires d8a88e81c8
more radical reorganization!
rendering is now performed in a separate thread. this is of little use
now but lays the groundwork for adding parallel rendering. i just need
to think about data ownership a little harder to make the tile renderer
nice.
2025-06-01 00:21:11 -04:00

26 lines
538 B
Rust

use crate::{
Shape,
geometry::{Hit, Hittable, Ray},
};
#[derive(Debug, Clone)]
pub struct Scene(Vec<Shape>);
impl Scene {
pub fn new(objects: Vec<Shape>) -> Self {
Self(objects)
}
pub fn intersect(&self, r: Ray) -> Option<Hit> {
let mut hit: Option<Hit> = None;
for obj in &self.0 {
let t_max = hit.as_ref().map(|h| h.t).unwrap_or(f32::INFINITY);
if let Some(h) = obj.intersect(&r, t_max) {
hit = Some(h)
}
}
hit
}
}