//============================================================================ // viewfrus.hpp : GENERAL perspective viewing frustum class definition //============================================================================ #ifndef VIEWFRUS #define VIEWFRUS #include "vect3d.hpp" #include "plane.hpp" #include "camera.hpp" // NEAR PLANE TYPES (USED IN GENERALIZED UPDATE) #define USESPTS 0 #define USEFARTHEST 1 #define USECLOSEST 2 class ViewFrustum { public: //-------------------------------------------------------------------------- // VIEW-FRUSTUM GEOMETRY (Pts ARE CCW W/ RESPECT TO THE VIEWER) //-------------------------------------------------------------------------- Vect3d* sPts; // GIVEN SILHOUETTE EDGES (3D POLYLINE). Vect3d* NearPts; // NEAR FACE VERTICES (define vertices of one end of frustum) Vect3d* FarPts; // FAR FACE VERTICES (define other end of frustum) int NumSides; // NUMBER OF SIDE PLANES, NearPts, AND FarPts Plane* Planes; // ARRAY OF VF PLANES (FIRST ARE SIDES AND LAST TWO ELEMENTS ARE THE NEAR AND FAR PLANES) int NumPlanes; // NumSides + Near + Far (optional) //-------------------------------------------------------------------------- // Camera frustum constructor: Prepares the generalized ViewFrustum to be used for VIEW frustum // culling (four sides, near and far plane, etc defined by the Camera class). //-------------------------------------------------------------------------- ViewFrustum(int numpts=4); //-------------------------------------------------------------------------- // Shadow frustum constructor: Stores the given set of points to be used to define the frustum // when an update is called. The sPts should be a 3D polygon or a set of occluder edges. // NOTE: NOT REQUIRED IF COMPLETE UPDATE IS REQUIRED (using generalized Update) //-------------------------------------------------------------------------- ViewFrustum(Vect3d* spts, int numpts); //-------------------------------------------------------------------------- // Destructor //-------------------------------------------------------------------------- ~ViewFrustum(); //-------------------------------------------------------------------------- // Initialization routine for the NearPts, FarPts, and Planes arrays. //-------------------------------------------------------------------------- void Init(int numpts); //-------------------------------------------------------------------------- // "GENERALIZED" Update routine : this update is called by the other update // routines. // Type "USENEARPTS": inits for a "Shadow" frustum where the near // plane is defined by the plane created by the near pts (the near pts should // be a 3D planar polygon). The COP is the center-of-projection in WORLD // coordinates, ViewDir is the current viewing direction, and the FarDist is // the distance to the far plane in the direction of ViewDir. // Type "USEFARTHEST": Uses the FARTHEST pt in the NearPts array along the // ViewDir to define the near plane. // Type "USECLOSEST": Uses the CLOSEST pt in the NearPts array along the // ViewDir to define the near plane. // IMPORTANT: NearPts are assumed to be ccw w/ respect to viewer. ViewDir must // be NORMALIZED. COP and NearPts are in WORLD COORDS. //-------------------------------------------------------------------------- void Update(Vect3d cop, Vect3d viewdir, float fardist, int Type); //-------------------------------------------------------------------------- // OCCLUDER SET UPDATE ROUTINE: Requires EVERYTHING since it first destroys // the old Frustum and then builds a new one given the new parameters. This // will be useful if the ViewFrustum is NOT supposed to store the "occluder", // but rather a set of occluder edges. The same rules apply as in the second // update routine (I will actually call it after NearPts is created). //-------------------------------------------------------------------------- void Update(Vect3d* spts, int numpts, Vect3d cop, Vect3d viewdir, float fardist, int Type); //-------------------------------------------------------------------------- // CAMERA UPDATE ROUTINE : UPDATE THE FRUSTUM FOR A CAMERA SYSTEM (LAST TWO // ELEMENTS OF Sides IS NEAR AND FAR). Updates the ViewFrustum as a normal // VIEWING frustum. //-------------------------------------------------------------------------- void ViewFrustum::Update(Camera* Cam); //-------------------------------------------------------------------------- // CHECKS IF AN EDGE INTERSECTS THE VIEW-FRUSTUM //-------------------------------------------------------------------------- int EdgeIntersect(Vect3d Start, Vect3d End) const; }; #endif