-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGeoObject.h
189 lines (144 loc) · 3.53 KB
/
GeoObject.h
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
186
187
188
#include "RaytraceHelpers.h"
#include "VectorHelpers.h"
/*
This file has information on GeoObject and its subclasses.
-RB Johnson, 10/5/2016
*/
/*
The GeoObject class is the super class to all the objects used by the raytracer.
It has two methods and two virtual methods:
getCenter - Returns an array of doubles corisponding to the center of the object.
getMaterial - Returns a pointer to a Material object defining the material of the object.
hit - A virtual method. It takes a pointer to a Ray object and an array of doubles. The array should be filled by the method with the point where the ray intersects the object. If it doesn't intersect the array should be filled with the source location of the ray.
getNormal - A virtual method. It takes two arrays of doubles. The first array should be a point on the object. The method should then fill the second array with a vector that is normal to the object at the specified point
*/
class GeoObject
{
public:
double* getCenter() { return center; }
virtual double* hit(Ray* r,double* intersect) { return intersect; }
virtual double* getNormal(double* loc,double* ans) { return ans; }
Material* getMaterial() { return mat;}
protected:
double *center;
Material *mat;
};
/*
The Plane object is a subclass of GeoObject. It represents a flat plane
*/
class Plane : public GeoObject
{
public:
Plane(double* cord,double* n,Material* m)
{
mat = m;
normal = new double[3];
normalize(n,normal);
center = cord;
delete [] n;
}
double* hit(Ray* r,double* intersect);
double* getNormal(double* loc,double* ans)
{
ans[0] = normal[0];
ans[1] = normal[1];
ans[2] = normal[2];
return ans;
}
~Plane()
{
delete [] center;
delete mat;
delete [] normal;
}
private:
double* normal;
};
/*
The Sphere class is a subclass of GeoObject. It represents a sphere.
*/
class Sphere: public GeoObject
{
public:
Sphere(double* cen,double r,Material* m)
{
center = cen;
radius = r;
mat = m;
}
double* hit(Ray* r,double* intersect);
double* getNormal(double* loc,double* ans)
{
subtract(loc,center,ans);
normalize(ans,ans);
return ans;
}
~Sphere()
{
delete [] center;
delete mat;
}
private:
double radius;
};
/*
The Tetrahedron class is a subclass of GeoObject. It represents a regular four faced polyhedron with triangular faces.
*/
class Tetrahedron: public GeoObject
{
public:
Tetrahedron(double* cen,double l,Material* m);
double* hit(Ray* r,double* intersect);
double* getNormal(double* loc,double* ans);
~Tetrahedron()
{
delete [] vertexes[0];
delete [] vertexes[1];
delete [] vertexes[2];
delete [] vertexes[3];
delete [] vertexes;
delete [] normals[0];
delete [] normals[1];
delete [] normals[2];
delete [] normals[3];
delete [] normals;
delete [] center;
delete mat;
}
private:
double** vertexes;
double** normals;
double length;
};
/*
The Dodecahedron class is a subclass of GeoObject. It represents a regular twelve faced polyhedron with pentagonal faces.
*/
class Dodecahedron: public GeoObject
{
public:
Dodecahedron(double* cen,double l,Material* m);
double* hit(Ray* r,double* intersect);
double* getNormal(double* loc,double* ans);
~Dodecahedron()
{
for(int i=0;i<20;i++)
{
delete [] vertexes[i];
}
for(int i=0;i<12;i++)
{
delete [] faces[i];
delete [] normals[i];
}
delete [] vertexes;
delete [] faces;
delete [] normals;
delete [] center;
delete mat;
}
private:
double** vertexes;
double** normals;
int** faces;
double length;
};