-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlane.h
72 lines (57 loc) · 1.47 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/* THE PLANE FILE - USED TO CREATE PLANES IN A RAYTRACER */
#ifndef _Plane_H
#define _Plane_H
//Includes
#include "math.h"
#include "Object.h"
#include "Vect.h"
#include "Colour.h"
//The plane class
class Plane : public Object {
//A vector normal to the plane
Vect normal;
//The distance from the center of the scene to the plane
double distance;
//The colour of the plane
Colour colour;
public:
//Constructor functions
Plane ();
Plane (Vect, double, Colour);
//Method functions
//Getters
Vect getPlaneNormal () { return normal; }
double getPlaneDistance () { return distance; }
virtual Colour getColour () { return colour; }
//Get the normal of the plane
virtual Vect getNormalAt(Vect point) {
return normal;
}
//Find the intersection between a ray and a plane
virtual double findIntersection(Ray ray) {
Vect ray_direction = ray.getRayDirection();
double a = ray_direction.dotProduct(normal);
//The case where the ray is parallel to the plane
if (a == 0) {
return -1;
}
//The case where the ray and the plane will intersect
else {
double b = normal.dotProduct(ray.getRayOrigin().vectAdd(normal.vectMult(distance).negative()));
return -1*b/a;
}
}
};
//Set the default plane
Plane::Plane () {
normal = Vect(1,0,0);
distance = 0;
colour = Colour(0.5,0.5,0.5, 0);
}
//Define a plane
Plane::Plane (Vect normalValue, double distanceValue, Colour ColourValue) {
normal = normalValue;
distance = distanceValue;
colour = ColourValue;
}
#endif