-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cc
81 lines (60 loc) · 2.42 KB
/
main.cc
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
#include <iostream>
#include <memory>
#include "window.h"
#include "util.h"
#include "linalg/linalg.h"
#include "scene.h"
#include "sphere.h"
#include "plane.h"
const int WIDTH = 1920;
const int HEIGHT = 1080;
int main() {
Window w(WIDTH, HEIGHT, "Raytracer");
w.drawRectToScreen(Rect{50, 50, 50, 50}, Color{0xFF, 0x00, 0x00});
Scene s(WIDTH, HEIGHT);
Geometry *g = new Sphere(Color{0xFF, 0xCC, 0x00}, 0, vec(0.0f, 0.0f, 10.0f), 1.0f);
g->setOpacity(0.5);
g->setRefraction(1.51);
// s.addToScene(std::unique_ptr<Geometry>(g));
g = new Sphere(Color{0xFF, 0xCC, 0xFF}, 0.5, vec(5.0f, -0.0f, 15.0f), 2.5f);
// s.addToScene(std::unique_ptr<Geometry>(g));
g = new Sphere(Color{0x00, 0x00, 0xFF}, 0, vec(-2.1f, -1.0f, 10.0f), 1.0f);
g->setOpacity(0.7);
g->setRefraction(1.51);
s.addToScene(std::unique_ptr<Geometry>(g));
g = new Sphere(Color{0xFF, 0xFF, 0xFF}, 0, vec(-0.0f, -1.0f, 10.0f), 1.0f);
g->setOpacity(0.7);
g->setRefraction(1.51);
s.addToScene(std::unique_ptr<Geometry>(g));
g = new Sphere(Color{0xFF, 0x00, 0xFF}, 0.2, vec(2.0f, 4.0f, 20.0f), 1.0f);
g->setOpacity(0.7);
g->setRefraction(1.01);
s.addToScene(std::unique_ptr<Geometry>(g));
g = new Plane(Color{0xFF, 0xFF, 0xFF}, 0, vec(-10.0f, 0.0f, 0.0f), vec(1.0f, 0.0f, -0.1f));
//s.addToScene(std::unique_ptr<Geometry>(g));
g = new Plane(Color{0xFF, 0xFF, 0xFF}, 0, vec(10.0f, 0.0f, 0.0f), vec(-1.0f, 0.0f, -0.1f));
//s.addToScene(std::unique_ptr<Geometry>(g));
g = new Plane(Color{0x00, 0xFF, 0xFF}, 0, vec(0.0f, -5.0f, 0.0f), vec(0.0f, 1.0f, -0.1f));
s.addToScene(std::unique_ptr<Geometry>(g));
g = new Plane(Color{0xFF, 0xFF, 0xFF}, 0, vec(0.0f, 5.0f, 0.0f), vec(0.0f, -1.0f, -0.1f));
//s.addToScene(std::unique_ptr<Geometry>(g));
g = new Plane(Color{0xDD, 0xDD, 0xDD}, 0, vec(0.0f, 0.0f, 15.0f), vec(0.0f, 0.0f, -1.0f));
s.addToScene(std::unique_ptr<Geometry>(g));
//s.addLight(vec(-10, 10, 0));
s.addLight(vec(-9, 4.9, 0));
// Calculate the color with a raytracer.
for (int x = 0; x < WIDTH; x++) {
for (int y = 0; y < HEIGHT; y++) {
Ray toTrace = s.getRay(x, y);
Color c = s.traceRay(toTrace, 3);
w.drawRectToScreen(Rect{x, y, 1, 1}, c);
}
w.updateWindow();
}
w.updateWindow();
w.saveToFile("tmp.bmp");
//Wait two seconds
SDL_Delay(1 * 1000);
//Destroy window
return 0;
}