mElite  1.0
An Elite clone based on TextElite by Jan-Philipp Kappmeier and Melanie Schmidt.
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Plane.cpp
Go to the documentation of this file.
1 
6 #include "Plane.h"
7 
11 Plane::Plane( const Vector3 &v1, const Vector3 &v2, const Vector3 &v3 ) {
12  setPlane(v1,v2,v3);
13 }
14 
18 Plane::Plane( Vector3 normal, Vector3 point){
19  setPlane(normal,point);
20 }
21 
23 
24 Plane::~Plane( void ) { }
25 
32 void Plane::setPlane( const Vector3 &v1, const Vector3 &v2, const Vector3 &v3 ) {
33  Vector3 aux1, aux2;
34  Vector3 h1 = v1;
35  Vector3 h3= v3;
36  aux1 = h1 - v2;
37  aux2 = h3 - v2;
38  normal = aux2 * aux1;
39  normal.normalize();
40  point.copy(v2);
41  d = -(normal.innerProduct(point));
42 }
43 
49 void Plane::setPlane( const Vector3 &normal, const Vector3 &point ) {
50  this->normal.copy( normal );
51  this->point.copy( point );
52  this->normal.normalize();
53  d = -(this->normal.innerProduct(point));
54 }
55 
64 void Plane::setPlane( float a, float b, float c, float d ) {
65  // set the normal vector
66  normal.set(a,b,c);
67  //compute the lenght of the vector
68  float l = normal.length();
69  // normalize the vector
70  normal.set(a/l,b/l,c/l);
71  // and divide d by th length as well
72  this->d = d/l;
73 }
74 
80 float Plane::distance( const Vector3 &p ) {
81  return d + normal.innerProduct(p);
82 }
83 
88  return this->normal;
89 }