-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshapes.h
73 lines (63 loc) · 1.35 KB
/
shapes.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
#ifndef PATHTRACE_SHAPES_H
#define PATHTRACE_SHAPES_H
#include "linalg.h"
class Hit {
public:
Ray ray;
double distance;
Vector3 normal;
Hit()
: ray(Vector3(), Vector3()), distance(-1), normal()
{ }
Hit(Ray const &ray, double const distance, Vector3 const &normal)
: ray(ray), distance(distance), normal(normal)
{ }
bool is_hit() {
return distance > 0;
}
};
class Shape {
public:
virtual Hit intersect(Ray const &ray) const = 0;
virtual Shape* clone() const = 0;
};
class Sphere : public Shape {
private:
Vector3 center;
double radius;
public:
Sphere(Vector3 const ¢er, double const radius)
: center(center), radius(radius)
{ }
virtual Hit intersect(Ray const &ray) const;
virtual Sphere* clone() const;
};
class Plane : public Shape {
private:
Vector3 point;
Vector3 normal;
public:
Plane(Vector3 const &point, Vector3 const &normal)
: point(point), normal(normal)
{
this->normal.normalize();
}
virtual Hit intersect(Ray const &ray) const;
virtual Plane* clone() const;
};
class Difference : public Shape {
private:
Shape *base, *cut;
public:
Difference(Shape const &base, Shape const &cut)
: base(base.clone()), cut(cut.clone())
{ }
virtual Hit intersect(Ray const &ray) const;
virtual Difference* clone() const;
};
/*
Local Variables:
mode:c++
End:
*/
#endif /* PATHTRACE_SHAPES_H */