diff options
author | Julian T <julian@jtle.dk> | 2021-02-10 23:06:48 +0100 |
---|---|---|
committer | Julian T <julian@jtle.dk> | 2021-02-10 23:06:48 +0100 |
commit | 49c6adb0db70ffc30eaac33b66eacf7574b34e26 (patch) | |
tree | 60f828ce8abf962fe2d88fdeb4e04db1d7663253 /src/world/scene.rs | |
parent | 3a144c8c1fc83150fc06d792082db5cc4bce3cc5 (diff) |
Fixed most clippy warnings
Diffstat (limited to 'src/world/scene.rs')
-rw-r--r-- | src/world/scene.rs | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/src/world/scene.rs b/src/world/scene.rs new file mode 100644 index 0000000..444e915 --- /dev/null +++ b/src/world/scene.rs @@ -0,0 +1,52 @@ +use crate::core::{Ray, Intersection}; +use crate::material::Material; + +use super::Object; + +pub struct Scene { + objs: Vec<Object>, +} + +pub struct SceneIntersect<'a> { + pub mat: &'a dyn Material, + pub i: Intersection, +} + +impl Scene { + pub fn new() -> Self { + Self::default() + } + + pub fn add_object(&mut self, obj: Object) { + self.objs.push(obj); + } + + pub fn add_objects(&mut self, objs: Vec<Object>) { + for obj in objs { + self.add_object(obj); + } + } + + pub fn intersect(&self, ray: &Ray) -> Option<SceneIntersect> { + let mut min: Option<SceneIntersect> = 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 Default for Scene { + fn default() -> Self { + Self { + objs: Vec::new(), + } + } +} |