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

pge::Frustum Class Reference

#include <Frustum.h>


Public Member Functions

 Frustum (void)
 Constructor.

 ~Frustum (void)
 Destructor.

void update (void)
 This function updates the frustum from the 3d matrices.

bool isPointInside (Vector3f v)
 Test if a point lies inside of the frustum.

bool isPointInside (float x, float y, float z)
bool isAABBInside (AABB *aabb)
float getDistanceToPlane (int plane, float x, float y, float z)

Private Member Functions

void normalizePlane (int plane)
 Normalize a plane.


Private Attributes

float m_frustum [6][4]


Constructor & Destructor Documentation

pge::Frustum::Frustum void   ) 
 

Constructor.

Definition at line 19 of file Frustum.cpp.

00019                              {
00020         }

pge::Frustum::~Frustum void   ) 
 

Destructor.

Definition at line 28 of file Frustum.cpp.

00028                               {
00029         }


Member Function Documentation

float pge::Frustum::getDistanceToPlane int  plane,
float  x,
float  y,
float  z
 

Definition at line 200 of file Frustum.cpp.

References m_frustum.

Referenced by isAABBInside().

00200                                                                               {
00201                 return m_frustum[plane][0] * x + m_frustum[plane][1] * y + m_frustum[plane][2] * z
00202                         + m_frustum[plane][3];
00203         }

bool pge::Frustum::isAABBInside AABB aabb  ) 
 

Definition at line 166 of file Frustum.cpp.

References getDistanceToPlane(), pge::AABB::m_maxX, pge::AABB::m_maxY, pge::AABB::m_maxZ, pge::AABB::m_minX, pge::AABB::m_minY, and pge::AABB::m_minZ.

00166                                              {
00167                 int i;
00168 
00169 
00170                 // Check each plane. The AABB must be completely outside of at least one
00171                 // plane of the frustum, then it is not visible.
00172                 for(i = 0; i < 6; i++) {
00173                         if(getDistanceToPlane(i, aabb->m_minX, aabb->m_minY, aabb->m_minZ) > 0.0f)
00174                                 continue;
00175                         if(getDistanceToPlane(i, aabb->m_maxX, aabb->m_minY, aabb->m_minZ) > 0.0f)
00176                                 continue;
00177                         if(getDistanceToPlane(i, aabb->m_minX, aabb->m_maxY, aabb->m_minZ) > 0.0f)
00178                                 continue;
00179                         if(getDistanceToPlane(i, aabb->m_maxX, aabb->m_maxY, aabb->m_minZ) > 0.0f)
00180                                 continue;
00181                         if(getDistanceToPlane(i, aabb->m_minX, aabb->m_minY, aabb->m_maxZ) > 0.0f)
00182                                 continue;
00183                         if(getDistanceToPlane(i, aabb->m_maxX, aabb->m_minY, aabb->m_maxZ) > 0.0f)
00184                                 continue;
00185                         if(getDistanceToPlane(i, aabb->m_minX, aabb->m_maxY, aabb->m_maxZ) > 0.0f)
00186                                 continue;
00187                         if(getDistanceToPlane(i, aabb->m_maxX, aabb->m_maxY, aabb->m_maxZ) > 0.0f)
00188                                 continue;
00189                         return false;
00190                 }
00191                 return true;
00192         }

Here is the call graph for this function:

bool pge::Frustum::isPointInside float  x,
float  y,
float  z
 

Definition at line 148 of file Frustum.cpp.

References m_frustum.

00148                                                              {
00149                 int i;
00150 
00151 
00152                 for(i = 0; i < 6; i++) {
00153                         if((m_frustum[i][0] * x + m_frustum[i][1] * y + m_frustum[i][2] * z + m_frustum[i][3]) <= 0.0f) {
00154                                 return false;
00155                         }
00156                 }
00157                 return true;
00158         }

bool pge::Frustum::isPointInside Vector3f  v  ) 
 

Test if a point lies inside of the frustum.

Definition at line 130 of file Frustum.cpp.

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

