-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.rs
84 lines (74 loc) · 2.45 KB
/
main.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
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
use rust_rtc::colors::color;
use rust_rtc::lights::point_light;
use rust_rtc::shapes::infinite_cylinder;
use rust_rtc::transformations::{
rotation_x, rotation_z, translate_y, translate_z, translation, view_transform,
};
use rust_rtc::tuples::{point, vector};
use rust_rtc::utils;
use rust_rtc::utils::RenderOptions;
use rust_rtc::world::world;
use std::f64::consts::PI;
use std::process::ExitCode;
fn main() -> ExitCode {
let cli = utils::parse_args();
let mut w = world();
let mut cyl1 = infinite_cylinder();
cyl1.material.color = color(0.722, 0.451, 0.20);
cyl1.material.specular = 1.0;
cyl1.material.shininess = 10.0;
cyl1.material.shininess = 10.0;
cyl1.material.reflective = 0.9;
w.add_object(cyl1);
let mut cyl2 = infinite_cylinder();
cyl2.set_transform(
&rotation_z(PI / 4.0)
.then(&rotation_x(PI / 2.0))
.then(&translate_z(-5.0)),
);
cyl2.material.color = color(0.722, 0.451, 0.20);
cyl2.material.specular = 1.0;
cyl2.material.shininess = 10.0;
cyl2.material.shininess = 10.0;
cyl2.material.reflective = 0.9;
w.add_object(cyl2);
let mut cyl3 = infinite_cylinder();
cyl3.set_transform(
&rotation_z(-PI / 4.0)
.then(&rotation_x(PI / 2.0))
.then(&translate_y(4.0))
.then(&translate_z(5.0)),
);
cyl3.material.color = color(0.722, 0.451, 0.20);
cyl3.material.specular = 1.0;
cyl3.material.shininess = 10.0;
cyl3.material.shininess = 10.0;
cyl3.material.reflective = 0.9;
w.add_object(cyl3);
let mut cyl4 = infinite_cylinder();
cyl4.set_transform(&translation(25.0, 0.0, 25.0));
cyl4.material.color = color(0.7922, 0.80, 0.8078);
cyl4.material.diffuse = 0.3;
cyl4.material.specular = 0.8;
cyl4.material.shininess = 100.0;
cyl4.material.shininess = 10.0;
cyl4.material.reflective = 0.5;
w.add_object(cyl4);
w.add_light(point_light(point(-2.0, 5.0, -10.0), color(1.0, 1.0, 1.0)));
let options = RenderOptions {
camera_transform: view_transform(
&point(0.0, 1.5, -5.0),
&point(0.0, 0.5, 0.0),
&vector(0.0, 1.0, 0.0),
)
.then(&translation(0.0, 0.0, -20.0)),
..Default::default()
};
ExitCode::from(match utils::render_world(&w, options, &cli.common) {
Ok(_) => 0,
Err(e) => {
eprintln!("Write {}: {}", cli.common.render.output, e);
1
}
})
}