aboutsummaryrefslogtreecommitdiff
path: root/src/world/scene.rs
blob: 03578bee9d3097d4956f5668d6df8dcba7b5599b (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 crate::core::Ray;

use super::{Object, HittableList, Hittable, Intersection};

pub struct Scene {
    content: HittableList,
}

impl Scene {
    pub fn new() -> Self {
        Self::default()
    }

    pub fn add_object(&mut self, obj: Object) {
        self.content.add(Box::new(obj));
    }

    pub fn add_objects(&mut self, objs: Vec<Object>) {
        for obj in objs {
            self.add_object(obj);
        }
    }
}

impl Hittable for Scene {
    fn intersect(&self, ray: &Ray) -> Option<Intersection> {
        self.content.intersect(ray)
    }
}

impl Default for Scene {
    fn default() -> Self {
        Self {
            content: HittableList::new(),
        }
    }
}