00130                                               {
00131                 int i;
00132 
00133 
00134                 for(i = 0; i < 6; i++) {
00135                         if((m_frustum[i][0] * v.m_v[0] + m_frustum[i][1] * v.m_v[1] + m_frustum[i][2] * v.m_v[2] + m_frustum[i][3]) <= 0.0f) {
00136                                 return false;
00137                         }
00138                 }
00139                 return true;
00140         }

void pge::Frustum::normalizePlane int  plane  )  [private]
 

Normalize a plane.

Definition at line 111 of file Frustum.cpp.

References m_frustum.

Referenced by update().

00111                                               {
00112                 float mag;
00113 
00114 
00115                 mag = (float)sqrt((double)(m_frustum[plane][0] * m_frustum[plane][0] + m_frustum[plane][1] * m_frustum[plane][1] +
00116                         m_frustum[plane][2] * m_frustum[plane][2]));
00117 
00118                 m_frustum[plane][0] = m_frustum[plane][0] / mag;
00119                 m_frustum[plane][1] = m_frustum[plane][1] / mag;
00120                 m_frustum[plane][2] = m_frustum[plane][2] / mag;
00121                 m_frustum[plane][3] = m_frustum[plane][3] / mag;
00122         }

void pge::Frustum::update void   ) 
 

This function updates the frustum from the 3d matrices.

Definition at line 37 of file Frustum.cpp.

References m_frustum, normalizePlane(), PLANE_BOTTOM, PLANE_FAR, PLANE_LEFT, PLANE_NEAR, PLANE_RIGHT, and PLANE_TOP.

Referenced by pge::World::render().

