Main Page   Namespace List   Class Hierarchy   Compound List   File List   Compound Members   File Members  

pvs.h File Reference

#include "portal.h"
#include "listnode.h"

Go to the source code of this file.

Functions

int CountVisibleLeaves ()
void FindVisibleLeaves (int Parent, PORTAL *CurrentPortal, BSP_node *ParentNode, int portalnumber)
void CalculatePVS (int currentleaf)


Function Documentation

void CalculatePVS int    currentleaf
 

Definition at line 113 of file pvs.cpp.

References Back, currentCamera, FindVisibleLeaves(), LinkedList< PORTAL >::Get(), LinkedList< T >::Get(), BSP_node::numportals, BSP_node::portallist, PortalWasSplit, SplitPortal(), PORTAL::Vertex, BSP_node::visible, VECTOR::x, VECTOR::y, and VECTOR::z.

Referenced by DrawGLScene().

00114 {
00115     int flag, result, counter, parentid, portalnumber, planenumber;
00116     VECTOR pointOnPlane;
00117     VECTOR ZUnit = camera[currentCamera].GetZUnit();    // camera's direction vector
00118     BSP_node* CurrentNode;
00119     PORTAL* CurrentPortal;
00120     PORTAL* front = new PORTAL;
00121     PORTAL* back = new PORTAL;
00122 
00123     parentid = currentleaf;
00124     CurrentNode = LeafList.Get(currentleaf);
00125     CurrentNode->visible = true;
00126     // loop through the portals of the current leafnode
00127     for (portalnumber = 1; portalnumber <= CurrentNode->numportals; portalnumber++)
00128     {
00129         counter = 0;
00130         CurrentPortal = CurrentNode->portallist.Get(portalnumber);
00131         flag = 1;
00132         // loop through the frustum planes
00133         for (planenumber = 0; planenumber < 6; planenumber++)
00134         {
00135             // find a point on the far plane by projecting the camera's direction vector
00136             if (planenumber == 4)
00137             {
00138                 pointOnPlane.x = camera[currentCamera].Position.x;
00139                 pointOnPlane.x -= ZUnit.x * 500.0;
00140                 pointOnPlane.y = camera[currentCamera].Position.y;
00141                 pointOnPlane.y -= ZUnit.y * 500.0;
00142                 pointOnPlane.z = camera[currentCamera].Position.z;
00143                 pointOnPlane.z -= ZUnit.z * 500.0;
00144             }
00145             else if (planenumber == 5) // skip the near frustum plane test
00146                 continue;
00147             else
00148                 // the camera position is a point on the frustum planes
00149                 pointOnPlane = camera[currentCamera].Position;
00150 
00151             result = SplitPortal(CurrentPortal, frustum[planenumber], pointOnPlane, front, back);
00152             if (result == PortalWasSplit)
00153             {
00154                 delete[] back->Vertex;
00155                 if (flag == 0)   // if there has been a previous split portal
00156                 {
00157                     delete[] CurrentPortal->Vertex;
00158                     delete CurrentPortal;
00159                 }
00160                 flag = 0;
00161                 CurrentPortal = front;
00162                 front = new PORTAL;
00163             }
00164             if (result != Back)
00165                 counter++;
00166         }
00167         // if the portal was split by or infront of the planes
00168         if (counter == 5)
00169         {
00170             FindVisibleLeaves(parentid, CurrentPortal, CurrentNode, portalnumber);
00171         }
00172         if (flag == 0)  // if there has been at least one split portal
00173         {
00174             delete[] CurrentPortal->Vertex;
00175             delete CurrentPortal;
00176         }
00177     }
00178     delete front;
00179     delete back;
00180 }

int CountVisibleLeaves  
 

Definition at line 21 of file pvs.cpp.

References LinkedList< T >::Get(), numleaves, and BSP_node::visible.

Referenced by DrawGLScene().

