forked from worblehat/WorbleRay
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
133 lines (118 loc) · 5.09 KB
/
main.cpp
File metadata and controls
133 lines (118 loc) · 5.09 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
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
129
130
131
132
133
#include "AmbientLight.h"
#include "Disk.h"
#include "Intersection.h"
#include "LambertMaterial.h"
#include "log.h"
#include "MirrorMaterial.h"
#include "OrthographicCamera.h"
#include "PerspectiveCamera.h"
#include "PhongMaterial.h"
#include "Plane.h"
#include "PointLight.h"
#include "Ray.h"
#include "Renderer.h"
#include "SDLWindow.h"
#include "Scene.h"
#include "Sphere.h"
#include <chrono>
#include <cstdlib>
#include <memory>
#include <thread>
// Declared in log.h, defined here
short X_POS;
short Y_POS;
int main()
{
// Optionen
Options options;
options.width = 960;
options.height = 600;
options.ambient_illumination = true;
options.diffuse_illumination = true;
options.specular_illumination = true;
options.shadows = true;
options.intersection_epsilon = 0.0000000001;
options.gamma = 1.4;
options.tone_mapping = ToneMapping::Scale;
options.max_recursion = 4;
// Build scene
Scene scene(options);
auto floor = std::unique_ptr<Plane>(new Plane(PointD(0.0, 0.0, 0.0), VectorD(0.0, 1.0, 0.0)));
auto wall_left = std::unique_ptr<Plane>(new Plane(PointD(-800.0, 0.0, 0.0), VectorD(1.0, 0.0, 0.0)));
auto wall_right = std::unique_ptr<Plane>(new Plane(PointD(800.0, 0.0, 0.0), VectorD(-1.0, 0.0, 0.0)));
auto wall_back = std::unique_ptr<Plane>(new Plane(PointD(0.0, 0.0, -1000.0), VectorD(0.0, 0.0, 1.0)));
auto wall_front = std::unique_ptr<Plane>(new Plane(PointD(0.0, 0.0, 2500.0), VectorD(0.0, 0.0, -1.0)));
auto ceiling = std::unique_ptr<Plane>(new Plane(PointD(0.0, 1100.0, 0.0), VectorD(0.0, -1.0, 0.0)));
//auto sphere_1 = std::unique_ptr<Sphere>(new Sphere(PointD(50.0, 200.0, -450.0), 200.0));
//auto sphere_2 = std::unique_ptr<Sphere>(new Sphere(PointD(350.0, 150.0, -200.0), 150.0));
auto sphere_1 = std::unique_ptr<Sphere>(new Sphere(PointD(230.0, 200.0, -500.0), 200.0));
auto sphere_2 = std::unique_ptr<Sphere>(new Sphere(PointD(500.0, 150.0, -250.0), 150.0));
auto disk_1 = std::unique_ptr<Disk>(new Disk(PointD(-550.0, 150.0, 100.0), 180, VectorD(0.0, 1.0, 0.0)));
auto disk_2 = std::unique_ptr<Disk>(new Disk(PointD(799.01, 400, 100.0), 350, VectorD(-1.0, 0.0, 0.0)));
//auto disk_2 = std::unique_ptr<Disk>(new Disk(PointD(350, 400, -999.9), 350, VectorD(0.0, 0.0, 1.0)));
auto perspective_cam = std::unique_ptr<PerspectiveCamera>(new PerspectiveCamera());
perspective_cam->set_field_of_view(50);
perspective_cam->set_position(PointD(0.0f, 800.0f, 2200.0f));
perspective_cam->set_look_at(VectorD(0.0f, -0.15f, -1.0f));
perspective_cam->set_up_vector(VectorD(0.0f, 1.0f, 0.0f));
perspective_cam->set_resolution(options.width, options.height);
perspective_cam->set_pixel_size(1.0f);
scene.set_camera(std::move(perspective_cam));
auto ambient_light = std::unique_ptr<AmbientLight>(
new AmbientLight(Color(0.3f, 0.3f, 0.3f), 1.0f));
auto point_light = std::unique_ptr<PointLight>(
new PointLight(PointD(500.0f, 1000.0f, 0.0f), Color(0.7f, 0.7f, 0.7f)));
scene.set_ambient_light(std::move(ambient_light));
scene.add_light(std::move(point_light));
auto red_phong = std::make_shared<PhongMaterial>(
Color(0.6f, 0.0f, 0.0f), Color(0.5f, 0.0f, 0.0f), Color(0.6f, 0.6f, 0.6f), 20.0);
auto blue_phong = std::make_shared<PhongMaterial>(
Color(0.0f, 0.0f, 0.6f), Color(0.0f, 0.0f, 0.5f), Color(0.0f, 0.0f, 0.6f), 5.0);
auto green_lambert = std::make_shared<LambertMaterial>(Color(0.0f, 0.6f, 0.0f), Color(0.0f, 0.5f, 0.0f));
auto light_gray_lambert = std::make_shared<LambertMaterial>(Color(0.8f, 0.8f, 0.8f), Color(0.5f, 0.5f, 0.5f));
auto dark_gray_lambert = std::make_shared<LambertMaterial>(Color(0.5f, 0.5f, 0.5f), Color(0.2f, 0.2f, 0.2f));
auto mirror = std::make_shared<MirrorMaterial>();
floor->set_material(green_lambert);
wall_left->set_material(light_gray_lambert);
wall_right->set_material(light_gray_lambert);
wall_back->set_material(light_gray_lambert);
wall_front->set_material(light_gray_lambert);
ceiling->set_material(dark_gray_lambert);
sphere_1->set_material(red_phong);
sphere_2->set_material(blue_phong);
disk_1->set_material(blue_phong);
disk_2->set_material(mirror);
scene.add_object(std::move(floor));
scene.add_object(std::move(ceiling));
scene.add_object(std::move(wall_left));
scene.add_object(std::move(wall_right));
scene.add_object(std::move(wall_back));
scene.add_object(std::move(wall_front));
scene.add_object(std::move(sphere_1));
scene.add_object(std::move(sphere_2));
scene.add_object(std::move(disk_1));
scene.add_object(std::move(disk_2));
// Render
SDLWindow window(options.width, options.height);
Renderer renderer(scene);
bool quit = false;
window.on_quit([&renderer, &quit]()
{
renderer.abort();
quit = true;
}
);
quit = !window.show();
if(!quit)
{
renderer.render(window);
}
// Idle
while(!quit)
{
std::chrono::milliseconds t(30);
std::this_thread::sleep_for(t);
window.handle_events();
}
return 0;
}