-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.rs
128 lines (114 loc) · 3.98 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
use rust_rtc::colors::color;
use rust_rtc::lights::point_light;
use rust_rtc::shapes::cylinder;
use rust_rtc::transformations::{rotation_x, rotation_y, scaling, 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 cyl_len = 4.0;
let solid = false;
// Steel pipes
let mut cyl = cylinder(-cyl_len * 1.0, cyl_len * 1.0, true, solid);
cyl.set_transform(
&rotation_x(-PI / 2.0)
.then(&rotation_x(0.1))
.then(&rotation_y(0.2))
.then(&translation(4.0, 4.0, -6.0)),
);
cyl.material.color = color(0.7922, 0.80, 0.8078);
cyl.material.ambient = 0.2;
cyl.material.diffuse = 0.3;
cyl.material.specular = 0.8;
cyl.material.shininess = 100.0;
cyl.material.shininess = 10.0;
cyl.material.reflective = 0.5;
w.add_object(cyl);
let mut cyl = cylinder(-cyl_len * 5.0, cyl_len * 1.0, true, solid);
cyl.set_transform(
&rotation_x(-PI / 2.0)
.then(&rotation_y(-0.33))
.then(&rotation_x(0.3))
.then(&translation(-6.0, -1.0, -4.0)),
);
cyl.material.color = color(0.7922, 0.80, 0.8078);
cyl.material.ambient = 0.2;
cyl.material.diffuse = 0.3;
cyl.material.specular = 0.8;
cyl.material.shininess = 100.0;
cyl.material.shininess = 10.0;
cyl.material.reflective = 0.5;
w.add_object(cyl);
// Copper pipes
let mut cyl = cylinder(-cyl_len * 1.0, cyl_len * 1.0, true, solid);
cyl.set_transform(&rotation_x(-PI / 2.0).then(&translation(-3.0, 4.0, -4.0)));
cyl.material.color = color(0.722, 0.451, 0.20);
cyl.material.ambient = 0.2;
cyl.material.diffuse = 0.3;
cyl.material.specular = 0.8;
cyl.material.shininess = 100.0;
cyl.material.shininess = 10.0;
cyl.material.reflective = 0.5;
w.add_object(cyl);
let mut cyl = cylinder(-cyl_len * 1.0, cyl_len * 1.0, true, solid);
cyl.set_transform(&rotation_x(-PI / 2.0).then(&translation(0.0, 2.0, -4.0)));
cyl.material.color = color(0.722, 0.451, 0.20);
cyl.material.ambient = 0.2;
cyl.material.diffuse = 0.3;
cyl.material.specular = 0.8;
cyl.material.shininess = 100.0;
cyl.material.shininess = 10.0;
cyl.material.reflective = 0.5;
w.add_object(cyl);
let mut cyl = cylinder(-cyl_len * 1.5, cyl_len * 1.0, true, solid);
cyl.set_transform(
&rotation_x(-PI / 2.0)
.then(&rotation_x(0.4))
.then(&translation(4.5, -2.0, -4.0)),
);
cyl.material.color = color(0.722, 0.451, 0.20);
cyl.material.ambient = 0.2;
cyl.material.diffuse = 0.3;
cyl.material.specular = 0.8;
cyl.material.shininess = 100.0;
cyl.material.shininess = 10.0;
cyl.material.reflective = 0.5;
w.add_object(cyl);
let mut cyl = cylinder(-cyl_len * 1.5, cyl_len * 1.0, true, solid);
cyl.set_transform(
&scaling(3.0, 0.1, 3.0)
.then(&rotation_x(-0.1))
.then(&translation(-1.0, -3.0, -4.0)),
);
cyl.material.color = color(0.722, 0.451, 0.20);
cyl.material.ambient = 0.2;
cyl.material.diffuse = 0.3;
cyl.material.specular = 0.8;
cyl.material.shininess = 100.0;
cyl.material.shininess = 10.0;
cyl.material.reflective = 0.5;
w.add_object(cyl);
w.add_light(point_light(point(-2.0, 5.0, -10.0), color(1.0, 1.0, 1.0)));
dbg!("{:#?}", &w);
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
}
})
}