-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSceneParser.h
More file actions
143 lines (122 loc) · 2.61 KB
/
SceneParser.h
File metadata and controls
143 lines (122 loc) · 2.61 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
133
134
135
136
137
138
139
140
141
142
143
#ifndef SCENE_PARSER_H
#define SCENE_PARSER_H
#include <cassert>
#include <vecmath.h>
#include "SceneParser.h"
#include "Camera.h"
#include "CubeMap.h"
#include "Light.h"
#include "Material.h"
#include "Object3D.h"
#include "Mesh.hpp"
#include "Group.h"
#include "Sphere.h"
#include "Plane.h"
#include "Triangle.h"
#include "Transform.h"
/*
class Camera;
class Light;
class Material;
class Object3D;
class Group;
class Sphere;
class Plane;
class Triangle;
class Transform;
*/
#define MAX_PARSER_TOKEN_LENGTH 100
class SceneParser
{
public:
SceneParser( const char* filename );
~SceneParser();
Camera* getCamera() const
{
return camera;
}
Vector3f getBackgroundColor(Vector3f dir) const
{
if(cubemap ==0){
return background_color;
}
return cubemap->operator()(dir);
}
Vector3f getAmbientLight() const
{
return ambient_light;
}
int getNumLights() const
{
return num_lights;
}
Light* getLight( int i ) const
{
assert( i >= 0 && i < num_lights );
return lights[i];
}
int getNumMaterials() const
{
return num_materials;
}
Material* getMaterial( int i ) const
{
assert( i >= 0 && i < num_materials );
return materials[i];
}
Group* getGroup() const
{
return group;
}
int getSamples() const
{
int samples = 1;
for (register int i = 0; i < num_lights; ++i)
{
if (getLight(i)->type != 'p')
{
samples = getLight(i)->samples;
}
}
return samples;
}
private:
SceneParser()
{
assert( false );
}
void parseFile();
void parsePerspectiveCamera();
void parseBackground();
void parseLights();
Light* parseDirectionalLight();
Light* parsePointLight();
void parseMaterials();
Material* parseMaterial();
Noise* parseNoise();
Object3D* parseObject( char token[ MAX_PARSER_TOKEN_LENGTH ] );
Group* parseGroup();
Sphere* parseSphere();
Plane* parsePlane();
Triangle* parseTriangle();
Mesh* parseTriangleMesh();
Transform* parseTransform();
CubeMap * parseCubeMap();
int getToken( char token[ MAX_PARSER_TOKEN_LENGTH ] );
Vector3f readVector3f();
Vector2f readVec2f();
float readFloat();
int readInt();
FILE* file;
Camera* camera;
Vector3f background_color;
Vector3f ambient_light;
int num_lights;
Light** lights;
int num_materials;
Material** materials;
Material* current_material;
Group* group;
CubeMap * cubemap;
};
#endif // SCENE_PARSER_H