-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSceneReader.cpp
More file actions
111 lines (86 loc) · 2.98 KB
/
SceneReader.cpp
File metadata and controls
111 lines (86 loc) · 2.98 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
/*
* SceneReader.cpp
* Theme06_m01
*
* Created by Carlos Olave on 12/8/11.
* Copyright 2011 Columbia University. All rights reserved.
*
*/
#include "SceneReader.h"
SceneReader::SceneReader() {
current_material_index = 0;
vSphereCollection = std::vector<Sphere>();
vTriangleCollection = std::vector<Triangle>();
vPlaneCollection = std::vector<Plane>();
vCameraCollection = std::vector<Camera>();
vPointLightCollection = std::vector<PointLight>();
vDirectionalLightCollection = std::vector<DirectionalLight>();
vAmbientLightCollection = std::vector<AmbientLight>();
vMaterialCollection = std::vector<Material>();
}
SceneReader::~SceneReader() {
vSphereCollection.clear();
vTriangleCollection.clear();
vPlaneCollection.clear();
vCameraCollection.clear();
vPointLightCollection.clear();
vDirectionalLightCollection.clear();
vAmbientLightCollection.clear();
vMaterialCollection.clear();
}
void SceneReader::sphere(float3 pos, float r) {
Sphere sphere = Sphere(pos, r);
// save the index of the material for this sphere.
if (!vMaterialCollection.empty()) {
sphere.setMaterialIndex(vMaterialCollection.size() - 1);
}
vSphereCollection.push_back(sphere);
}
void SceneReader::triangle(float3 p1, float3 p2, float3 p3) {
Triangle triangle = Triangle(p1, p2, p3);
// save the index of the material for this triangle.
if (!vMaterialCollection.empty()) {
triangle.setMaterialIndex(vMaterialCollection.size() - 1);
}
vTriangleCollection.push_back(triangle);
}
void SceneReader::triangle(float3 p1, float3 p2, float3 p3,
float3 np1, float3 np2, float3 np3) {
Triangle triangle = Triangle(p1, p2, p3, np1, np2, np3);
// save the index of the material for this triangle.
if (!vMaterialCollection.empty()) {
triangle.setMaterialIndex(vMaterialCollection.size() - 1);
}
vTriangleCollection.push_back(triangle);
}
void SceneReader::plane(float3 n, float d) {
Plane plane = Plane(n, d);
// save the index of the material for this plane.
if (!vMaterialCollection.empty()) {
plane.setMaterialIndex(vMaterialCollection.size() - 1);
}
vPlaneCollection.push_back(plane);
}
void SceneReader::camera(float3 pos, float3 dir, float d, float iw, float ih, int pw, int ph) {
Camera camera = Camera(pos, dir, d, iw, ih, pw, ph);
vCameraCollection.push_back(camera);
}
void SceneReader::pointLight(float3 pos, float3 rgb) {
PointLight pointLight = PointLight(pos, rgb);
vPointLightCollection.push_back(pointLight);
}
void SceneReader::directionalLight(float3 dir, float3 rgb) {
DirectionalLight directLight = DirectionalLight(dir, rgb);
vDirectionalLightCollection.push_back(directLight);
}
void SceneReader::ambientLight(float3 rgb) {
AmbientLight ambientLight = AmbientLight(rgb);
vAmbientLightCollection.push_back(ambientLight);
}
void SceneReader::material(float3 diff, float3 spec, float r, float3 refl) {
Material material = Material(diff, spec, r, refl);
vMaterialCollection.push_back(material);
}
void SceneReader::parse(const char* name) {
Parser::parse(name);
}