aboutsummaryrefslogtreecommitdiff
path: root/src/scene/scene.rs
blob: 367003e0f7b7d75100062da8c56944a02639d063 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
use super::{Intersection, Hittable};
use crate::core::Ray;

type Shape = Box<dyn Hittable>;

pub struct Scene {
    shps: Vec<Shape>,
}

impl Scene {
    pub fn new() -> Self {
        Self {
            shps: Vec::new(),
        }
    }

    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(i) = shp.intersect(&ray) {
                return Some(i)
            }
        }

        None
    }
}