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.rs38
1 files changed, 38 insertions, 0 deletions
diff --git a/src/scene/scene.rs b/src/scene/scene.rs
new file mode 100644
index 0000000..a2f5b88
--- /dev/null
+++ b/src/scene/scene.rs
@@ -0,0 +1,38 @@
+use super::shapes::Shape;
+use crate::Float;
+use crate::core::Ray;
+
+pub struct Scene {
+ shps: Vec<Box<dyn Shape>>,
+}
+
+pub struct Intersection<'a> {
+ pub shp: &'a dyn Shape,
+ pub t: Float,
+}
+
+impl Scene {
+ pub fn new() -> Self {
+ Self {
+ shps: Vec::new(),
+ }
+ }
+
+ pub fn add_shape(&mut self, shp: Box<dyn Shape>) {
+ self.shps.push(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,
+ })
+ }
+ }
+
+ None
+ }
+}
+