aboutsummaryrefslogtreecommitdiff
path: root/src/world/scene.rs
diff options
context:
space:
mode:
authorJulian T <julian@jtle.dk>2021-02-21 18:01:56 +0100
committerJulian T <julian@jtle.dk>2021-02-21 18:01:56 +0100
commitda1c3949a449f3fafe579c62ff6b14ffd993a197 (patch)
tree754df5c9b5e9f0fa0a8bb7a8cd3dd4b12fe5ad89 /src/world/scene.rs
parentc695da871a75bb6786c08c3546ef71ed032bd61d (diff)
Add 3d bounding box and merged SceneIntersection and Intersection
Diffstat (limited to 'src/world/scene.rs')
-rw-r--r--src/world/scene.rs33
1 files changed, 9 insertions, 24 deletions
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<Object>,
-}
-
-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<Object>) {
@@ -26,27 +20,18 @@ impl Scene {
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 Hittable for Scene {
+ fn intersect(&self, ray: &Ray) -> Option<Intersection> {
+ self.content.intersect(ray)
}
}
impl Default for Scene {
fn default() -> Self {
Self {
- objs: Vec::new(),
+ content: HittableList::new(),
}
}
}