-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgeometries.h
141 lines (105 loc) · 2.06 KB
/
geometries.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
/*
* @file: geometries.h
* @author: Ondrej Hirjak, 2009
* @description:
*/
#ifndef geometries_h
#define geometries_h
class Vector3D;
class Point3D
{
public:
double x, y, z;
Point3D() : x(0.0), y(0.0), z(0.0) { }
Point3D(const Point3D &p) : x(p.x), y(p.y), z(p.z) { }
Point3D(double d1, double d2, double d3) : x(d1), y(d2), z(d3) { }
};
class Vector3D : public Point3D
{
public:
Vector3D() : Point3D() { }
Vector3D(const Point3D &p) : Point3D(p) { }
Vector3D(double d1, double d2, double d3) : Point3D(d1, d2, d3) { }
Vector3D Normalize() const;
static double DotProduct(Vector3D v1, Vector3D v2)
{
return v1.x * v2.x + v1.y * v2.y + v1.z * v2.z;
}
Vector3D operator +(Vector3D p);
Vector3D operator -(Vector3D p);
Vector3D operator *(double t);
};
class Ray
{
private:
Point3D p;
Vector3D v;
public:
Ray(Point3D p1, Point3D p2)
{
p = p1;
v = (Vector3D)p2 - p1;
v = v.Normalize();
}
Ray(Point3D p1, Vector3D v1)
{
p = p1;
v = v1.Normalize();
}
Point3D& Point()
{
return p;
}
Vector3D& Vector()
{
return v;
}
};
struct IntersectData
{
Point3D contact;
Vector3D normal;
Color color;
};
class GeometryObject
{
protected:
Point3D center;
Color color;
double reflection;
double refraction;
public:
GeometryObject(Point3D p, Color c) : center(p), color(c), reflection(0.0), refraction(0.0) { }
void SetReflection(double r)
{
reflection = r;
}
double GetReflection()
{
return reflection;
}
void SetRefraction(double r)
{
refraction = r;
}
double GetRefraction()
{
return refraction;
}
virtual double RayIntersect(Ray &ray, IntersectData *intersectData) = 0;
};
class Sphere : public GeometryObject
{
private:
double radius;
public:
Sphere(Point3D p, Color c, double r) : GeometryObject(p, c), radius(r) { }
double RayIntersect(Ray &ray, IntersectData *intersectData);
};
class Plane; // TODO
class Triangle; // TODO
class Polygon; // TODO
class Box; // TODO
class Cylinder; // TODO
class Quadric; // TODO
#endif // geometries_h