-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlane.h
58 lines (44 loc) · 1.04 KB
/
Plane.h
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
#ifndef PLANE_H
#define PLANE_H
#include "math.h"
#include "Object.h"
#include "Vect.h"
#include "Color.h"
class Plane : public Object {
Vect normal;
double distance;
Color color;
public:
Plane ();
Plane (Vect, double, Color);
// method functions
Vect getPlaneNormal () { return normal; }
double getPlaneDistance () { return distance; }
virtual Color getColor () { return color; }
virtual Vect getNormalAt(Vect point) {
return normal;
}
virtual double findIntersection(Ray ray) {
Vect ray_direction = ray.getRayDirection();
double a = ray_direction.dotProduct(normal);
if (a == 0) {
// ray is parallel to the plane
return -1;
}
else {
double b = normal.dotProduct(ray.getRayOrigin().vectAdd(normal.vectMult(distance).negative()));
return -1*b/a;
}
}
};
Plane::Plane () {
normal = Vect(1,0,0);
distance = 0;
color = Color(0.5,0.5,0.5, 0);
}
Plane::Plane (Vect normalValue, double distanceValue, Color colorValue) {
normal = normalValue;
distance = distanceValue;
color = colorValue;
}
#endif