-
Notifications
You must be signed in to change notification settings - Fork 1
/
Plane.cpp
70 lines (50 loc) · 1009 Bytes
/
Plane.cpp
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
#include "Plane.h"
const double Plane::kEpsilon = 0.001;
Plane::Plane(void)
: GeometricObject(),
a(0.0),
n(0, 1, 0)
{}
Plane::Plane(const Point3D& point, const Normal& normal)
: GeometricObject(),
a(point),
n(normal)
{
n.normalize();
}
Plane::Plane(const Plane& plane)
: GeometricObject(plane),
a(plane.a),
n(plane.n)
{}
Plane* Plane::clone(void) const {
return(new Plane(*this));
}
Plane& Plane::operator= (const Plane& rhs) {
if(this == &rhs)
return (*this);
GeometricObject::operator= (rhs);
a = rhs.a;
n = rhs.n;
return(*this);
}
Plane::~Plane(void)
{}
bool Plane::hit(const Ray& ray, double& tmin, ShadeRec& sr) const {
float t = (a - ray.o) * n / (ray.d * n);
if(t > kEpsilon) {
tmin = t;
sr.normal = n;
sr.local_hit_point = ray.o + t * ray.d;
return (true);
}
return(false);
}
bool Plane::shadow_hit(const Ray& ray, float& tmin) const {
float t = (a - ray.o) * n / (ray.d * n);
if(t > kEpsilon) {
tmin = t;
return(true);
}
return(false);
}