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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
|
#pragma once
#include <vector>
#include <string>
#include <glm/glm.hpp>
#include "rgba.h"
// Enum of the types of virtual lights that might be in the scene
enum class LightType {
LIGHT_POINT,
LIGHT_DIRECTIONAL,
LIGHT_SPOT,
LIGHT_AREA
};
// Enum of the types of primitives that might be in the scene
enum class PrimitiveType {
PRIMITIVE_CUBE,
PRIMITIVE_CONE,
PRIMITIVE_CYLINDER,
PRIMITIVE_SPHERE,
PRIMITIVE_MESH
};
// Enum of the types of transformations that can be applied
enum class TransformationType {
TRANSFORMATION_TRANSLATE,
TRANSFORMATION_SCALE,
TRANSFORMATION_ROTATE,
TRANSFORMATION_MATRIX
};
// Type which can be used to store an RGBA color in floats [0,1]
using SceneColor = glm::vec4;
// Struct which contains the global color coefficients of a scene.
// These are multiplied with the object-specific materials in the lighting equation.
struct SceneGlobalData {
float ka; // Ambient term
float kd; // Diffuse term
float ks; // Specular term
float kt; // Transparency; used for extra credit (refraction)
glm::vec4 gravity; // Acceleration due to gravity (as a 4d vector)
};
// Struct which contains raw parsed data fro a single light
struct SceneLight {
int id;
LightType type;
SceneColor color;
glm::vec3 function; // Attenuation function
glm::vec4 dir; // Not applicable to point lights
float penumbra; // Only applicable to spot lights, in RADIANS
float angle; // Only applicable to spot lights, in RADIANS
float width, height; // No longer supported (area lights)
};
// Struct which contains data for a single light with CTM applied
struct SceneLightData {
int id;
LightType type;
SceneColor color;
glm::vec3 function; // Attenuation function
glm::vec4 pos; // Position with CTM applied (Not applicable to directional lights)
glm::vec4 dir; // Direction with CTM applied (Not applicable to point lights)
float penumbra; // Only applicable to spot lights, in RADIANS
float angle; // Only applicable to spot lights, in RADIANS
float width, height; // No longer supported (area lights)
};
// Struct which contains data for the camera of a scene
struct SceneCameraData {
glm::vec4 pos;
glm::vec4 look;
glm::vec4 up;
glm::vec4 over;
float heightAngle; // The height angle of the camera in RADIANS
float depthAngle; // The depth angle of the camera in RADIANS
float aperture; // Only applicable for depth of field
float focalLength; // Only applicable for depth of field
};
// Struct which contains data for texture mapping files
struct SceneFileMap {
SceneFileMap() : isUsed(false) {}
bool isUsed;
std::string filename;
float repeatU;
float repeatV;
void clear()
{
isUsed = false;
repeatU = 0.0f;
repeatV = 0.0f;
filename = std::string();
}
};
struct TextureData {
int width;
int height;
RGBA* data;
};
// Struct which contains data for a material (e.g. one which might be assigned to an object)
struct SceneMaterial {
SceneColor cAmbient; // Ambient term
SceneColor cDiffuse; // Diffuse term
SceneColor cSpecular; // Specular term
float shininess; // Specular exponent
SceneColor cReflective; // Used to weight contribution of reflected ray lighting (via multiplication)
SceneColor cTransparent; // Transparency; used for extra credit (refraction)
float ior; // Index of refraction; used for extra credit (refraction)
SceneFileMap textureMap; // Used for texture mapping
float blend; // Used for texture mapping
TextureData textureData;
SceneColor cEmissive; // Not used
SceneFileMap bumpMap; // Not used
void clear()
{
cAmbient = glm::vec4(0);
cDiffuse = glm::vec4(0);
cSpecular = glm::vec4(0);
shininess = 0;
cReflective = glm::vec4(0);
cTransparent = glm::vec4(0);
ior = 0;
textureMap.clear();
blend = 0;
cEmissive = glm::vec4(0);
bumpMap.clear();
}
};
// Struct which contains data for a single primitive in a scene
struct ScenePrimitive {
PrimitiveType type;
SceneMaterial material;
std::string meshfile; // Used for triangle meshes
glm::vec4 velocity; // Current velocity of the primitive
};
// Struct which contains data for a transformation.
struct SceneTransformation {
TransformationType type;
glm::vec4 translate; // Only applicable when translating. Defines t_x, t_y, and t_z, the amounts to translate by, along each axis.
glm::vec4 scale; // Only applicable when scaling. Defines s_x, s_y, and s_z, the amounts to scale by, along each axis.
glm::vec3 rotate3; // Only applicable when rotating. Defines the axis of rotation (for the first 3 axis); should be a unit vector.
glm::vec3 rotateW; // Only applicable when rotating. Defines the axis of rotation (for the last 3 axis); should be a unit vector.
float angle; // Only applicable when rotating. Defines the angle to rotate by in RADIANS, following the right-hand rule.
glm::mat4 matrix; // Only applicable when transforming by a custom matrix. This is that custom matrix.
glm::vec4 matrixRight4d; // Only applicable when transforming by a custom matrix. This is the 4d translation vector appended to the right of the matrix.
};
// Struct which represents a node in the scene graph/tree, to be parsed by the student's `SceneParser`.
struct SceneNode {
std::vector<SceneTransformation*> transformations; // Note the order of transformations described in lab 5
std::vector<ScenePrimitive*> primitives;
std::vector<SceneLight*> lights;
std::vector<SceneNode*> children;
};
|