blob: a2f5b884b552e0d67171fa89a75eccd9c073506b (
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
|
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
}
}
|