Main Page | Namespace List | Class Hierarchy | Alphabetical List | Data Structures | File List | Namespace Members | Data Fields | Globals

pge::Plane Class Reference

#include <Plane.h>

Collaboration diagram for pge::Plane:

Collaboration graph
[legend]

Public Member Functions

 Plane (void)
 Standard constructor.

 Plane (Vector3f a, Vector3f b, Vector3f c)
 Create a plane out of the three points.

 Plane (Vector3f start, Vector3f u, Vector3f v, int i)
 Create a plane out of a startpoint and two vectors.

 Plane (Vector3f normal, float d)
 Create a plane out of the normal and the d component.

 Plane (Triangle *triangle)
 Create a plane from a triangle.

 ~Plane (void)
 Destructor.

float a (void)
 Return A component.

float b (void)
 Return B component.

float c (void)
 Return C component.

float d (void)
 Return D component.

bool isPointOnPlane (Vector3f point)
 Returns 1 if the point is on the plane.

float getDistanceToPoint (Vector3f point)
 Returns the distance to the nearest point on the plane.

Vector3f getFootPoint (Vector3f point)
 Returns the nearest point on the plane from the given point.

Vector3f getIntersectionPoint (Vector3f lineStart, Vector3f lineEnd)
 Returns the intersection point of a line and the plane.

bool isLineIntersecting (Vector3f lineStart, Vector3f lineEnd)
 Checks if a line intersects this plane.

std::string toString (void)
 Prints the plane's data out.


Data Fields

Vector3f m_normal
float m_d

Constructor & Destructor Documentation

pge::Plane::Plane void   ) 
 

Standard constructor.

Definition at line 22 of file Plane.cpp.

References m_d.

00022                          {
00023                 m_d = 0.0f;
00024         }

pge::Plane::Plane Vector3f  a,
Vector3f  b,
Vector3f  c
 

Create a plane out of the three points.

Definition at line 32 of file Plane.cpp.

References pge::Vector3f::crossProduct(), pge::Vector3f::dotProduct(), m_d, m_normal, pge::Vector3f::normalize(), and pge::Vector3f::subtract().

00032                                                        {
00033                 Vector3f u;
00034                 Vector3f v;
00035 
00036                 // Get the spanning vectors for the plane.
00037                 u = b.subtract(a);
00038                 v = c.subtract(a);
00039 
00040                 m_normal = u.crossProduct(v);
00041                 m_normal.normalize();
00042 
00043                 m_d = -(a.dotProduct(m_normal));
00044         }

Here is the call graph for this function:

pge::Plane::Plane Vector3f  start,
Vector3f  u,
Vector3f  v,
int  i
 

Create a plane out of a startpoint and two vectors.

Definition at line 52 of file Plane.cpp.

References pge::Vector3f::crossProduct(), pge::Vector3f::dotProduct(), m_d, m_normal, and pge::Vector3f::normalize().

00052                                                                   {
00053                 m_normal = u.crossProduct(v);
00054                 m_normal.normalize();
00055                 m_d = -(start.dotProduct(m_normal));
00056         }

Here is the call graph for this function:

pge::Plane::Plane Vector3f  normal,
float  d
 

Create a plane out of the normal and the d component.

Definition at line 64 of file Plane.cpp.

References m_d, m_normal, and pge::Vector3f::normalize().

00064                                              {
00065                 normal.normalize();
00066                 m_normal = normal;
00067                 m_d = d;
00068         }

Here is the call graph for this function:

pge::Plane::Plane Triangle triangle  ) 
 

Create a plane from a triangle.

Definition at line 76 of file Plane.cpp.

References a(), b(), c(), pge::Vector3f::crossProduct(), pge::Vector3f::dotProduct(), m_d, m_normal, pge::Triangle::m_vertices, pge::Vector3f::normalize(), and pge::Vector3f::subtract().

