-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlane.cpp
More file actions
34 lines (27 loc) · 766 Bytes
/
Copy pathPlane.cpp
File metadata and controls
34 lines (27 loc) · 766 Bytes
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
#include "Plane.hpp"
#include "Vec.hpp"
#include "rt.hpp"
#include <cmath>
Plane::Plane(const Vec& normal_in, double D_in, const Color& c1, const Color& c2)
: Object(c1, c2), normal(normal_in), D(D_in) {
if (c1.getR() == c2.getR() &&
c1.getG() == c2.getG() &&
c1.getB() == c2.getB()) {
checker = 0;
} else {
checker = 1;
} // assign checker value in constructor
}
bool Plane::intersect(const RAY_T& ray, double& t, Vec& int_pt, Vec& normal_out) const {
double dp = ray.dir.dot(normal);
if (dp == 0) {
return false;
}
t = -(ray.origin.dot(normal) + D) / dp;
if (t < 0) {
return false;
}
int_pt = ray.origin + ray.dir * t;
normal_out = normal;
return true;
}