-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmodel.h
More file actions
134 lines (123 loc) · 2.43 KB
/
model.h
File metadata and controls
134 lines (123 loc) · 2.43 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
#include <bits/stdc++.h>
#include "GL/freeglut.h"
#include "GL/gl.h"
#include <GL/glu.h>
#include "photonMap.h"
#define DIFFUSE 0
#define SPECULAR 1
#define REFRACT 2
#define NOT_INTERSECTED (1.0e6)
#define nPhotons 500000
#define mP 3000000
using namespace std;
enum Axis {xAxis = 0, yAxis = 1, zAxis = 2};
class PhotonRay;
/*
* Sphere defines the sphericals objects in the scene
* Identified by a center (x, y, z) and radius
* Spheres are assumed to be specular
*/
class Spheres {
public:
Vec3 center, color;
float radius;
int opticalProp;
Spheres() {
radius = 0;
}
Spheres(float a, float b, float c, float r, int t) {
center.x = a; center.y = b; center.z = c;
radius = r;
opticalProp = t;
color = Vec3(1, 1, 1);
}
float sIntersect(Vec3, Vec3);
Vec3 sNormal(Vec3);
};
/* Plane defines the wall of the box
* {xAxis, 2} implies plane at x = 2
* Planes are assumed to be diffused
* with diffuse component kd of .5
*/
class Planes {
public:
enum Axis axis;
Vec3 color;
float distanceFromO;
int opticalProp;
Planes(enum Axis a, float d, float r, float g, float b) {
axis = a;
distanceFromO = d;
color.x = r; color.y = g; color.z = b;
opticalProp = 0;
}
float pIntersect(Vec3, Vec3);
Vec3 pNormal(Vec3, PhotonRay);
};
/*
* stores indices of intersected objects
*/
class ObjectIntersection {
public:
int index, type;
float dist;
ObjectIntersection() {
dist = NOT_INTERSECTED;
index = -1;
type = -1;
}
};
/*
* Origin and direction of ray
*/
class PhotonRay {
public:
Vec3 origin;
Vec3 direction;
float color[3];
PhotonRay(){
origin = Vec3();
direction = Vec3();
}
PhotonRay(Vec3 o) {
origin = o;
direction = Vec3();
}
void randDir(float);
void specularReflect(Vec3, Vec3);
void refract(Vec3, Vec3, float&);
void pureDiffuse(Vec3, Vec3);
ObjectIntersection* tracePhotonRay(vector<Spheres*>, vector<Planes*>);
};
class Light {
public:
const int numPhotons = nPhotons;
Vec3 pos;
float power;
float color[3];
Light(Vec3 a, float x) {
pos = a;
power = x;
}
};
class Scene {
public:
float eye[4];
float transmat[6];
bool viewMap, empty;
float X, Y, Z;
int pCol, pRow, pIteration, res;
int time;
Light *light;
// One map for diffuse reflection, one for other interactions
PhotonMap *map, *globalMap;
vector<Spheres*> spheres;
vector<Planes*> planes;
Scene();
void init();
void close();
void render();
void castPhotons();
void drawScene();
void setCamera(float*);
};