-
Notifications
You must be signed in to change notification settings - Fork 0
/
scene.rs
36 lines (31 loc) · 781 Bytes
/
scene.rs
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
use super::acceleration::*;
use super::hittable::*;
use super::sphere::*;
pub struct Scene {
pub spheres: Vec<Sphere>,
pub bvh: Bvh,
}
fn as_object_refs<H>(objects: &[H]) -> Vec<&(dyn Hittable + Sync)>
where
H: Hittable + Sync,
{
objects
.iter()
.map(|e| e as &(dyn Hittable + Sync))
.collect()
}
impl Scene {
pub fn new() -> Scene {
Scene {
spheres: vec![],
bvh: Bvh::new(),
}
}
pub fn objects(&self) -> Vec<&(dyn Hittable + Sync)> {
as_object_refs(&self.spheres)
}
pub fn build_bvh(&mut self, method: BvhPartitionMethod) {
let objects = as_object_refs(&self.spheres);
self.bvh.build(&objects[..], method);
}
}