aboutsummaryrefslogtreecommitdiff
path: root/src/scene/scene.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/scene/scene.rs')
-rw-r--r--src/scene/scene.rs27
1 files changed, 13 insertions, 14 deletions
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<Box<dyn Shape>>,
-}
+type Shape = Box<dyn Hittable>;
-pub struct Intersection<'a> {
- pub shp: &'a dyn Shape,
- pub t: Float,
+pub struct Scene {
+ shps: Vec<Shape>,
}
impl Scene {
@@ -18,17 +14,20 @@ impl Scene {
}
}
- pub fn add_shape(&mut self, shp: Box<dyn Shape>) {
+ pub fn add_shape(&mut self, shp: Shape) {
self.shps.push(shp);
}
+ pub fn add_shapes(&mut self, shps: Vec<Shape>) {
+ for shp in shps {
+ self.add_shape(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,
- })
+ if let Some(i) = shp.intersect(&ray) {
+ return Some(i)
}
}