-
Notifications
You must be signed in to change notification settings - Fork 0
/
plane.cpp
44 lines (41 loc) · 1.05 KB
/
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
#include "plane.h"
#include "ray.h"
#include <cfloat>
#include <limits>
// Intersect with the half space defined by the plane. The plane's normal
// points outside. If the ray starts on the "inside" side of the plane, be sure
// to record a hit with t=0 as the first entry in hits.
Hit Plane::Intersection(const Ray& ray, int part) const
{
Hit hit;
double t;
double U;
vec3 W = ray.endpoint - x1; // E - x1
U = dot(ray.direction, normal);
if(U == 0){
hit = {0, 0, 0}; //no intersection
}
else{
t = (-1)*dot(W, normal)/U;
if(t > small_t){
hit = {this, t, 1};
}
else{
hit = {0, 0, 0};
}
}
return hit;
}
vec3 Plane::Normal(const vec3& point, int part) const
{
return normal;
}
// There is not a good answer for the bounding box of an infinite object.
// The safe thing to do is to return a box that contains everything.
Box Plane::Bounding_Box(int part) const
{
Box b;
b.hi.fill(std::numeric_limits<double>::max());
b.lo=-b.hi;
return b;
}