use crate::hittable::{Hit, Hittable}; use crate::ray::Ray; pub struct Scene { objects: Vec>, } impl Scene { pub fn new() -> Scene { Scene { objects: Vec::new(), } } pub fn add(&mut self, obj: Box) { self.objects.push(obj) } pub fn clear(&mut self) { self.objects = Vec::new() } } impl Hittable for Scene { fn is_hit(&self, ray: &Ray, t_min: f64, t_max: f64) -> Option { let mut closest_so_far = t_max; let mut hit = None; for obj in self.objects.iter() { if let Some(h) = obj.is_hit(ray, t_min, closest_so_far) { closest_so_far = h.t; hit = Some(h); } } hit } }