00037                                  {
00038                 float projMatrix[16];
00039                 float modelMatrix[16];
00040                 float clip[16];
00041 
00042                 // Get the matrices from opengl
00043                 glGetFloatv(GL_PROJECTION_MATRIX, projMatrix);
00044                 glGetFloatv(GL_MODELVIEW_MATRIX, modelMatrix);
00045 
00046                 // get the clipping planes
00047                 clip[0] = modelMatrix[0] * projMatrix[0] + modelMatrix[1] * projMatrix[4] + modelMatrix[2] * projMatrix[8] + modelMatrix[3] * projMatrix[12];
00048                 clip[1] = modelMatrix[0] * projMatrix[1] + modelMatrix[1] * projMatrix[5] + modelMatrix[2] * projMatrix[9] + modelMatrix[3] * projMatrix[13];
00049                 clip[2] = modelMatrix[0] * projMatrix[2] + modelMatrix[1] * projMatrix[6] + modelMatrix[2] * projMatrix[10] + modelMatrix[3] * projMatrix[14];
00050                 clip[3] = modelMatrix[0] * projMatrix[3] + modelMatrix[1] * projMatrix[7] + modelMatrix[2] * projMatrix[11] + modelMatrix[3] * projMatrix[15];
00051 
00052                 clip[4] = modelMatrix[4] * projMatrix[0] + modelMatrix[5] * projMatrix[4] + modelMatrix[6] * projMatrix[8] + modelMatrix[7] * projMatrix[12];
00053                 clip[5] = modelMatrix[4] * projMatrix[1] + modelMatrix[5] * projMatrix[5] + modelMatrix[6] * projMatrix[9] + modelMatrix[7] * projMatrix[13];
00054                 clip[6] = modelMatrix[4] * projMatrix[2] + modelMatrix[5] * projMatrix[6] + modelMatrix[6] * projMatrix[10] + modelMatrix[7] * projMatrix[14];
00055                 clip[7] = modelMatrix[4] * projMatrix[3] + modelMatrix[5] * projMatrix[7] + modelMatrix[6] * projMatrix[11] + modelMatrix[7] * projMatrix[15];
00056 
00057                 clip[8] = modelMatrix[8] * projMatrix[0] + modelMatrix[9] * projMatrix[4] + modelMatrix[10] * projMatrix[8] + modelMatrix[11] * projMatrix[12];
00058                 clip[9] = modelMatrix[8] * projMatrix[1] + modelMatrix[9] * projMatrix[5] + modelMatrix[10] * projMatrix[9] + modelMatrix[11] * projMatrix[13];
00059                 clip[10] = modelMatrix[8] * projMatrix[2] + modelMatrix[9] * projMatrix[6] + modelMatrix[10] * projMatrix[10] + modelMatrix[11] * projMatrix[14];
00060                 clip[11] = modelMatrix[8] * projMatrix[3] + modelMatrix[9] * projMatrix[7] + modelMatrix[10] * projMatrix[11] + modelMatrix[11] * projMatrix[15];
00061 
00062                 clip[12] = modelMatrix[12] * projMatrix[0] + modelMatrix[13] * projMatrix[4] + modelMatrix[14] * projMatrix[8] + modelMatrix[15] * projMatrix[12];
00063                 clip[13] = modelMatrix[12] * projMatrix[1] + modelMatrix[13] * projMatrix[5] + modelMatrix[14] * projMatrix[9] + modelMatrix[15] * projMatrix[13];
00064                 clip[14] = modelMatrix[12] * projMatrix[2] + modelMatrix[13] * projMatrix[6] + modelMatrix[14] * projMatrix[10] + modelMatrix[15] * projMatrix[14];
00065                 clip[15] = modelMatrix[12] * projMatrix[3] + modelMatrix[13] * projMatrix[7] + modelMatrix[14] * projMatrix[11] + modelMatrix[15] * projMatrix[15];
00066 
00067                 // now get the planes of the frustum
00068                 m_frustum[PLANE_RIGHT][0] = clip[3] - clip[0];
00069                 m_frustum[PLANE_RIGHT][1] = clip[7] - clip[4];
00070                 m_frustum[PLANE_RIGHT][2] = clip[11] - clip[8];
00071                 m_frustum[PLANE_RIGHT][3] = clip[15] - clip[12];
00072                 normalizePlane(PLANE_RIGHT);
00073 
00074                 m_frustum[PLANE_LEFT][0] = clip[3] + clip[0];
00075                 m_frustum[PLANE_LEFT][1] = clip[7] + clip[4];
00076                 m_frustum[PLANE_LEFT][2] = clip[11] + clip[8];
00077                 m_frustum[PLANE_LEFT][3] = clip[15] + clip[12];
00078                 normalizePlane(PLANE_LEFT);
00079 
00080                 m_frustum[PLANE_BOTTOM][0] = clip[3] + clip[1];
00081                 m_frustum[PLANE_BOTTOM][1] = clip[7] + clip[5];
00082                 m_frustum[PLANE_BOTTOM][2] = clip[11] + clip[9];
00083                 m_frustum[PLANE_BOTTOM][3] = clip[15] + clip[13];
00084                 normalizePlane(PLANE_BOTTOM);
00085 
00086                 m_frustum[PLANE_TOP][0] = clip[3] - clip[1];
00087                 m_frustum[PLANE_TOP][1] = clip[7] - clip[5];
00088                 m_frustum[PLANE_TOP][2] = clip[11] - clip[9];
00089                 m_frustum[PLANE_TOP][3] = clip[15] - clip[13];
00090                 normalizePlane(PLANE_TOP);
00091 
00092                 m_frustum[PLANE_FAR][0] = clip[3] - clip[2];
00093                 m_frustum[PLANE_FAR][1] = clip[7] - clip[6];
00094                 m_frustum[PLANE_FAR][2] = clip[11] - clip[10];
00095                 m_frustum[PLANE_FAR][3] = clip[15] - clip[14];
00096                 normalizePlane(PLANE_FAR);
00097 
00098                 m_frustum[PLANE_NEAR][0] = clip[3] + clip[2];
00099                 m_frustum[PLANE_NEAR][1] = clip[7] + clip[6];
00100                 m_frustum[PLANE_NEAR][2] = clip[11] + clip[10];
00101                 m_frustum[PLANE_NEAR][3] = clip[15] + clip[14];
00102                 normalizePlane(PLANE_NEAR);
00103         }

Here is the call graph for this function:


Field Documentation

float pge::Frustum::m_frustum[6][4] [private]
 

Definition at line 75 of file Frustum.h.

Referenced by getDistanceToPlane(), isPointInside(), normalizePlane(), and update().


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