aboutsummaryrefslogtreecommitdiff
path: root/src/scene/scene.rs
diff options
context:
space:
mode:
authorJulian T <julian@jtle.dk>2021-02-07 14:25:06 +0100
committerJulian T <julian@jtle.dk>2021-02-07 14:26:20 +0100
commit33e747fa1c0957546c10e4d7b490ac7fbb0fd2d2 (patch)
tree515b2b2e017329cbcada60e898fb5795fbceb5cd /src/scene/scene.rs
parenta43ab40a75e9d4c6ee3fbdd583bc93574db19124 (diff)
Abstracted lambertian into material
Diffstat (limited to 'src/scene/scene.rs')
-rw-r--r--src/scene/scene.rs28
1 files changed, 14 insertions, 14 deletions
diff --git a/src/scene/scene.rs b/src/scene/scene.rs
index 367003e..0ffbe97 100644
--- a/src/scene/scene.rs
+++ b/src/scene/scene.rs
@@ -1,33 +1,33 @@
-use super::{Intersection, Hittable};
-use crate::core::Ray;
+use crate::core::{Ray, Intersection, Hittable};
+use crate::material::Material;
-type Shape = Box<dyn Hittable>;
+use super::Object;
pub struct Scene {
- shps: Vec<Shape>,
+ objs: Vec<Object>,
}
impl Scene {
pub fn new() -> Self {
Self {
- shps: Vec::new(),
+ objs: Vec::new(),
}
}
- pub fn add_shape(&mut self, shp: Shape) {
- self.shps.push(shp);
+ pub fn add_object(&mut self, obj: Object) {
+ self.objs.push(obj);
}
- pub fn add_shapes(&mut self, shps: Vec<Shape>) {
- for shp in shps {
- self.add_shape(shp);
+ pub fn add_objects(&mut self, objs: Vec<Object>) {
+ for obj in objs {
+ self.add_object(obj);
}
}
- pub fn intersect(&self, ray: &Ray) -> Option<Intersection> {
- for shp in self.shps.iter() {
- if let Some(i) = shp.intersect(&ray) {
- return Some(i)
+ pub fn intersect(&self, ray: &Ray) -> Option<(&dyn Material, Intersection)> {
+ for obj in self.objs.iter() {
+ if let Some(i) = obj.shape.intersect(&ray) {
+ return Some((obj.mat.as_ref(), i))
}
}