-
Notifications
You must be signed in to change notification settings - Fork 0
/
SceneHandler.cpp
42 lines (38 loc) · 1.33 KB
/
SceneHandler.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
#include "SceneHandler.h"
using namespace parser;
Scene parser::scene;
float parser::epsilon;
SceneHandler::SceneHandler(string input)
{
scene.loadFromXml(input);
epsilon = scene.shadow_ray_epsilon * 0.0000000000005;
for (Camera& c : scene.cameras) {
cameras.push_back(CameraHandler(c));
}
for (Sphere& s : scene.spheres) {
s.center_vertex = scene.vertex_data[s.center_vertex_id - 1];
s.material = scene.materials[s.material_id - 1];
}
for (Triangle& t : scene.triangles) {
t.material = scene.materials[t.material_id - 1];
Vec3f a = parser::scene.vertex_data[ t.indices.v0_id - 1];
Vec3f b = parser::scene.vertex_data[t.indices.v1_id - 1];
Vec3f c = parser::scene.vertex_data[t.indices.v2_id - 1];
t.indices.normal = crossProduct((c-b), (a-b));
normalize(t.indices.normal);
}
for (Mesh& m : scene.meshes) {
m.material = scene.materials[m.material_id - 1];
for(Face &f : m.faces){
Vec3f a = parser::scene.vertex_data[ f.v0_id - 1];
Vec3f b = parser::scene.vertex_data[ f.v1_id - 1];
Vec3f c = parser::scene.vertex_data[ f.v2_id - 1];
f.normal = crossProduct((c-b), (a-b));
normalize(f.normal);
}
}
}
void SceneHandler::render()
{
for (CameraHandler& c : cameras) c.render();
}