00076                                        {
00077                 Vector3f a;
00078                 Vector3f b;
00079                 Vector3f c;
00080                 Vector3f u;
00081                 Vector3f v;
00082 
00083                 a = triangle->m_vertices[0];
00084                 b = triangle->m_vertices[1];
00085                 c = triangle->m_vertices[2];
00086 
00087                 // Get the spanning vectors for the plane.
00088                 u = b.subtract(a);
00089                 v = c.subtract(a);
00090 
00091                 m_normal = u.crossProduct(v);
00092                 m_normal.normalize();
00093 
00094                 m_d = -(a.dotProduct(m_normal));
00095         }

Here is the call graph for this function:

pge::Plane::~Plane void   ) 
 

Destructor.

Definition at line 103 of file Plane.cpp.

00103                           {
00104         }


Member Function Documentation

float pge::Plane::a void   )  [inline]
 

Return A component.

Definition at line 46 of file Plane.h.

References m_normal, and pge::Vector3f::m_v.

Referenced by Plane().

00046                               {
00047                         return m_normal.m_v[0];
00048                 }

float pge::Plane::b void   )  [inline]
 

Return B component.

Definition at line 51 of file Plane.h.

References m_normal, and pge::Vector3f::m_v.

Referenced by Plane().

00051                               {
00052                         return m_normal.m_v[1];
00053                 }

float pge::Plane::c void   )  [inline]
 

Return C component.

Definition at line 56 of file Plane.h.

References m_normal, and pge::Vector3f::m_v.

Referenced by Plane().

00056                               {
00057                         return m_normal.m_v[2];
00058                 }

float pge::Plane::d void   )  [inline]
 

Return D component.

Definition at line 61 of file Plane.h.

References m_d.

Referenced by isPointOnPlane().

00061                               {
00062                         return m_d;
00063                 }

float pge::Plane::getDistanceToPoint Vector3f  point  ) 
 

Returns the distance to the nearest point on the plane.

The function uses the nearest footpoint on the plane and returns the distance between the footpoint and the given point.

Definition at line 135 of file Plane.cpp.

References pge::Vector3f::dotProduct(), m_d, and m_normal.

Referenced by isPointOnPlane().

00135                                                       {
00136                 return m_normal.dotProduct(point) + m_d;
00137         }

Here is the call graph for this function:

Vector3f pge::Plane::getFootPoint Vector3f  point  ) 
 

Returns the nearest point on the plane from the given point.

Definition at line 145 of file Plane.cpp.

References pge::Vector3f::dotProduct(), m_d, m_normal, pge::Vector3f::multiply(), and pge::Vector3f::subtract().

00145                                                    {
00146                 float n;
00147                 Vector3f v;
00148                 n = (m_normal.dotProduct(point) + m_d) / m_normal.dotProduct(m_normal);
00149                 v = m_normal.multiply(n);
00150                 v = point.subtract(v);
00151                 return v;
00152         }

Here is the call graph for this function:

Vector3f pge::Plane::getIntersectionPoint Vector3f  lineStart,
Vector3f  lineEnd
 

Returns the intersection point of a line and the plane.

Definition at line 160 of file Plane.cpp.

References pge::Vector3f::dotProduct(), m_d, m_normal, pge::Vector3f::m_v, pge::Vector3f::normalize(), PLANE_ZERO_TOLERANCE, and pge::Vector3f::subtract().

Referenced by pge::Mesh::getHeightAt().

