-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlane.h
58 lines (51 loc) · 1.23 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_INCLUDED
#define PLANE_H_INCLUDED
#include"Object.h"
#include"Vector.h"
#include"Ray.h"
#include"Color.h"
class Plane : public Object
{
private:
Vec3 normal;
double distanceFromOrigin;
Color color;
public:
Plane()
{
normal = Vec3(0,1,0);
distanceFromOrigin = 0.0;
color = Color(1,0,0,0);
}
Plane(Vec3 n , double distance , Color c)
{
normal = n.getNormalized();
distanceFromOrigin = distance;
color = c;
}
Vec3 getNormal() { return normal;}
double getDistance() { return distanceFromOrigin;}
Color getColor() { return color;}
void setNormal(Vec3 n) { normal = n.getNormalized();}
void setDistance(double d) { distanceFromOrigin = d;}
void setColor(Color c) { color = c; }
Vec3 getNormalAt(Vec3 point)
{
return normal;
}
double findIntersection(Ray ray)
{
Vec3 rayDir = ray.getRayDirection();
double a = rayDir.dot(normal);
if(a == 0)
{
return -1;
}
else
{
double b =normal.dot(ray.getRayOrigin().add(normal.scale(distanceFromOrigin).getNegative()));
return -1*b/a;
}
}
};
#endif // PLANE_H_INCLUDED