-
Notifications
You must be signed in to change notification settings - Fork 0
/
Plane.cpp
42 lines (33 loc) · 821 Bytes
/
Plane.cpp
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
#include "Plane.h"
#include <glm/glm.hpp>
using namespace glm;
Plane::Plane(void) {
planeNormal = vec3(0);
}
Plane::Plane(vec3 _position, vec3 _normal, vec3 _colour) {
position = _position;
planeNormal = _normal;
colour = _colour;
}
bool Plane::Intersection(vec3 rayOrigin, vec3 rayDirection, float& u, float& v, float& w, float* t)
{
float denom = dot(rayDirection, planeNormal);
if (abs(denom) < 1e-6) {
return false;
}
else if (t <= 0) {
return false;
}
else {
*t = dot((position - rayOrigin), planeNormal) / denom;
return *t >= 0;
}
}
vec3 Plane::CalculateNormal(vec3 p0, float& u, float& v, float& w, int* shininess, vec3* diffuseColour, vec3* specularColour) {
*shininess = 1;
*diffuseColour = vec3(0.6, 0.5, 0.2);
*specularColour = colour;
return planeNormal;
}
Plane::~Plane() {
}