From 0d5e6bd9363d5ed5c4f28174819fc0f5fd9aa586 Mon Sep 17 00:00:00 2001 From: Julian T Date: Sat, 6 Feb 2021 17:27:42 +0100 Subject: Reorganized scene module, and fixed bug in sphere intersect --- src/scene/scene.rs | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) (limited to 'src/scene/scene.rs') diff --git a/src/scene/scene.rs b/src/scene/scene.rs index 33a7613..367003e 100644 --- a/src/scene/scene.rs +++ b/src/scene/scene.rs @@ -1,14 +1,10 @@ -use super::shapes::Shape; -use crate::Float; +use super::{Intersection, Hittable}; use crate::core::Ray; -pub struct Scene { - shps: Vec>, -} +type Shape = Box; -pub struct Intersection<'a> { - pub shp: &'a dyn Shape, - pub t: Float, +pub struct Scene { + shps: Vec, } impl Scene { @@ -18,17 +14,20 @@ impl Scene { } } - pub fn add_shape(&mut self, shp: Box) { + pub fn add_shape(&mut self, shp: Shape) { self.shps.push(shp); } + pub fn add_shapes(&mut self, shps: Vec) { + for shp in shps { + self.add_shape(shp); + } + } + pub fn intersect(&self, ray: &Ray) -> Option { for shp in self.shps.iter() { - if let Some(t) = shp.intersect(&ray) { - return Some(Intersection { - shp: shp.as_ref(), - t, - }) + if let Some(i) = shp.intersect(&ray) { + return Some(i) } } -- cgit v1.2.3