Changeset 2762 for GTP


Ignore:
Timestamp:
06/15/08 23:35:07 (16 years ago)
Author:
mattausch
Message:

debug version

Location:
GTP/trunk/App/Demos/Vis/CHC_revisited
Files:
14 edited

Legend:

Unmodified
Added
Removed
  • GTP/trunk/App/Demos/Vis/CHC_revisited/AxisAlignedBox3.cpp

    r2755 r2762  
    720720} 
    721721 
    722 #if TOIMPLEMENT 
    723 int AxisAlignedBox3::Side(const Plane3 &plane) const 
    724 { 
    725         Vector3 v; 
    726         int i, m=3, M=-3, s; 
    727  
    728         for (i=0;i<8;i++) { 
    729                 GetVertex(i, v); 
    730                 if((s = plane.Side(v)) < m) 
    731                         m=s; 
    732                 if(s > M) 
    733                         M=s; 
    734                 if (m && m==-M) 
    735                         return 0; 
    736         } 
    737  
    738         return (m == M) ? m : m + M; 
    739 } 
    740  
    741  
    742 Plane3 AxisAlignedBox3::GetPlane(const int face) const 
    743 { 
    744         switch (face)  
    745         { 
    746  
    747         case 0: 
    748                 return Plane3(Vector3(-1, 0, 0), mMin); 
    749         case 1:  
    750                 return Plane3(Vector3(1, 0, 0), mMax); 
    751         case 2: 
    752                 return Plane3(Vector3(0, -1, 0), mMin); 
    753         case 3: 
    754                 return Plane3(Vector3(0, 1, 0), mMax); 
    755         case 4: 
    756                 return Plane3(Vector3(0, 0, -1), mMin); 
    757         case 5: 
    758                 return Plane3(Vector3(0, 0, 1), mMax); 
    759         } 
    760  
    761         // should not come here 
    762         return Plane3(); 
    763 } 
    764 #endif 
    765  
    766722 
    767723void AxisAlignedBox3::Scale(const float scale)  
     
    1032988} 
    1033989 
    1034  
     990//int AxisAlignedBox3::GetIndexFarthestVertex(const Vector3 &vecPlaneNormal) 
    1035991int AxisAlignedBox3::GetIndexNearestVertex(const Vector3 &vecPlaneNormal) 
    1036992{ 
    1037         int index; 
    1038  
    1039         if (vecPlaneNormal.x > 0.0f) 
    1040                 index = (vecPlaneNormal.y > 0.0f) ? 0 : 3; 
    1041         else 
    1042                 index = (vecPlaneNormal.y > 0.0f) ? 1 : 2; 
    1043  
    1044         return (vecPlaneNormal.z > 0.0f) ? index : 7 - index; 
    1045 } 
    1046  
    1047  
     993        int x, y, z; 
     994 
     995        x = (vecPlaneNormal.x > 0.0f) ? 0 : 1; 
     996        y = (vecPlaneNormal.y > 0.0f) ? 0 : 1; 
     997        z = (vecPlaneNormal.z > 0.0f) ? 0 : 1; 
     998         
     999        return 4 * x + 2 * y + z; 
     1000} 
     1001 
     1002 
     1003//int AxisAlignedBox3::GetIndexNearestVertex(const Vector3 &vecPlaneNormal) 
    10481004int AxisAlignedBox3::GetIndexFarthestVertex(const Vector3 &vecPlaneNormal) 
    10491005{ 
    1050         int index; 
     1006        int x, y, z; 
     1007 
     1008        x = (vecPlaneNormal.x <= 0.0f) ? 0 : 1; 
     1009        y = (vecPlaneNormal.y <= 0.0f) ? 0 : 1; 
     1010        z = (vecPlaneNormal.z <= 0.0f) ? 0 : 1; 
     1011         
     1012        return 4 * x + 2 * y + z; 
     1013 
     1014        /*int index; 
    10511015 
    10521016        if (vecPlaneNormal.x <= 0.0f) 
     
    10551019                index = (vecPlaneNormal.y <= 0.0f) ? 1 : 2; 
    10561020 
    1057         return (vecPlaneNormal.z <= 0.0f) ? index : 7 - index; 
     1021        return (vecPlaneNormal.z <= 0.0f) ? index : 7 - index;*/ 
    10581022} 
    10591023 
  • GTP/trunk/App/Demos/Vis/CHC_revisited/BinaryLoader.cpp

    r2760 r2762  
    173173        istr.read(reinterpret_cast<char *>(&shapeCount), sizeof(int)); 
    174174 
     175        geometry.resize(shapeCount); 
     176 
    175177        int progress = 0; 
    176178 
    177179        for (int i = 0; i < shapeCount; ++ i) 
    178180        { 
     181                int id; 
     182                istr.read(reinterpret_cast<char *>(&id), sizeof(int)); 
     183 
    179184                SceneEntity *ent = LoadSceneEntity(istr); 
    180                 geometry.push_back(ent); 
     185                ent->id = id; 
     186 
     187                geometry[id] = ent; 
    181188                 
    182189                int p = (i + 1) * 100 / shapeCount; 
     
    184191                if (p >= progress) 
    185192                { 
    186                         cout << "% loaded: " << p << endl; 
     193                        //cout << "% loaded: " << p << endl; 
    187194                        progress += 10; 
    188195                } 
  • GTP/trunk/App/Demos/Vis/CHC_revisited/Bvh.cpp

    r2761 r2762  
    292292 
    293293 
     294bool Bvh::TestPlane(BvhNode *node, int i, bool &bIntersect) 
     295{ 
     296        // do the test only if necessary 
     297        if (1)//node->mPlaneMask & (1 << i)) 
     298        {//cout<<"plane "<< i << endl; 
     299                bool outs = true; 
     300                //-- test the n-vertex 
     301                for (int j = 0; j < 8; ++ j) 
     302                { 
     303                        if (sFrustum.mClipPlanes[i].Distance(node->mBox.GetVertex(j)) <= 0) outs = false; 
     304                } 
     305                if (outs) return 0; 
     306                //if ((node->mBox.GetDistance(sClipPlaneAABBVertexIndices[i * 2 + 0], sFrustum.mClipPlanes[i]) > 0.0f)) 
     307                        //&&    (node->mBox.GetDistance(sClipPlaneAABBVertexIndices[i * 2 + 1], sFrustum.mClipPlanes[i]) > 0.0f)) 
     308                { 
     309                        // outside 
     310                //      node->mPreferredPlane = i; 
     311                        //cout<<"f " << node->mBox.GetDistance(sClipPlaneAABBVertexIndices[i * 2 + 0], sFrustum.mClipPlanes[i]) << " " << sFrustum.mClipPlanes[i] << endl; 
     312                //      return false; 
     313                }//else cout<<"ok " << node->mBox.GetDistance(sClipPlaneAABBVertexIndices[i * 2 + 0], sFrustum.mClipPlanes[i]) << " " << sFrustum.mClipPlanes[i] << endl; 
     314 
     315                //-- test the p-vertex 
     316                if (node->mBox.GetDistance(sClipPlaneAABBVertexIndices[i * 2 + 1], sFrustum.mClipPlanes[i]) <= 0.0f) 
     317                { 
     318                        // completely inside: children don't need to check against this plane no more 
     319                        node->mPlaneMask^= 1 << i; 
     320                } 
     321                else  
     322                { 
     323                        bIntersect = true; 
     324                } 
     325        } 
     326 
     327        return true; 
     328} 
     329 
     330 
    294331int     Bvh::IsWithinViewFrustum(BvhNode *node) 
    295332{ 
     
    300337 
    301338 
     339        for (int i = 0; i < 6; ++ i) 
     340        { 
     341                if (!TestPlane(node, i, bIntersect)) return 0; 
     342        } 
     343 
    302344        //////// 
    303         //-- do the view frustum culling for the planes [mPreferredPlane - 5] 
    304  
     345        //-- apply frustum culling for the planes [mPreferredPlane - 5] 
     346/* 
    305347        for (int i = node->mPreferredPlane; i < 6; ++ i) 
    306348        { 
    307                 //-- do the test only if necessary 
    308                 if (node->mPlaneMask & (1 << i)) 
    309                 { 
    310                         //-- test the n-vertex 
    311                         if (node->mBox.GetDistance(sClipPlaneAABBVertexIndices[i * 2 + 0], sFrustum.mClipPlanes[i]) > 0.0f) 
    312                         { 
    313                                 //-- outside 
    314                                 node->mPreferredPlane = i; 
    315                                 return 0; 
    316                         } 
    317  
    318                         //-- test the p-vertex 
    319                         if (node->mBox.GetDistance(sClipPlaneAABBVertexIndices[i * 2 + 1], sFrustum.mClipPlanes[i]) <= 0.0f) 
    320                         { 
    321                                 //-- completely inside: children don't need to check against this plane no more 
    322                                 node->mPlaneMask^=      1 << i; 
    323                         } 
    324                         else  
    325                         { 
    326                                 bIntersect = true; 
    327                         } 
    328                 } 
     349                if (!TestPlane(node, i, bIntersect)) return 0; 
    329350        } 
    330351 
     
    334355        for (int i = 0; i < node->mPreferredPlane; ++ i) 
    335356        { 
    336                 // do the test only if necessary 
    337                 if (node->mPlaneMask & (1 << i)) 
    338                 { 
    339                         //-- test the n-vertex 
    340                         if (node->mBox.GetDistance(sClipPlaneAABBVertexIndices[i * 2 + 0], sFrustum.mClipPlanes[i]) > 0.0f) 
    341                         { 
    342                                 // outside 
    343                                 node->mPreferredPlane = i; 
    344                                 return 0; 
    345                         } 
    346  
    347                         //-- test the p-vertex 
    348                         if (node->mBox.GetDistance(sClipPlaneAABBVertexIndices[i * 2 + 1], sFrustum.mClipPlanes[i]) <= 0.0f) 
    349                         { 
    350                                 // completely inside: children don't need to check against this plane no more 
    351                                 node->mPlaneMask^= 1 << i; 
    352                         } 
    353                         else  
    354                         { 
    355                                 bIntersect = true; 
    356                         } 
    357                 } 
    358         } 
    359  
     357                if (!TestPlane(node, i, bIntersect)) return 0; 
     358        } 
     359*/ 
    360360        return bIntersect ? -1 : 1; 
    361361} 
     
    373373        sFrustum.CalcNPVertexIndices(sClipPlaneAABBVertexIndices); 
    374374 
    375         // calc near plane 
    376         sNearPlane = Plane3(mCamera->GetDirection(),  
    377                                 -mCamera->GetDirection() * mCamera->GetPosition()); 
     375        for (int i = 0; i<12; ++ i) 
     376//cout<<" x " << sClipPlaneAABBVertexIndices[i]; 
     377//      cout<<"\n********\n"; 
     378        // near plane 
     379        sNearPlane = Plane3(mCamera->GetDirection(), mCamera->GetPosition()); 
     380 
     381//      Debug << "near: " << sNearPlane << " d " << mCamera->GetDirection() << " " << mCamera->GetPosition() << std::endl; 
     382//      for (int i = 0; i < 6; ++ i) Debug << "plane: " << sFrustum.mClipPlanes[i] << std::endl; 
    378383} 
    379384 
     
    865870 
    866871 
     872void Bvh::Dummy() 
     873{ 
     874        for (int i = 0; i < mGeometrySize; ++ i) 
     875                Debug << mGeometry[i]->id << " " << mGeometry[i]->GetGeometry()->GetBoundingBox() << endl; 
     876 
     877        AxisAlignedBox3 boxl; boxl.Initialize(); 
     878        AxisAlignedBox3 boxr; boxr.Initialize(); 
     879 
     880 
     881        for (int i = 0; i <= 107; ++ i) 
     882                boxl.Include(mGeometry[i]->GetBoundingBox()); 
     883 
     884        for (int i = 108; i <= 193; ++ i) 
     885                boxr.Include(mGeometry[i]->GetBoundingBox()); 
     886 
     887        Debug << "dummy " << boxl << " " << boxr << endl; 
     888 
     889        queue<BvhNode *> tStack; 
     890        tStack.push(mRoot); 
     891 
     892        while (!tStack.empty()) 
     893        { 
     894                BvhNode *node = tStack.front();//top(); 
     895                tStack.pop(); 
     896 
     897                AxisAlignedBox3 box; 
     898                box.Initialize(); 
     899 
     900                int i = 0; 
     901                for (int i = node->mFirst; i <= node->mLast; ++ i) 
     902                { 
     903                        if ((mGeometry[i]->id < node->mFirst) || (mGeometry[i]->id > node->mLast)) 
     904                                cout << "big error!! " << mGeometry[i]->id << endl; 
     905                        else cout << "ok"<<mGeometry[i]->id; 
     906                        box.Include(mGeometry[i]->GetBoundingBox()); 
     907                } 
     908 
     909                Debug<< box << " " << node->GetBox() << " f " << node->mFirst << " l " << node->mLast << " id " << node->GetId() << " l " << node->IsLeaf() << endl; 
     910 
     911                //node->mBox = box; 
     912                if (!node->IsLeaf()) 
     913                { 
     914                        BvhInterior *interior = static_cast<BvhInterior *>(node); 
     915 
     916                        tStack.push(interior->mFront); 
     917                        tStack.push(interior->mBack); 
     918                } 
     919        } 
     920} 
     921 
     922 
    867923void Bvh::SetVirtualLeaves(int numTriangles)  
    868924{ 
  • GTP/trunk/App/Demos/Vis/CHC_revisited/Bvh.h

    r2761 r2762  
    440440 
    441441public: 
    442  
     442void Dummy(); 
    443443        /** Destructor. 
    444444        */ 
     
    597597        */ 
    598598        void UpdateNumLeaves(BvhNode *node) const; 
     599        /** Frustum tests the ith plane. 
     600        */ 
     601        inline bool TestPlane(BvhNode *node, int i, bool &bIntersect); 
     602 
    599603 
    600604        //////////////////////// 
  • GTP/trunk/App/Demos/Vis/CHC_revisited/BvhLoader.cpp

    r2761 r2762  
    4646        stream.read(reinterpret_cast<char *>(&(node->mFirst)), sizeof(int)); 
    4747        stream.read(reinterpret_cast<char *>(&(node->mLast)), sizeof(int)); 
     48 
    4849        stream.read(reinterpret_cast<char *>(&bMin), sizeof(Vector3)); 
    4950        stream.read(reinterpret_cast<char *>(&bMax), sizeof(Vector3)); 
     51 
     52        //if ((bMin.x >= bMax.x)||(bMin.y >= bMax.y)||(bMin.z >= bMax.z)) 
     53        //      cout << "error: " << bMin << " " << bMax << endl; 
    5054 
    5155        node->mBox = AxisAlignedBox3(bMin, bMax); 
     
    5458 
    5559        //cout << "box: " << node->mBox << " area: " << node->mArea << endl; 
     60        cout << node->mBox << " f " << node->mFirst << " l " << node->mLast << endl; 
    5661 
    5762        return node; 
     
    107112        bvh->PostProcess(); 
    108113        // set virtual leaves for 500 triangles 
    109         bvh->SetVirtualLeaves(500); 
     114        bvh->SetVirtualLeaves(0); 
    110115 
    111116        bvh->UpdateNumLeaves(bvh->mRoot); 
     
    113118        bvh->ComputeIds(); 
    114119        // specify bounds for occlusion tests 
    115         bvh->RecomputeBounds(); 
     120        //bvh->RecomputeBounds(); 
    116121        // compute and print stats 
    117122        bvh->ComputeBvhStats(); 
    118123        bvh->PrintBvhStats(); 
    119  
     124bvh->Dummy(); 
    120125        return bvh; 
    121126} 
  • GTP/trunk/App/Demos/Vis/CHC_revisited/Camera.cpp

    r2760 r2762  
    6565void Camera::LookAtBox(const AxisAlignedBox3 &box) 
    6666{ 
    67         mDirection = box.Min() - box.Max(); 
    68         mPosition = box.Max() - mDirection; 
     67        mDirection = Vector3(0, 0, box.Min().z - box.Max().z); 
     68        mPosition = Vector3(0);//box.Max() - mDirection; 
    6969 
    7070        Precompute(); 
     
    9292        GetProjectionMatrix(matProjectionView); 
    9393 
    94         matProjectionView *= matViewing; 
    95  
    96         float fInvLength; 
     94        matProjectionView = matViewing * matProjectionView; 
     95        //matProjectionView = matProjectionView * matViewing; 
     96         
    9797        float planes[6][4]; 
     98 
    9899 
    99100        ////////// 
     
    118119                // the clipping planes look outward the frustum, 
    119120                // so distances > 0 mean that a point is outside 
    120                 fInvLength      = -1.0f / sqrt(planes[i][0] * planes[i][0] +     
    121                                                                    planes[i][1] * planes[i][1] +         
    122                                                                    planes[i][2] * planes[i][2]); 
     121                float fInvLength = -1.0f /  
     122                        sqrt(planes[i][0] * planes[i][0] +       
     123                             planes[i][1] * planes[i][1] +       
     124                                 planes[i][2] * planes[i][2]); 
    123125 
    124126                planes[i][0] *= fInvLength; 
     
    127129                planes[i][3] *= fInvLength; 
    128130 
    129                 Vector3 normal(planes[i][0], planes[i][1], planes[i][2]); 
    130                 frustum.mClipPlanes[i] = Plane3(normal, planes[i][3]); 
     131                frustum.mClipPlanes[i].mNormal = Vector3(planes[i][0], planes[i][1], planes[i][2]); 
     132                frustum.mClipPlanes[i].mD = planes[i][3]; 
    131133        } 
    132134} 
     
    156158 
    157159 
    158 } 
    159  
     160 
     161void Camera::ComputePoints(Vector3 &ftl, Vector3 &ftr, Vector3 &fbl, Vector3 &fbr, 
     162                                                   Vector3 &ntl, Vector3 &ntr, Vector3 &nbl, Vector3 &nbr) 
     163{ 
     164        float z_near = 0.1f; 
     165        float z_far = 300; 
     166 
     167        const float h_near = 2.0f * tan(mFovy / 2) * z_near; 
     168        const float w_near = h_near * GetAspect(); 
     169        const float h_far = 2.0f * tan(mFovy / 2) * z_far; 
     170        const float w_far = h_far * GetAspect(); 
     171 
     172        const Vector3 view = mDirection; 
     173        const Vector3 fc = mPosition + view * z_far;  
     174         
     175        const Vector3 up = mUp; 
     176 
     177        const Vector3 right = mRight; 
     178 
     179        Vector3 t1, t2; 
     180 
     181        t1 = h_far * 0.5f * up; 
     182        t2 = w_far * 0.5f * right; 
     183 
     184        ftl = fc + t1 - t2; 
     185        ftr = fc + t1 + t2; 
     186        fbl = fc - t1 - t2; 
     187        fbr = fc - t1 + t2; 
     188 
     189        const Vector3 nc = mPosition + mDirection * z_near; 
     190         
     191        t1 = h_near * 0.5f * up; 
     192        t2 = w_near * 0.5f * right; 
     193 
     194        ntl = nc + t1 - t2; 
     195        ntr = nc + t1 + t2; 
     196        nbl = nc - t1 - t2; 
     197        nbr = nc - t1 + t2; 
     198} 
     199 
     200 
     201} 
     202 
  • GTP/trunk/App/Demos/Vis/CHC_revisited/Camera.h

    r2756 r2762  
    5555        void CalcFrustum(Frustum &frustum); 
    5656 
     57        void ComputePoints(Vector3 &ftl, Vector3 &ftr, Vector3 &fbl, Vector3 &fbr, 
     58                               Vector3 &ntl, Vector3 &ntr, Vector3 &nbl, Vector3 &nbr); 
     59 
    5760 
    5861protected: 
  • GTP/trunk/App/Demos/Vis/CHC_revisited/FrustumCullingTraverser.cpp

    r2761 r2762  
    11#include "FrustumCullingTraverser.h" 
    22#include "SceneEntity.h" 
     3 
     4using namespace std; 
    35 
    46 
     
    1618        mDistanceQueue.push(mBvh->GetRoot()); 
    1719 
     20 
    1821        int traversed = 0; 
    1922        while (!mDistanceQueue.empty()) 
     
    2730 
    2831                //bool intersects; 
    29          
    30                 if (mBvh->IsWithinViewFrustum(node)) 
     32                int intersect; 
     33                if (mBvh->IsWithinViewFrustum(node)!=0) 
    3134                { 
    3235                        // update node's visited flag => needed for rendering 
     
    3639                        ++ traversed; 
    3740                        TraverseNode(node); 
     41                        RenderBox(node->GetBox()); 
    3842                } 
    3943                else 
    40                 { 
     44                {RenderBox(node->GetBox()); 
     45                        if (node->IsLeaf())  
     46                        { 
     47                         
     48                        //cout <<"b: " << node->GetBox() << endl; 
     49                        } 
    4150                        //mNumFrustumCulledNodes ++; 
    4251                } 
     52                //cout << "intersect: " << intersect << " bx " << node->GetBox() << endl; 
    4353        } 
     54                 
     55        //RenderFrustum(); 
    4456 
    45         std::cout << "traversed: " << traversed << std::endl; 
     57        //std::cout << "traversed: " << traversed << std::endl; 
    4658} 
    4759 
  • GTP/trunk/App/Demos/Vis/CHC_revisited/Plane3.cpp

    r2755 r2762  
    1414 
    1515 
    16 Plane3::Plane3(Vector3 &normal, float dist):  
     16/*Plane3::Plane3(const Vector3 &normal, float dist):  
    1717mNormal(normal), mD(dist) 
    1818{ 
    19 } 
     19}*/ 
    2020 
    2121 
  • GTP/trunk/App/Demos/Vis/CHC_revisited/Plane3.h

    r2755 r2762  
    1616        Plane3() {} 
    1717 
    18         Plane3(Vector3 &normal, float dist); 
     18        //Plane3(const Vector3 &normal, float dist); 
    1919 
    2020        Plane3(const Vector3 &a, const Vector3 &b, const Vector3 &c); 
  • GTP/trunk/App/Demos/Vis/CHC_revisited/RenderTraverser.cpp

    r2761 r2762  
    22#include "glInterface.h" 
    33#include "Timers.h" 
     4#include "Camera.h" 
    45 
    56 
     
    6667void RenderTraverser::TraverseNode(BvhNode *node) 
    6768{ 
    68         if (node->IsVirtualLeaf()||node->IsLeaf()) 
    69         { 
     69 
     70        if (node->IsVirtualLeaf()) 
     71        { 
     72                //RenderBox(node->GetBox()); 
     73 
    7074                //mNumRenderedGeometry += 
    7175                mBvh->Render(node, mRenderState); 
     
    7478        { 
    7579                // for non leafs this renders only the bounding volume (if the flag is set) 
    76                 //node->Render(); 
    7780                BvhInterior *interior = static_cast<BvhInterior *>(node); 
    7881 
     
    394397} 
    395398 
    396 } 
     399 
     400void RenderTraverser::RenderBox(const AxisAlignedBox3 &box) 
     401{ 
     402        glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); 
     403        glDisable(GL_CULL_FACE); 
     404        glColor3f(1.0f, 0.0f, 0.0f); 
     405 
     406        glBegin(GL_QUADS); 
     407        glVertex3f(box.Min().x, box.Max().y, box.Min().z); 
     408        glVertex3f(box.Max().x, box.Max().y, box.Min().z); 
     409        glVertex3f(box.Max().x, box.Min().y, box.Min().z); 
     410        glVertex3f(box.Min().x, box.Min().y, box.Min().z); 
     411        glEnd(); 
     412 
     413        glBegin(GL_QUADS); 
     414        glVertex3f(box.Min().x, box.Min().y, box.Max().z); 
     415        glVertex3f(box.Max().x, box.Min().y, box.Max().z); 
     416        glVertex3f(box.Max().x, box.Max().y, box.Max().z); 
     417        glVertex3f(box.Min().x, box.Max().y, box.Max().z); 
     418        glEnd(); 
     419 
     420        glBegin(GL_QUADS); 
     421        glVertex3f(box.Max().x, box.Min().y, box.Min().z); 
     422        glVertex3f(box.Max().x, box.Min().y, box.Max().z); 
     423        glVertex3f(box.Max().x, box.Max().y, box.Max().z); 
     424        glVertex3f(box.Max().x, box.Max().y, box.Min().z); 
     425        glEnd(); 
     426 
     427        glBegin(GL_QUADS); 
     428        glVertex3f(box.Min().x, box.Min().y, box.Min().z); 
     429        glVertex3f(box.Min().x, box.Min().y, box.Max().z); 
     430        glVertex3f(box.Min().x, box.Max().y, box.Max().z); 
     431        glVertex3f(box.Min().x, box.Max().y, box.Min().z); 
     432        glEnd(); 
     433 
     434        glBegin(GL_QUADS); 
     435        glVertex3f(box.Min().x, box.Min().y, box.Min().z); 
     436        glVertex3f(box.Max().x, box.Min().y, box.Min().z); 
     437        glVertex3f(box.Max().x, box.Min().y, box.Max().z); 
     438        glVertex3f(box.Min().x, box.Min().y, box.Max().z); 
     439        glEnd(); 
     440 
     441        glBegin(GL_QUADS); 
     442        glVertex3f(box.Min().x, box.Max().y, box.Min().z); 
     443        glVertex3f(box.Max().x, box.Max().y, box.Min().z); 
     444        glVertex3f(box.Max().x, box.Max().y, box.Max().z); 
     445        glVertex3f(box.Min().x, box.Max().y, box.Max().z); 
     446        glEnd(); 
     447 
     448        glEnable(GL_CULL_FACE); 
     449 
     450        glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); 
     451} 
     452 
     453 
     454void RenderTraverser::RenderFrustum() 
     455{ 
     456        Vector3 ftl, ftr, fbl, fbr, ntl, ntr, nbl, nbr; 
     457        mCamera->ComputePoints(ftl, ftr, fbl, fbr, ntl, ntr, nbl, nbr); 
     458 
     459        glLineWidth(2); 
     460 
     461        glBegin(GL_LINE_LOOP); 
     462        glVertex3d(fbl.x, fbl.y, fbl.z); 
     463        glVertex3d(fbr.x, fbr.y, fbr.z); 
     464        glVertex3d(ftr.x, ftr.y, ftr.z); 
     465        glVertex3d(ftl.x, ftl.y, ftl.z); 
     466        glEnd(); 
     467 
     468        glBegin(GL_LINE_LOOP); 
     469        glVertex3d(nbl.x, nbl.y, nbl.z); 
     470        glVertex3d(nbr.x, nbr.y, nbr.z); 
     471        glVertex3d(ntr.x, ntr.y, ntr.z); 
     472        glVertex3d(ntl.x, ntl.y, ntl.z); 
     473        glEnd(); 
     474 
     475        glBegin(GL_LINE_LOOP); 
     476        glVertex3d(fbl.x, fbl.y, fbl.z); 
     477        glVertex3d(ftl.x, ftl.y, ftl.z); 
     478        glVertex3d(ntl.x, ntl.y, ntl.z); 
     479        glVertex3d(nbl.x, nbl.y, nbl.z); 
     480        glEnd(); 
     481 
     482        glBegin(GL_LINE_LOOP); 
     483        glVertex3d(fbr.x, fbr.y, fbr.z); 
     484        glVertex3d(ftr.x, ftr.y, ftr.z); 
     485        glVertex3d(ntr.x, ntr.y, ntr.z); 
     486        glVertex3d(nbr.x, nbr.y, nbr.z); 
     487        glEnd(); 
     488 
     489        glBegin(GL_LINE_LOOP); 
     490        glVertex3d(fbr.x, fbr.y, fbr.z); 
     491        glVertex3d(fbl.x, fbl.y, fbl.z); 
     492        glVertex3d(nbl.x, nbl.y, nbl.z); 
     493        glVertex3d(nbr.x, nbr.y, nbr.z); 
     494        glEnd(); 
     495 
     496        glBegin(GL_LINE_LOOP); 
     497        glVertex3d(ftr.x, ftr.y, ftr.z); 
     498        glVertex3d(ftl.x, ftl.y, ftl.z); 
     499        glVertex3d(ntl.x, ntl.y, ntl.z); 
     500        glVertex3d(ntr.x, ntr.y, ntr.z); 
     501        glEnd(); 
     502} 
     503 
     504 
     505} 
  • GTP/trunk/App/Demos/Vis/CHC_revisited/RenderTraverser.h

    r2760 r2762  
    6868        /** Sets the camera. 
    6969        */ 
    70         void SetCamera(Camera *camera); 
     70        void SetCamera(Camera *cam)  {mCamera = cam;} 
    7171        /** sets view projection matrix 
    7272        */ 
     
    8787        */ 
    8888        void SetRenderState(RenderState *state); 
     89         
     90        void RenderFrustum(); 
    8991 
    9092 
     
    117119 
    118120        void EnqueueNode(BvhNode *node); 
     121 
     122        void RenderBox(const AxisAlignedBox3 &box); 
     123 
    119124 
    120125 
  • GTP/trunk/App/Demos/Vis/CHC_revisited/Vector3.h

    r2756 r2762  
    4747        {} 
    4848 
    49         Vector3(float v): x(v), y(v), z(v) 
    50         {} 
     49        Vector3(float v): x(v), y(v), z(v){} 
    5150        /** Copy constructor. 
    5251        */ 
  • GTP/trunk/App/Demos/Vis/CHC_revisited/chcdemo.cpp

    r2760 r2762  
    128128        //const string filename("house_test.dem"); 
    129129        //const string filename("city_demo.dem"); 
    130         const string filename("city.dem"); 
     130        //const string filename("city.dem"); 
     131        const string filename("roofs.dem"); 
    131132 
    132133        if (loader.Load(filename, sceneEntities)) 
     
    136137 
    137138        BvhLoader bvhLoader; 
    138         bvh = bvhLoader.Load("city.bvh", sceneEntities); 
     139        bvh = bvhLoader.Load("roofs.bvh", sceneEntities); 
     140         
     141 
     142        //bvh = bvhLoader.Load("city.bvh", sceneEntities); 
     143        //bvh = bvhLoader.Load("house_test.bvh", sceneEntities); 
    139144 
    140145        sceneBox = bvh->GetBox(); 
     
    171176         
    172177        glDepthFunc(GL_LESS); 
     178        glEnable(GL_DEPTH_TEST); 
    173179 
    174180        SetupLighting(); 
     
    185191        //glDisable(GL_CULL_FACE); 
    186192         
     193 
    187194        GLfloat ambientColor[] = {0.5, 0.5, 0.5, 1.0}; 
    188195        GLfloat diffuseColor[] = {1.0, 0.0, 0.0, 1.0}; 
     
    322329 
    323330        glMatrixMode(GL_MODELVIEW); 
    324         glLoadIdentity();        
    325  
    326331        camera->SetupCameraView(); 
    327332 
     
    389394 
    390395        t1 = GetTime(); 
     396 
     397        traverser->SetCamera(camera); 
     398 
     399        //traverser->RenderFrustum(); 
    391400 
    392401        glEnableClientState(GL_VERTEX_ARRAY); 
     
    446455         
    447456 
    448          
    449457        begin2D(); 
    450458         
     
    473481                } 
    474482        } 
    475  
    476483        end2D(); 
    477484 
Note: See TracChangeset for help on using the changeset viewer.