-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathray-tracer.cpp
83 lines (67 loc) · 2.11 KB
/
ray-tracer.cpp
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
#include <qapplication.h>
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <math.h>
#include "Viewer.h"
#include "Scene.h"
#include "Sphere.h"
#include "Material.h"
#include "PointLight.h"
using namespace std;
using namespace rt;
void addBubble(Scene &scene, Point3 c, Real r, Material transp_m) {
Material revert_m = transp_m;
std::swap(revert_m.in_refractive_index, revert_m.out_refractive_index);
Sphere *sphere_out = new Sphere(c, r, transp_m);
Sphere *sphere_in = new Sphere(c, r - 0.02f, revert_m);
scene.addObject(sphere_out);
scene.addObject(sphere_in);
}
float to_rad(float degres) {
return degres * (M_PI / 180);
}
int main(int argc, char **argv) {
// Read command lines arguments.
QApplication application(argc, argv);
// Creates a 3D scene
Scene scene;
// Light at infinity
Light *light0 = new PointLight(GL_LIGHT0, Point4(1, 1, 1, 0),
Color(1.0, 1.0, 1.0));
Light *light1 = new PointLight(GL_LIGHT1, Point4(10, 10, 10, 1), Color(1.0, 0.0, 1.0));
scene.addLight(light0);
scene.addLight(light1);
// Objects
//Sphere *sphere3 = new Sphere(Point3(10, 10, 5), 3.0, Material::whitePlastic());
// scene.addObject(sphere3);
int center = 10;
int radius = 20;
int delta_angle = round(360 / radius);
int x, y, z;
z = 5;
while (radius > -40) {
for (int incre_angle = 0; incre_angle < 360; incre_angle += delta_angle) {
x = round(center + radius * sin(to_rad(incre_angle)));
y = round(center + radius * cos(to_rad(incre_angle)));
addBubble(scene, Point3(x, y, z), 2.0, Material::glass());
}
radius -= 5;
if(radius == 0)
radius = -5;
z += 4;
delta_angle = round(360 / abs(radius));
}
// Instantiate the viewer.
Viewer viewer;
// Give a name
viewer.setWindowTitle("Ray-tracer preview");
// Sets the scene
viewer.setScene(scene);
// Make the viewer window visible on screen.
viewer.show();
// Run main loop.
application.exec();
return 0;
}