From da1c3949a449f3fafe579c62ff6b14ffd993a197 Mon Sep 17 00:00:00 2001 From: Julian T Date: Sun, 21 Feb 2021 18:01:56 +0100 Subject: Add 3d bounding box and merged SceneIntersection and Intersection --- src/world/scene.rs | 33 +++++++++------------------------ 1 file changed, 9 insertions(+), 24 deletions(-) (limited to 'src/world/scene.rs') diff --git a/src/world/scene.rs b/src/world/scene.rs index 444e915..03578be 100644 --- a/src/world/scene.rs +++ b/src/world/scene.rs @@ -1,15 +1,9 @@ -use crate::core::{Ray, Intersection}; -use crate::material::Material; +use crate::core::Ray; -use super::Object; +use super::{Object, HittableList, Hittable, Intersection}; pub struct Scene { - objs: Vec, -} - -pub struct SceneIntersect<'a> { - pub mat: &'a dyn Material, - pub i: Intersection, + content: HittableList, } impl Scene { @@ -18,7 +12,7 @@ impl Scene { } pub fn add_object(&mut self, obj: Object) { - self.objs.push(obj); + self.content.add(Box::new(obj)); } pub fn add_objects(&mut self, objs: Vec) { @@ -26,27 +20,18 @@ impl Scene { self.add_object(obj); } } +} - pub fn intersect(&self, ray: &Ray) -> Option { - let mut min: Option = None; - - for obj in self.objs.iter() { - if let Some(i) = obj.shape.intersect(&ray) { - match min { - Some(ref si) if si.i.t < i.t => (), - _ => min = Some(SceneIntersect {i, mat: obj.mat.as_ref() }), - } - } - } - - min +impl Hittable for Scene { + fn intersect(&self, ray: &Ray) -> Option { + self.content.intersect(ray) } } impl Default for Scene { fn default() -> Self { Self { - objs: Vec::new(), + content: HittableList::new(), } } } -- cgit v1.2.3