-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplane.cpp
69 lines (42 loc) · 1011 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
// File: plane.cpp
// Author: Samuel McFalls
// Description: Implements the Plane class
#include "plane.hpp"
Plane::Plane() {
color = Color();
lambert = 0;
center = Vec3();
normal = Vec3();
}
Plane::Plane(const Color &colorCon, double lambertCon, const Vec3 ¢erCon, const Vec3 &normalCon) {
color = colorCon;
lambert = lambertCon;
center = centerCon;
normal = normalCon;
}
Vec3 Plane::getNormal() const {
return normal;
}
Vec3 Plane::getCenter() const {
return center;
}
void Plane::setNormal(Vec3 normalSet) {
normal = normalSet;
}
void Plane::setCenter(Vec3 centerSet) {
center = centerSet;
}
double Plane::intersectedBy(Ray ray) const {
Vec3 n = normal.normalize();
Vec3 l = ray.getDirection().normalize();
double denominator = n.dot(l);
double inf = std::numeric_limits<double>::infinity();
if (std::abs(denominator) > 1e-6) {
double t = ((center - ray.getOrigin()).dot(n)) / denominator;
if (t <= 1e-6) {
return inf;
}
return t;
}
return inf;
}