-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.rs
More file actions
executable file
·70 lines (59 loc) · 1.57 KB
/
main.rs
File metadata and controls
executable file
·70 lines (59 loc) · 1.57 KB
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
mod camera;
mod geometry;
mod interval;
mod material;
mod raytracer;
mod vec;
use camera::Camera;
use camera::Color;
use geometry::Point3;
use geometry::Sphere;
use material::Lambertian;
use material::Metal;
use std::rc::Rc;
use std::sync::Arc;
use std::time::Instant;
fn main() {
let mut world: raytracer::HittableList = raytracer::HittableList::new();
let ground_mat = Arc::new(Lambertian {
albedo: Color::new(0.8, 0.8, 0.0),
});
let center_mat = Arc::new(Lambertian {
albedo: Color::new(0.1, 0.2, 0.5),
});
let left_mat = Arc::new(Metal {
albedo: Color::new(0.8, 0.8, 0.8),
});
let right_mat = Arc::new(Metal {
albedo: Color::new(0.8, 0.6, 0.2),
});
world.add(Rc::new(Sphere {
center: Point3::new(0.0, 0.0, -1.0),
radius: 0.5,
material: center_mat,
}));
world.add(Rc::new(Sphere {
center: Point3::new(0.0, -100.5, -1.0),
radius: 100.0,
material: ground_mat,
}));
world.add(Rc::new(Sphere {
center: Point3::new(-1.0, 0.0, -1.0),
radius: 0.5,
material: left_mat,
}));
world.add(Rc::new(Sphere {
center: Point3::new(1.0, 0.0, -1.0),
radius: 0.5,
material: right_mat,
}));
let camera = Camera::init(16.0 / 9.0, 400);
let start = Instant::now();
match camera.render(&world) {
Ok(_) => {
let duration = start.elapsed();
println!("Rendering took {:.2} seconds", duration.as_secs_f64());
}
Err(e) => println!("Cannot render world. {}", e),
}
}