-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplane.cpp
More file actions
119 lines (106 loc) · 2.52 KB
/
Copy pathplane.cpp
File metadata and controls
119 lines (106 loc) · 2.52 KB
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#include "plane.h"
#include "ray.h"
#include <cfloat>
// 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.
bool Plane::
Intersection(const Ray& ray, std::vector<Hit>& hits) const
{
// TODO
/*
u is ray.endpoint
v is ray.direction
n is normal
p is x1
*/
double raydotn = dot(ray.direction, normal);
Hit temp;
if(dot((ray.endpoint - x1), normal) <= 0)
{
if(raydotn < 0)
{
//std::cerr << "RAY Surface TO INSIDE \n";
//ray starts on surface of half plane and never leaves
//first hit point
temp.object = this;
temp.t = 0;
temp.ray_exiting = false;
hits.push_back(temp);
//second hit point
temp.object = this;
temp.t = DBL_MAX;
temp.ray_exiting = false;
hits.push_back(temp);
return true;
}
else if(raydotn > 0)
{
//std::cerr << "RAY Inside to OUTSIDE \n";
//ray starts inside half plane but leaves
//first hit point
temp.object = this;
temp.t = 0;
temp.ray_exiting = false;
hits.push_back(temp);
//second hit point
temp.object = this;
temp.t = - dot((ray.endpoint - x1), normal) / raydotn ;
temp.ray_exiting = true;
hits.push_back(temp);
return true;
}
else
{
//ray has no intersections with surface of plane,
// ray starts inside half space and never leaves
//first hit point
//std::cerr << "RAY inside TO INSIDE \n";
temp.object = this;
temp.t = 0;
temp.ray_exiting = false;
hits.push_back(temp);
//second hit point
temp.object = this;
temp.t = DBL_MAX;
temp.ray_exiting = false;
hits.push_back(temp);
return true;
}
}
else
{
if(raydotn < 0)
{
//std::cerr << "RAY OUTSIDE TO INSIDE \n";
//one intersection, ray starts outside plane
//first hit point
temp.object = this;
temp.t = - dot((ray.endpoint - x1), normal) / raydotn ;
temp.ray_exiting = false;
hits.push_back(temp);
//second hit point
temp.object = this;
temp.t = DBL_MAX;
temp.ray_exiting = false;
hits.push_back(temp);
return true;
}
else if(raydotn > 0)
{
//doesnt intersect with plane
return false;
}
else
{
//doesnt intersect with plane
return false;
}
}
return false;
}
vec3 Plane::
Normal(const vec3& point, int part) const
{
return normal;
}