-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpath-tracer.cpp
More file actions
132 lines (121 loc) · 4.66 KB
/
path-tracer.cpp
File metadata and controls
132 lines (121 loc) · 4.66 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
#include <iostream>
#include <fstream>
#include <stdlib.h>
#include <vector>
#include <math.h>
#include <chrono>
#include "./header-files/Ambient.h"
#include "./header-files/Camera.h"
#include "./header-files/Light.h"
#include "./header-files/Material.h"
#include "./header-files/Object.h"
#include "./header-files/pinholeCamera.h"
#include "./header-files/Plane.h"
#include "./header-files/PointLight.h"
#include "./header-files/Points.h"
#include "./header-files/RGBColor.h"
#include "./header-files/Sphere.h"
#include "./header-files/TriangleMesh.h"
#include "./header-files/TriangleMeshLight.h"
#include "./header-files/Vectors.h"
#include "./header-files/World.h"
void render(std::vector<Object*> &objects, std::vector<Light*> &lights, Camera &camera, Ambient &ambient, std::string version)
{
camera.render(objects, lights, ambient, version);
}
int main(int argc, char *argv[]) {
std::string version = argv[1];
std::vector<Object*> objects;
std::vector<Light*> lights;
Camera *camera;
Ambient *ambient;
char objectType;
auto read = true;
float _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18;
while (scanf("%c %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f\n", &objectType, &_1, &_2, &_3, &_4, &_5, &_6, &_7, &_8, &_9, &_10, &_11, &_12, &_13, &_14, &_15, &_16, &_17, &_18) != EOF && read)
{
switch(objectType)
{
case 's':
{
auto mater = new Material{
RGBColor(_5, _6, _7), _8, _9, _10, _11, _12, _13, (bool)_15, _16
};
objects.push_back(new Sphere(Point3D(_1, _2, _3), _4, mater, (bool)_14));
break;
}
case 't':
{
auto mater = new Material{
RGBColor(_3, _4, _5), _6, _7, _8, _9, _10, _11, (bool)_13, _14
};
auto mesh = new TriangleMesh((int)_1, (int)_2, mater, (bool)_12);
float v1, v2, v3;
int i1, i2, i3;
while(_2 > 0)
{
scanf("%f %f %f\n", &v1, &v2, &v3);
mesh->vertices.push_back(Point3D(v1, v2, v3));
_2--;
}
while(_1 > 0)
{
scanf("%i %i %i\n", &i1, &i2, &i3);
mesh->triangles.push_back(Point3I(i1, i2, i3));
_1--;
}
objects.push_back(mesh);
break;
}
case 'l':
{
if (_8 > 0 && _9 > 0) {
auto mater = new Material(RGBColor(_4, _5, _6), 0, 0, 0, 0, 0, 0, _13, 0);
auto mesh = new TriangleMesh((int)_8, (int)_9, mater, _12);
float v1, v2, v3;
int i1, i2, i3;
while (_9 > 0) {
scanf("%f %f %f\n", &v1, &v2, &v3);
mesh->vertices.push_back(Point3D(v1, v2, v3));
_9--;
}
while(_8 > 0) {
scanf("%i %i %i\n", &i1, &i2, &i3);
mesh->triangles.push_back(Point3I(i1, i2, i3));
_8--;
}
auto l = new TriangleMeshLight(mater->color, mesh, (int)_14);
for (int i = 0; i < l->getLightSamples().size(); i++) {
lights.push_back(new PointLight(l->getLightSamples()[i], mater->color, (bool)_7, (int)_14));
}
lights.push_back(l);
} else {
lights.push_back(new PointLight(Point3D(_1, _2, _3), RGBColor(_4, _5, _6), (bool)_7, (int)_14));
}
break;
}
case 'c':
{
camera = new PinholeCamera(_1, _2, _3, Vec3D(_4, _5, _6), Point3D(_7, _8, _9), Point3D(_10, _11, _12), _13, _14, _15);
camera->makeCamera();
break;
}
case 'a':
{
ambient = new Ambient(RGBColor(_1, _2, _3), _4, _5, _6);
break;
}
default:
{
read = false;
break;
}
}
}
auto start = std::chrono::high_resolution_clock::now();
render(objects, lights, (*camera), (*ambient), version);
auto end = std::chrono::high_resolution_clock::now();
auto duration = std::chrono::duration_cast<std::chrono::seconds>(end - start);
std::cout << "Time elapsed: " << duration.count() << "s" << std::endl;
return 0;
}