-
Notifications
You must be signed in to change notification settings - Fork 1
/
shape.h
125 lines (91 loc) · 2.97 KB
/
shape.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
#pragma once
#include <vector>
#include "vectormath.h"
#include "color.h"
#include "ray.h"
struct MaterialProperty {
Color surfaceColor, emissionColor;
float transparency, reflection, refractiveIndex;
};
class Shape {
public:
virtual ~Shape() {}
// virtual functions because we are going to be calling these methods from
// the Base pointer
virtual bool intersect(Intersection& intersection) = 0;
virtual bool doesIntersect(const Ray& ray) = 0;
virtual Vector getNormalVector(const Point& pHit) = 0;
virtual MaterialProperty getMaterialProperty() = 0;
};
class ShapeSet: public Shape {
protected:
std::vector<Shape*> shapes;
public:
ShapeSet();
virtual ~ShapeSet();
void addShape(Shape* shape);
virtual bool intersect(Intersection& intersection);
virtual bool doesIntersect(const Ray& ray);
virtual Vector getNormalVector(const Point& pHit) { return Vector();} // because they were pure
virtual MaterialProperty getMaterialProperty() { return MaterialProperty();} // virtual functions
};
class Plane : public Shape
{
protected:
Point position;
Vector normal;
Color surfaceColor, emissionColor;
float transparency, reflection; // from 0 and 1
float refractiveIndex;
public:
Plane() {}
Plane(const Point& position, const Vector& normal,
const Color& surfaceColor = Color(1.0f, 1.0f, 1.0f),
const float reflection = 0.0f,
const float transparency = 0.0f,
const float refractiveIndex = 1.0f,
const Color& emissionColor = Color(0.0f));
virtual ~Plane();
virtual Vector getNormalVector(const Point& pHit);
virtual MaterialProperty getMaterialProperty();
virtual bool intersect(Intersection& intersection);
virtual bool doesIntersect(const Ray& ray);
};
class Triangle : public Plane {
public:
Point A, B, C; // vertices in counter clockwise order
Point position;
Vector normal;
Color surfaceColor, emissionColor;
float transparency, reflection;
float refractiveIndex;
Triangle (const Point vertices[],
const Color& surfaceColor = Color(1.0f, 1.0f, 1.0f),
const float reflection = 0.0f,
const float transparency = 0.0f,
const float refractiveIndex = 1.0f,
const Color& emissionColor = Color(0.0f));
bool intersect(Intersection& intersection);
bool doesIntersect(const Ray& ray);
};
class Sphere : public Shape
{
protected:
Point center;
float radius;
Color surfaceColor, emissionColor; /// surface color and emission (light)
float transparency, reflection; /// surface transparency and reflectivity
float refractiveIndex; /// from the scale of 0 to 1
public:
Sphere(const Point& center, float radius,
const Color& surfaceColor = Color(1.0f, 1.0f, 1.0f),
const float reflection = 0.0f,
const float transparency = 0.0f,
const float refractiveIndex = 1.5f,
const Color& emissionColor = Color(0.0f));
virtual ~Sphere();
virtual Vector getNormalVector(const Point& pHit);
virtual MaterialProperty getMaterialProperty();
virtual bool intersect(Intersection& intersection);
virtual bool doesIntersect(const Ray& ray);
};