aboutsummaryrefslogtreecommitdiff
path: root/src/world/scene.rs
blob: 87bec1f85fd326e04f278320e0c267b9b8e5494c (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
38
39
40
41
42
43
use crate::core::{Bound3f, Ray};

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

type Container = container::HittableList;

pub struct Scene {
    content: Container,
}

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

    pub fn add_object(&mut self, obj: Object) {
        self.content.add(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)
    }

    fn bounding_box(&self) -> Bound3f {
        self.content.bounding_box()
    }
}

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