-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.rs
103 lines (90 loc) · 3.68 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
use rust_rtc::colors::{color, GREEN, GREY25, GREY75, RED};
use rust_rtc::lights::point_light;
use rust_rtc::materials::default_material;
use rust_rtc::patterns::{blended_pattern, stripe_pattern};
use rust_rtc::shapes::{plane, sphere};
use rust_rtc::transformations::{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 mut floor = plane();
floor.material = default_material();
floor.material.color = color(1.0, 0.9, 0.9);
floor.material.ambient = 0.2;
floor.material.specular = 0.0;
floor.material.reflective = 0.2;
let mut floor_pattern_1 = stripe_pattern(&GREY25, &GREY75);
let mut floor_pattern_2 = stripe_pattern(&GREY25, &GREY75);
let scale = 0.4;
floor_pattern_1.set_transform(&scaling(scale, scale, scale).then(&rotation_y(PI / 4.0)));
floor_pattern_2.set_transform(&scaling(scale, scale, scale).then(&rotation_y(-PI / 4.0)));
let mut floor_pattern = blended_pattern(&floor_pattern_1, &floor_pattern_2);
floor_pattern.set_transform(&rotation_y(-PI / 16.0));
floor.material.set_pattern(&floor_pattern);
w.add_object(floor);
let mut sphere1 = sphere(1);
sphere1.set_transform(&scaling(1.5, 1.5, 1.5).then(&translation(0.0, 0.5, 0.0)));
sphere1.material.color = GREY25;
sphere1.material.specular = 1.0;
sphere1.material.shininess = 1000.0;
sphere1.material.reflective = 0.9;
w.add_object(sphere1);
let mut sphere2 = sphere(2);
sphere2.set_transform(&scaling(0.4, 0.4, 0.4).then(&translation(-2.0, 1.7, -1.0)));
sphere2.material.color = RED;
sphere2.material.specular = 0.7;
sphere2.material.shininess = 100.0;
sphere2.material.reflective = 0.4;
w.add_object(sphere2);
let mut sphere3 = sphere(3);
sphere3.set_transform(&scaling(0.5, 0.5, 0.5).then(&translation(1.8, 1.8, -1.0)));
sphere3.material.color = GREEN;
sphere3.material.specular = 0.7;
sphere3.material.shininess = 100.0;
sphere3.material.reflective = 0.4;
w.add_object(sphere3);
let mut sphere4 = sphere(4);
sphere4.set_transform(&scaling(0.2, 0.2, 0.2).then(&translation(1.5, 0.2, -1.8)));
sphere4.material.color = color(0.8, 0.0, 0.8);
sphere4.material.specular = 0.5;
sphere4.material.shininess = 10.0;
sphere4.material.reflective = 0.0;
w.add_object(sphere4);
let mut sphere5 = sphere(5);
sphere5.set_transform(&scaling(0.5, 0.5, 0.5).then(&translation(-1.0, 0.5, -3.5)));
sphere5.material.color = color(0.1, 0.0, 1.0);
sphere5.material.specular = 1.0;
sphere5.material.shininess = 1000.0;
sphere5.material.reflective = 0.8;
w.add_object(sphere5);
// yellow sphere behind the camera
let mut sphere6 = sphere(6);
sphere6.set_transform(&scaling(2.0, 2.0, 2.0).then(&translation(4.0, 2.0, -5.0)));
sphere6.material.color = color(0.9, 0.7, 0.0);
sphere6.material.specular = 0.2;
sphere6.material.shininess = 10.0;
sphere6.material.reflective = 0.8;
w.add_object(sphere6);
w.add_light(point_light(point(-10.0, 10.0, -5.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, 1.0, 0.0),
&vector(0.0, 1.0, 0.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
}
})
}