blob: 85752171ac318a01b3860809b613e20adfccb485 (
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, Intersection};
use crate::material::Material;
use super::Object;
pub struct Scene {
objs: Vec<Object>,
}
impl Scene {
pub fn new() -> Self {
Self {
objs: Vec::new(),
}
}
pub fn add_object(&mut self, obj: Object) {
self.objs.push(obj);
}
pub fn add_objects(&mut self, objs: Vec<Object>) {
for obj in objs {
self.add_object(obj);
}
}
pub fn intersect(&self, ray: &Ray) -> Option<(&dyn Material, Intersection)> {
for obj in self.objs.iter() {
if let Some(i) = obj.shape.intersect(&ray) {
return Some((obj.mat.as_ref(), i))
}
}
None
}
}
|