00022 {
00023     int counter = 0;
00024     BSP_node* tempnode;
00025     for (int loop = 1; loop <= numleaves; loop++)
00026     {
00027         tempnode = LeafList.Get(loop);
00028         if (tempnode->visible)
00029         {
00030             counter++;
00031         }
00032     }
00033     return counter;
00034 }

void FindVisibleLeaves int    Parent,
PORTAL   CurrentPortal,
BSP_node   ParentNode,
int    portalnumber
 

Definition at line 36 of file pvs.cpp.

References Back, PORTAL::backleaf, VERTEX::coords, CrossVector(), currentCamera, LinkedList< T >::Get(), LinkedList< PORTAL >::Get(), BSP_node::nodeid, PLANE::normal, BSP_node::numportals, PORTAL::numVertices, BSP_node::portallist, PortalWasSplit, SplitPortal(), PORTAL::Vertex, and BSP_node::visible.

Referenced by CalculatePVS().

00037 {
00038     int loop, numPlanes, Nminus1, counter, flag, result, parentid, planenumber;
00039     VECTOR edge1, edge2, pointOnPlane, planesNormal;
00040     BSP_node* CurrentNode;
00041     PORTAL* front = new PORTAL;
00042     PORTAL* back = new PORTAL;
00043     PORTAL* inputPortal;
00044 
00045     inputPortal = ParentNode->portallist.Get(portalnumber);
00046     parentid = inputPortal->backleaf->nodeid;
00047     CurrentNode = LeafList.Get(parentid);
00048     CurrentNode->visible = true;
00049 
00050     // Create the planes from CurrentPortal
00051     pointOnPlane = camera[currentCamera].Position;
00052 
00053     numPlanes = CurrentPortal->numVertices;
00054     PLANE* Planes = new PLANE[numPlanes];
00055     for (loop = 0; loop < numPlanes; loop++)
00056     {
00057         if (loop == 0)
00058             Nminus1 = numPlanes - 1;
00059         else
00060             Nminus1 = loop - 1;
00061         // get the normal from edges
00062         edge1 = CurrentPortal->Vertex[loop].coords - camera[currentCamera].Position;
00063         edge2 = CurrentPortal->Vertex[Nminus1].coords - camera[currentCamera].Position;
00064         planesNormal = CrossVector(edge1, edge2);
00065         Planes[loop].normal = planesNormal;
00066     }
00067 
00068     // loop through the portals of this leafnode
00069     for (portalnumber = 1; portalnumber <= CurrentNode->numportals; portalnumber++)
00070     {
00071         counter = 0;
00072         CurrentPortal = CurrentNode->portallist.Get(portalnumber);
00073         flag = 1;
00074         // if the backleaf isn't the parent
00075         if (CurrentPortal->backleaf->nodeid != Parent)
00076         {
00077             // loop through the planes
00078             for (planenumber = 0; planenumber < numPlanes; planenumber++)
00079             {
00080                 result = SplitPortal(CurrentPortal, Planes[planenumber], pointOnPlane, front, back);
00081                 if (result == PortalWasSplit)
00082                 {
00083                     delete[] back->Vertex;
00084                     if (flag == 0)   // if there has been a previous split polygon
00085                     {
00086                         delete[] CurrentPortal->Vertex;
00087                         delete CurrentPortal;
00088                     }
00089                     flag = 0;
00090                     CurrentPortal = front;
00091                     front = new PORTAL;
00092                 }
00093                 if (result != Back)
00094                     counter++;
00095             }
00096             // if the portal was split by or infront of all the planes
00097             if (counter == numPlanes)
00098             {
00099                 FindVisibleLeaves(parentid, CurrentPortal, CurrentNode, portalnumber);
00100             }
00101             if (flag == 0)   // if there has been at least one split polygon
00102             {
00103                 delete[] CurrentPortal->Vertex;
00104                 delete CurrentPortal;
00105             }
00106         }
00107     }
00108     delete[] Planes;
00109     delete front;
00110     delete back;
00111 }


Generated on Fri Dec 23 05:15:51 2005 for Constructive Solid Geometry by doxygen1.2.15