aboutsummaryrefslogtreecommitdiff
path: root/src/scene/scene.rs
diff options
context:
space:
mode:
authorJulian T <julian@jtle.dk>2021-02-06 17:27:42 +0100
committerJulian T <julian@jtle.dk>2021-02-06 17:27:42 +0100
commit0d5e6bd9363d5ed5c4f28174819fc0f5fd9aa586 (patch)
treef9ecafe7350ad616486e509ed55904295f505f83 /src/scene/scene.rs
parent1e83ea211055eb234b89c69b5d03602e3fcb98fb (diff)
Reorganized scene module, and fixed bug in sphere intersect
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)
}
}