-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlane.cpp
More file actions
35 lines (29 loc) · 677 Bytes
/
Copy pathPlane.cpp
File metadata and controls
35 lines (29 loc) · 677 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
35
#include "Plane.h"
Plane::Plane(){
normal = Vector(1, 0, 0);
distance = 1.0;
color = Color(0.5, 0.5, 0.5, 0);
}
Plane::Plane(Vector normalValue, double distanceValue, Color colorValue){
normal = normalValue;
distance = distanceValue;
color = colorValue;
}
Color Plane::getColor(){
return color;
}
Vector Plane::getNormalAt(Vector point){
return normal;
}
double Plane::findIntersection(Ray ray){
Vector rayDirection = ray.getRayDirection();
double a = rayDirection.dot(normal);
if (a == 0){
// ray is parallel to the plane
return -1.0;
}
else{
double b = normal.dot(ray.getRayOrigin().add(normal.mult(distance).negative()));
return -1.0 * b / a;
}
}