diff options
author | Julian T <julian@jtle.dk> | 2021-01-31 17:21:11 +0100 |
---|---|---|
committer | Julian T <julian@jtle.dk> | 2021-01-31 17:21:11 +0100 |
commit | c4369f86c920888bfaa00e46d74e3f5a1872a9ab (patch) | |
tree | 0bbfa3fa0d6db98b43b3854034def7f028a7a847 /src/scene/scene.rs | |
parent | 86303936ab3180828b984ebb256bab8e69dab5cf (diff) |
Add Scene type and Sphere intersect
Diffstat (limited to 'src/scene/scene.rs')
-rw-r--r-- | src/scene/scene.rs | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/src/scene/scene.rs b/src/scene/scene.rs new file mode 100644 index 0000000..a2f5b88 --- /dev/null +++ b/src/scene/scene.rs @@ -0,0 +1,38 @@ +use super::shapes::Shape; +use crate::Float; +use crate::core::Ray; + +pub struct Scene { + shps: Vec<Box<dyn Shape>>, +} + +pub struct Intersection<'a> { + pub shp: &'a dyn Shape, + pub t: Float, +} + +impl Scene { + pub fn new() -> Self { + Self { + shps: Vec::new(), + } + } + + pub fn add_shape(&mut self, shp: Box<dyn Shape>) { + self.shps.push(shp); + } + + pub fn intersect(&self, ray: Ray) -> Option<Intersection> { + for shp in self.shps.iter() { + if let Some(t) = shp.intersect(&ray) { + return Some(Intersection { + shp: shp.as_ref(), + t, + }) + } + } + + None + } +} + |