-
Notifications
You must be signed in to change notification settings - Fork 0
/
Plane.cpp
48 lines (33 loc) · 863 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
43
44
45
46
47
48
/*
* File: Plane.cpp
* Author: gabriel
*
* Created on May 15, 2011, 6:27 PM
*/
#include "Plane.h"
#include "externs.h"
Plane::Plane() {
normal = new Vertex();
point = new Vertex();
d = 0;
}
Plane::Plane(Vertex *v1, Vertex *v2, Vertex *v3) {
set3Points(v1, v2, v3);
}
void Plane::set3Points(Vertex* v1, Vertex* v2, Vertex* v3) {
Vertex aux1, aux2;
aux1 = *v1 - *v2;
aux2 = *v3 - *v2;
*normal = aux2 * aux1;
normal->normalize();
point = new Vertex(v2->x, v2->y, v2->z);
d = -(normal->inner_product(point));
}
void Plane::setNormalAndPoint(Vertex* normal, Vertex* point) {
this->normal = new Vertex ( normal->x, normal->y, normal->z);
this->normal->normalize();
d = -(this->normal->inner_product(point));
}
float Plane::distance(Vertex* p) {
return (d + normal->inner_product(p));
}