frustum.h

Go to the documentation of this file.
00001 /* MAINTAINER: Martin */
00002 
00003 #ifndef _FRUSTUM_H
00004 #define _FRUSTUM_H
00005 
00006 #include "GLMatrix.h"
00007 #include "GLPlane.h"
00008 #include "log.h"
00009 #include <vector>
00010 
00011 class Frustum
00012 {
00013 public:
00014         typedef GLPlaned TPlane;
00015         
00016         enum TPlaneID {
00017                 PL_LEFT = 0, 
00018                 PL_RIGHT, 
00019                 PL_TOP,
00020                 PL_BOTTOM,
00021                 PL_NEAR, 
00022                 PL_FAR
00023         };
00024 
00025         enum ClipState {
00026                 OUTSIDE,
00027                 INSIDE,
00028                 INTERSECT
00029         };
00030 
00031         Frustum():mPlanes(6){}
00032         Frustum(const Frustum & f);
00033 
00034         Frustum(const GLMatrix4d &m):mPlanes(6){ set(m, true); }
00035 
00045         void set(const GLMatrix4d &m, bool normalize = true);
00046 
00056         void transform(const GLMatrix4d &m, bool normalize = true);
00057         
00058         
00064         const TPlane& getPlane(TPlaneID planeID){ return mPlanes[planeID]; }
00065 
00073         void normalizePlane(TPlaneID planeID);
00074 
00078         void normalizeAllPlanes(void);
00079 
00080         bool testPoint(const GLVector3d &p);
00081 
00082         enum Halfspace{
00083                 NEGATIVE = -1,
00084                 POSITIVE = +1,
00085                 ON_PLANE = 0
00086         };
00087 
00088         static Halfspace classifyPoint(const TPlane &plane, const GLVector3d &point, const double eps = 0.0f);
00089 
00090         ClipState testSphere(const GLVector3d &center, const double r) const;
00091         ClipState testBox(const GLVector3d &center, const GLVector3d &extent) const;
00092         
00093 private:
00103         int mi(int row, int col) 
00104         { 
00105                 assertL(row > 0 && row <= 4 && col > 0 && col <= 4 && "Bad row/column for computation of matrix index of view frustum."); 
00106                 return ((col-1) * 4) + row-1; 
00107         }
00108         
00109         typedef std::vector<TPlane> TPlaneContainer;
00110         TPlaneContainer mPlanes; 
00111 };
00112 
00113 
00114 #endif

Generated on Wed Apr 12 13:55:28 2006 for bjs by  doxygen 1.4.5