Changeset 2790


Ignore:
Timestamp:
06/20/08 09:10:28 (16 years ago)
Author:
mattausch
Message:
 
Location:
GTP/trunk/App/Demos/Vis/FriendlyCulling/src
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Bvh.cpp

    r2786 r2790  
    967967} 
    968968 
    969 } 
     969 
     970 
     971 
     972static void RenderBoxForViz(const AxisAlignedBox3 &box) 
     973{ 
     974        glBegin(GL_LINE_LOOP); 
     975        glVertex3d(box.Min().x, box.Max().y, box.Min().z); 
     976        glVertex3d(box.Max().x, box.Max().y, box.Min().z); 
     977        glVertex3d(box.Max().x, box.Min().y, box.Min().z); 
     978        glVertex3d(box.Min().x, box.Min().y, box.Min().z); 
     979        glEnd(); 
     980 
     981        glBegin(GL_LINE_LOOP); 
     982        glVertex3d(box.Min().x, box.Min().y, box.Max().z); 
     983        glVertex3d(box.Max().x, box.Min().y, box.Max().z); 
     984        glVertex3d(box.Max().x, box.Max().y, box.Max().z); 
     985        glVertex3d(box.Min().x, box.Max().y, box.Max().z); 
     986        glEnd(); 
     987 
     988        glBegin(GL_LINE_LOOP); 
     989        glVertex3d(box.Max().x, box.Min().y, box.Min().z); 
     990        glVertex3d(box.Max().x, box.Min().y, box.Max().z); 
     991        glVertex3d(box.Max().x, box.Max().y, box.Max().z); 
     992        glVertex3d(box.Max().x, box.Max().y, box.Min().z); 
     993        glEnd(); 
     994 
     995        glBegin(GL_LINE_LOOP); 
     996        glVertex3d(box.Min().x, box.Min().y, box.Min().z); 
     997        glVertex3d(box.Min().x, box.Min().y, box.Max().z); 
     998        glVertex3d(box.Min().x, box.Max().y, box.Max().z); 
     999        glVertex3d(box.Min().x, box.Max().y, box.Min().z); 
     1000        glEnd(); 
     1001 
     1002        glBegin(GL_LINE_LOOP); 
     1003        glVertex3d(box.Min().x, box.Min().y, box.Min().z); 
     1004        glVertex3d(box.Max().x, box.Min().y, box.Min().z); 
     1005        glVertex3d(box.Max().x, box.Min().y, box.Max().z); 
     1006        glVertex3d(box.Min().x, box.Min().y, box.Max().z); 
     1007        glEnd(); 
     1008 
     1009        glBegin(GL_LINE_LOOP); 
     1010        glVertex3d(box.Min().x, box.Max().y, box.Min().z); 
     1011        glVertex3d(box.Max().x, box.Max().y, box.Min().z); 
     1012        glVertex3d(box.Max().x, box.Max().y, box.Max().z); 
     1013        glVertex3d(box.Min().x, box.Max().y, box.Max().z); 
     1014 
     1015        glEnd(); 
     1016} 
     1017 
     1018 
     1019void Bvh::RenderBoundsForViz(BvhNode *node, bool useTightBounds) 
     1020{ 
     1021        glDisable(GL_TEXTURE_2D); 
     1022        glDisable(GL_LIGHTING); 
     1023        glColor3f(1, 1, 1); 
     1024         
     1025        if (!useTightBounds) 
     1026        { 
     1027                RenderBoxForViz(node->GetBox()); 
     1028        } 
     1029        else 
     1030        { 
     1031                for (int i = 0; i < node->mNumTestNodes; ++ i) 
     1032                { 
     1033                        RenderBoxForViz(mTestNodes[node->mTestNodesIdx + i]->GetBox()); 
     1034                } 
     1035        } 
     1036 
     1037        glEnable(GL_LIGHTING); 
     1038        glEnable(GL_TEXTURE_2D); 
     1039} 
     1040 
     1041 
     1042 
     1043} 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Bvh.h

    r2787 r2790  
    536536        */ 
    537537        int GetNumVirtualNodes() const  { return mNumVirtualNodes; } 
     538        /** Render wireframe bvh for visualization purpose. 
     539        */ 
     540        void RenderBoundsForViz(BvhNode *node, bool useTightBounds); 
    538541 
    539542 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/CHCPlusPlusTraverser.cpp

    r2782 r2790  
    8282        { 
    8383                bool resultAvailable = false; 
     84 
    8485                while (!mQueryQueue.empty() &&  
    8586                           (mDistanceQueue.empty() || (resultAvailable = mQueryQueue.front()->ResultAvailable()))) 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderTraverser.cpp

    r2788 r2790  
    4747mAssumedVisibleFrames(10), 
    4848mMaxBatchSize(50), 
    49 mUseTightBounds(false) 
     49mUseTightBounds(false), mShowBounds(false) 
    5050{ 
    5151} 
     
    7272        { 
    7373                RenderNode(node); 
     74 
     75                if (mShowBounds) 
     76                        mBvh->RenderBoundsForViz(node, mUseTightBounds);                 
    7477        } 
    7578        else  
     
    198201 
    199202 
     203void RenderTraverser::SetShowBounds(bool showBounds) 
     204{ 
     205        mShowBounds = showBounds; 
     206} 
     207 
     208 
    200209void RenderTraverser::SetUseTightBounds(bool useTightBounds) 
    201210{ 
    202211        mUseTightBounds = useTightBounds; 
    203         cout << "using tight bounds: " << useTightBounds << endl; 
     212        //cout << "using tight bounds: " << useTightBounds << endl; 
    204213} 
    205214 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderTraverser.h

    r2787 r2790  
    115115        */ 
    116116        void SetUseTightBounds(bool useTightBounds); 
     117        /** If bounds should be shown 
     118        */ 
     119        void SetShowBounds(bool showBounds); 
    117120 
    118121protected: 
     
    179182 
    180183        bool mUseTightBounds; 
     184 
     185        bool mShowBounds; 
    181186}; 
    182187 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Visualization.cpp

    r2788 r2790  
    1515{ 
    1616 
    17         GLUquadric *mSphere; 
     17GLUquadric *mSphere; 
     18 
     19 
     20static void RenderBoxForViz(const AxisAlignedBox3 &box) 
     21{ 
     22        glBegin(GL_LINE_LOOP); 
     23        glVertex3d(box.Min().x, box.Max().y, box.Min().z); 
     24        glVertex3d(box.Max().x, box.Max().y, box.Min().z); 
     25        glVertex3d(box.Max().x, box.Min().y, box.Min().z); 
     26        glVertex3d(box.Min().x, box.Min().y, box.Min().z); 
     27        glEnd(); 
     28 
     29        glBegin(GL_LINE_LOOP); 
     30        glVertex3d(box.Min().x, box.Min().y, box.Max().z); 
     31        glVertex3d(box.Max().x, box.Min().y, box.Max().z); 
     32        glVertex3d(box.Max().x, box.Max().y, box.Max().z); 
     33        glVertex3d(box.Min().x, box.Max().y, box.Max().z); 
     34        glEnd(); 
     35 
     36        glBegin(GL_LINE_LOOP); 
     37        glVertex3d(box.Max().x, box.Min().y, box.Min().z); 
     38        glVertex3d(box.Max().x, box.Min().y, box.Max().z); 
     39        glVertex3d(box.Max().x, box.Max().y, box.Max().z); 
     40        glVertex3d(box.Max().x, box.Max().y, box.Min().z); 
     41        glEnd(); 
     42 
     43        glBegin(GL_LINE_LOOP); 
     44        glVertex3d(box.Min().x, box.Min().y, box.Min().z); 
     45        glVertex3d(box.Min().x, box.Min().y, box.Max().z); 
     46        glVertex3d(box.Min().x, box.Max().y, box.Max().z); 
     47        glVertex3d(box.Min().x, box.Max().y, box.Min().z); 
     48        glEnd(); 
     49 
     50        glBegin(GL_LINE_LOOP); 
     51        glVertex3d(box.Min().x, box.Min().y, box.Min().z); 
     52        glVertex3d(box.Max().x, box.Min().y, box.Min().z); 
     53        glVertex3d(box.Max().x, box.Min().y, box.Max().z); 
     54        glVertex3d(box.Min().x, box.Min().y, box.Max().z); 
     55        glEnd(); 
     56 
     57        glBegin(GL_LINE_LOOP); 
     58        glVertex3d(box.Min().x, box.Max().y, box.Min().z); 
     59        glVertex3d(box.Max().x, box.Max().y, box.Min().z); 
     60        glVertex3d(box.Max().x, box.Max().y, box.Max().z); 
     61        glVertex3d(box.Min().x, box.Max().y, box.Max().z); 
     62 
     63        glEnd(); 
     64} 
     65 
    1866 
    1967/******************************************************/ 
     
    63111        RenderViewPoint(); 
    64112        RenderFrustum(); 
    65         RenderBox(mBvh->GetBox()); 
     113        RenderBoxForViz(mBvh->GetBox()); 
    66114 
    67115        glEnable(GL_LIGHTING); 
     
    106154 
    107155 
    108 void Visualization::RenderBox(const AxisAlignedBox3 &box) 
    109 { 
    110         glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); 
    111         glDisable(GL_CULL_FACE); 
    112         glColor3f(1.0f, 0.0f, 0.0f); 
    113  
    114         glBegin(GL_QUADS); 
    115         glVertex3f(box.Min().x, box.Max().y, box.Min().z); 
    116         glVertex3f(box.Max().x, box.Max().y, box.Min().z); 
    117         glVertex3f(box.Max().x, box.Min().y, box.Min().z); 
    118         glVertex3f(box.Min().x, box.Min().y, box.Min().z); 
    119         glEnd(); 
    120  
    121         glBegin(GL_QUADS); 
    122         glVertex3f(box.Min().x, box.Min().y, box.Max().z); 
    123         glVertex3f(box.Max().x, box.Min().y, box.Max().z); 
    124         glVertex3f(box.Max().x, box.Max().y, box.Max().z); 
    125         glVertex3f(box.Min().x, box.Max().y, box.Max().z); 
    126         glEnd(); 
    127  
    128         glBegin(GL_QUADS); 
    129         glVertex3f(box.Max().x, box.Min().y, box.Min().z); 
    130         glVertex3f(box.Max().x, box.Min().y, box.Max().z); 
    131         glVertex3f(box.Max().x, box.Max().y, box.Max().z); 
    132         glVertex3f(box.Max().x, box.Max().y, box.Min().z); 
    133         glEnd(); 
    134  
    135         glBegin(GL_QUADS); 
    136         glVertex3f(box.Min().x, box.Min().y, box.Min().z); 
    137         glVertex3f(box.Min().x, box.Min().y, box.Max().z); 
    138         glVertex3f(box.Min().x, box.Max().y, box.Max().z); 
    139         glVertex3f(box.Min().x, box.Max().y, box.Min().z); 
    140         glEnd(); 
    141  
    142         glBegin(GL_QUADS); 
    143         glVertex3f(box.Min().x, box.Min().y, box.Min().z); 
    144         glVertex3f(box.Max().x, box.Min().y, box.Min().z); 
    145         glVertex3f(box.Max().x, box.Min().y, box.Max().z); 
    146         glVertex3f(box.Min().x, box.Min().y, box.Max().z); 
    147         glEnd(); 
    148  
    149         glBegin(GL_QUADS); 
    150         glVertex3f(box.Min().x, box.Max().y, box.Min().z); 
    151         glVertex3f(box.Max().x, box.Max().y, box.Min().z); 
    152         glVertex3f(box.Max().x, box.Max().y, box.Max().z); 
    153         glVertex3f(box.Min().x, box.Max().y, box.Max().z); 
    154         glEnd(); 
    155  
    156         glEnable(GL_CULL_FACE); 
    157         glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); 
    158 } 
    159  
    160  
    161 void Visualization::RenderFrustum() 
    162 { 
    163         glColor3f(1.0f, 0.0f, 0.0f); 
    164  
    165         Vector3 ftl, ftr, fbl, fbr, ntl, ntr, nbl, nbr; 
    166         mCamera->ComputePoints(ftl, ftr, fbl, fbr, ntl, ntr, nbl, nbr); 
    167  
    168         glLineWidth(2); 
    169  
    170         glBegin(GL_LINE_LOOP); 
    171         glVertex3d(fbl.x, fbl.y, fbl.z); 
    172         glVertex3d(fbr.x, fbr.y, fbr.z); 
    173         glVertex3d(ftr.x, ftr.y, ftr.z); 
    174         glVertex3d(ftl.x, ftl.y, ftl.z); 
    175         glEnd(); 
    176  
    177         glBegin(GL_LINE_LOOP); 
    178         glVertex3d(nbl.x, nbl.y, nbl.z); 
    179         glVertex3d(nbr.x, nbr.y, nbr.z); 
    180         glVertex3d(ntr.x, ntr.y, ntr.z); 
    181         glVertex3d(ntl.x, ntl.y, ntl.z); 
    182         glEnd(); 
    183  
    184         glBegin(GL_LINE_LOOP); 
    185         glVertex3d(fbl.x, fbl.y, fbl.z); 
    186         glVertex3d(ftl.x, ftl.y, ftl.z); 
    187         glVertex3d(ntl.x, ntl.y, ntl.z); 
    188         glVertex3d(nbl.x, nbl.y, nbl.z); 
    189         glEnd(); 
    190  
    191         glBegin(GL_LINE_LOOP); 
    192         glVertex3d(fbr.x, fbr.y, fbr.z); 
    193         glVertex3d(ftr.x, ftr.y, ftr.z); 
    194         glVertex3d(ntr.x, ntr.y, ntr.z); 
    195         glVertex3d(nbr.x, nbr.y, nbr.z); 
    196         glEnd(); 
    197  
    198         glBegin(GL_LINE_LOOP); 
    199         glVertex3d(fbr.x, fbr.y, fbr.z); 
    200         glVertex3d(fbl.x, fbl.y, fbl.z); 
    201         glVertex3d(nbl.x, nbl.y, nbl.z); 
    202         glVertex3d(nbr.x, nbr.y, nbr.z); 
    203         glEnd(); 
    204  
    205         glBegin(GL_LINE_LOOP); 
    206         glVertex3d(ftr.x, ftr.y, ftr.z); 
    207         glVertex3d(ftl.x, ftl.y, ftl.z); 
    208         glVertex3d(ntl.x, ntl.y, ntl.z); 
    209         glVertex3d(ntr.x, ntr.y, ntr.z); 
    210         glEnd(); 
    211 } 
    212  
    213  
    214  
    215156void Visualization::RenderViewPoint() 
    216157{ 
     
    232173} 
    233174 
    234 } 
     175 
     176void Visualization::RenderFrustum() 
     177{ 
     178        glColor3f(1.0f, 0.0f, 0.0f); 
     179 
     180        Vector3 ftl, ftr, fbl, fbr, ntl, ntr, nbl, nbr; 
     181        mCamera->ComputePoints(ftl, ftr, fbl, fbr, ntl, ntr, nbl, nbr); 
     182 
     183        glLineWidth(2); 
     184 
     185        glBegin(GL_LINE_LOOP); 
     186        glVertex3d(fbl.x, fbl.y, fbl.z); 
     187        glVertex3d(fbr.x, fbr.y, fbr.z); 
     188        glVertex3d(ftr.x, ftr.y, ftr.z); 
     189        glVertex3d(ftl.x, ftl.y, ftl.z); 
     190        glEnd(); 
     191 
     192        glBegin(GL_LINE_LOOP); 
     193        glVertex3d(nbl.x, nbl.y, nbl.z); 
     194        glVertex3d(nbr.x, nbr.y, nbr.z); 
     195        glVertex3d(ntr.x, ntr.y, ntr.z); 
     196        glVertex3d(ntl.x, ntl.y, ntl.z); 
     197        glEnd(); 
     198 
     199        glBegin(GL_LINE_LOOP); 
     200        glVertex3d(fbl.x, fbl.y, fbl.z); 
     201        glVertex3d(ftl.x, ftl.y, ftl.z); 
     202        glVertex3d(ntl.x, ntl.y, ntl.z); 
     203        glVertex3d(nbl.x, nbl.y, nbl.z); 
     204        glEnd(); 
     205 
     206        glBegin(GL_LINE_LOOP); 
     207        glVertex3d(fbr.x, fbr.y, fbr.z); 
     208        glVertex3d(ftr.x, ftr.y, ftr.z); 
     209        glVertex3d(ntr.x, ntr.y, ntr.z); 
     210        glVertex3d(nbr.x, nbr.y, nbr.z); 
     211        glEnd(); 
     212 
     213        glBegin(GL_LINE_LOOP); 
     214        glVertex3d(fbr.x, fbr.y, fbr.z); 
     215        glVertex3d(fbl.x, fbl.y, fbl.z); 
     216        glVertex3d(nbl.x, nbl.y, nbl.z); 
     217        glVertex3d(nbr.x, nbr.y, nbr.z); 
     218        glEnd(); 
     219 
     220        glBegin(GL_LINE_LOOP); 
     221        glVertex3d(ftr.x, ftr.y, ftr.z); 
     222        glVertex3d(ftl.x, ftl.y, ftl.z); 
     223        glVertex3d(ntl.x, ntl.y, ntl.z); 
     224        glVertex3d(ntr.x, ntr.y, ntr.z); 
     225        glEnd(); 
     226} 
     227 
     228 
     229} 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Visualization.h

    r2788 r2790  
    4848        */ 
    4949        void RenderFrustum(); 
    50         /** Renders a bounding box for visualization. 
     50        /** Renders the current view point. 
    5151        */ 
    52         void RenderBox(const AxisAlignedBox3 &box); 
    53  
    5452        void RenderViewPoint(); 
    5553 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp

    r2788 r2790  
    7272bool showHelp = false; 
    7373bool showStatistics = true; 
     74bool showOptions = true; 
    7475bool showBoundingVolumes = false; 
    7576bool visMode = false; 
     
    243244                "", 
    244245                "'F1'           - shows/dismisses this message", 
     246                "'F2'           - shows/hides statistics", 
     247                "'F3'           - shows/hides bounds (boxes or tight bounds)", 
     248                "'F4'           - shows/hides bird eye view", 
     249                "'f5',          - load helpScreen", 
     250                "'SPACE'        - cycles through occlusion culling algorithms", 
    245251                "", 
    246252                "'MOUSE-LEFT'   - turn left/right, move forward/backward", 
     
    252258                "'CURSOR LEFT'  - turn left", 
    253259                "", 
    254                 "'SPACE'        - cycles through occlusion culling algorithms", 
    255260                "'-'            - decreases max batch size", 
    256261                "'+'            - increases max batch size", 
     
    261266                "", 
    262267                "'R'            - use render queue", 
    263                 "", 
    264                 "'S'            - shows/hides statistics", 
    265                 "'V'            - shows/hides bounding volumes", 
    266                 "", 
    267                 "'1'            - shows/hides bird eye view", 
     268                "'B'            - use tight bounds", 
     269                "'M'            - use multiqueries", 
    268270                0, 
    269271        }; 
     
    441443                showHelp = !showHelp; 
    442444                break; 
    443         case 'v': 
    444         case 'V': 
    445                 showBoundingVolumes = !showBoundingVolumes; 
    446                 //HierarchyNode::SetRenderBoundingVolume(showBoundingVolumes); 
    447                 break; 
    448         case 'O': 
    449         case 'o': 
    450                 showStatistics = !showStatistics; 
    451                 break; 
    452445        case '+': 
    453446                maxBatchSize += 10; 
     
    472465                useMultiQueries = !useMultiQueries; 
    473466                traverser->SetUseMultiQueries(useMultiQueries); 
    474                 break; 
    475         case '1': 
    476                 visMode = !visMode; 
    477467                break; 
    478468        case '8': 
     
    537527                        traverser->SetUseRenderQueue(useRenderQueue); 
    538528                } 
     529                break; 
    539530        case 'b': 
    540531        case 'B': 
     
    543534                        traverser->SetUseTightBounds(useTightBounds); 
    544535                } 
     536                break; 
    545537        default: 
    546538                return; 
     
    560552        case GLUT_KEY_F1: 
    561553                showHelp = !showHelp; 
     554                break; 
     555        case GLUT_KEY_F2: 
     556                showStatistics = !showStatistics; 
     557                break; 
     558        case GLUT_KEY_F3: 
     559                showBoundingVolumes = !showBoundingVolumes; 
     560                traverser->SetShowBounds(showBoundingVolumes); 
     561                break; 
     562        case GLUT_KEY_F4: 
     563                visMode = !visMode; 
     564                break; 
     565        case GLUT_KEY_F5: 
     566                showOptions = !showOptions; 
    562567                break; 
    563568        case GLUT_KEY_LEFT: 
     
    927932        char msg5[200]; 
    928933        char msg6[200]; 
     934        char msg7[200]; 
    929935 
    930936 
     
    951957        } 
    952958 
    953         sprintf_s(msg2, "assumed visible frames: %4d, max batch size: %4d, using render queue: %d",  
    954                       assumedVisibleFrames, maxBatchSize, useRenderQueue); 
     959        sprintf_s(msg2, "assumed visible frames: %4d, max batch size: %4d",  
     960                      assumedVisibleFrames, maxBatchSize); 
     961 
     962        sprintf_s(msg3, "render queue: %d, multiqueries: %d, tight bounds: %d",  
     963                      useRenderQueue, useMultiQueries, useTightBounds); 
    955964 
    956965        string str; 
     
    960969        CalcDecimalPoint(str2, bvh->GetBvhStats().mTriangles); 
    961970 
    962         sprintf_s(msg3, "rendered nodes: %6d (of %6d), rendered triangles: %s (of %s)",  
     971        sprintf_s(msg4, "rendered nodes: %6d (of %6d), rendered triangles: %s (of %s)",  
    963972                          renderedNodes, bvh->GetNumVirtualNodes(), str.c_str(), str2.c_str());  
    964973 
    965         sprintf_s(msg4, "traversed: %5d, frustum culled: %5d, query culled: %5d", 
     974        sprintf_s(msg5, "traversed: %5d, frustum culled: %5d, query culled: %5d", 
    966975                          traversedNodes, frustumCulledNodes, queryCulledNodes); 
    967976 
    968         sprintf_s(msg5, "issued queries: %5d, state changes: %5d", issuedQueries, stateChanges); 
    969  
    970         sprintf_s(msg6, "fps: %6.1f", fps); 
     977        sprintf_s(msg6, "issued queries: %5d, state changes: %5d", issuedQueries, stateChanges); 
     978 
     979        sprintf_s(msg7, "fps: %6.1f", fps); 
    971980        //cout << "previously visible node queries: " << traverser->GetStats().mNumPreviouslyVisibleNodeQueries << endl; 
    972981 
     
    982991                Output(850, 30, msg[renderMode]); 
    983992 
     993                 
    984994                if (showStatistics) 
    985995                { 
    986                         Output(20, 30, msg2); 
    987                         Output(20, 60, msg3); 
    988                         Output(20, 90, msg4); 
    989                         Output(20, 120, msg5); 
    990                         Output(20, 150, msg6); 
     996                        Output(20, 30, msg4); 
     997                        Output(20, 60, msg5); 
     998                        Output(20, 90, msg6); 
     999                        Output(20, 120, msg7); 
     1000                } 
     1001 
     1002                if (showOptions) 
     1003                { 
     1004                        Output(20, 150, msg2); 
     1005                        Output(20, 180, msg3); 
    9911006                } 
    9921007        } 
Note: See TracChangeset for help on using the changeset viewer.