00160                                                                                  {
00161                 //
00162                 // Variables
00163                 //
00164                 Vector3f lineDirection;
00165                 Vector3f result;
00166                 float distPoint;
00167                 float dotLine;
00168                 float distance;
00169 
00170 
00171                 lineDirection = lineEnd.subtract(lineStart);
00172                 lineDirection.normalize();
00173 
00174 
00175                 distPoint = -(m_normal.m_v[0] * lineStart.m_v[0] +
00176                         m_normal.m_v[1] * lineStart.m_v[1] +
00177                         m_normal.m_v[2] * lineStart.m_v[2] + m_d);
00178 
00179                 dotLine = m_normal.dotProduct(lineDirection);
00180 
00181                 /*if(dotLine == 0.0f) {
00182                         return lineStart;
00183                 }*/
00184                 if(mathutils::isValueInTolerance(dotLine, 0.0f, PLANE_ZERO_TOLERANCE)) {
00185                         return lineStart;
00186                 }
00187 
00188 
00189                 distance = distPoint / dotLine;
00190 
00191                 result.m_v[0] = lineStart.m_v[0] + (lineDirection.m_v[0] * distance);
00192                 result.m_v[1] = lineStart.m_v[1] + (lineDirection.m_v[1] * distance);
00193                 result.m_v[2] = lineStart.m_v[2] + (lineDirection.m_v[2] * distance);
00194 
00195                 return result;
00196         }

Here is the call graph for this function:

bool pge::Plane::isLineIntersecting Vector3f  lineStart,
Vector3f  lineEnd
 

Checks if a line intersects this plane.

Definition at line 204 of file Plane.cpp.

References m_d, m_normal, and pge::Vector3f::m_v.

00204                                                                            {
00205                 //
00206                 // Variables
00207                 //
00208                 float dist1;
00209                 float dist2;
00210 
00211 
00212                 dist1 = 0.0f;
00213                 dist2 = 0.0f;
00214 
00215                 dist1 = ((m_normal.m_v[0] * lineStart.m_v[0]) +
00216                         (m_normal.m_v[1] * lineStart.m_v[1]) +
00217                         (m_normal.m_v[2] * lineStart.m_v[2])) + m_d;
00218 
00219                 dist2 = ((m_normal.m_v[0] * lineEnd.m_v[0]) +
00220                         (m_normal.m_v[1] * lineEnd.m_v[1]) +
00221                         (m_normal.m_v[2] * lineEnd.m_v[2])) + m_d;
00222 
00223                 if(dist1 * dist2 >= 0.0f) {
00224                         return false;
00225                 }
00226 
00227                 return true;
00228         }

bool pge::Plane::isPointOnPlane Vector3f  point  ) 
 

Returns 1 if the point is on the plane.

Definition at line 112 of file Plane.cpp.

References d(), getDistanceToPoint(), and PLANE_ZERO_TOLERANCE.

00112                                                  {
00113                 /*float d;
00114                 bool ret;
00115 
00116                 d = getDistanceToPoint(point);
00117                 ret = (d == 0.0f);
00118                 return ret;*/
00119 
00120                 float d;
00121 
00122                 d = getDistanceToPoint(point);
00123 
00124                 // This seems to work pretty well.
00125                 return mathutils::isValueInTolerance(d, 0.0f, PLANE_ZERO_TOLERANCE);
00126 
00127         }

Here is the call graph for this function:

std::string pge::Plane::toString void   ) 
 

Prints the plane's data out.

Definition at line 236 of file Plane.cpp.

00236                                   {
00237                 //printf("normal: %f %f %f\n", m_normal.m_v[0], m_normal.m_v[1], m_normal.m_v[2]);
00238                 //printf("     D: %f\n", m_d);
00239                 return std::string("TODO");
00240         }


Field Documentation

float pge::Plane::m_d
 

Definition at line 92 of file Plane.h.

Referenced by d(), getDistanceToPoint(), getFootPoint(), getIntersectionPoint(), isLineIntersecting(), and Plane().

Vector3f pge::Plane::m_normal
 

Definition at line 91 of file Plane.h.

Referenced by a(), pge::VBO::addTriangle(), b(), c(), getDistanceToPoint(), getFootPoint(), getIntersectionPoint(), isLineIntersecting(), Plane(), and pge::Mesh::renderImmediate().


The documentation for this class was generated from the following files:
Generated on Mon Oct 16 12:09:27 2006 for Phobosengine by doxygen 1.3.4