Ignore:
Timestamp:
06/16/08 08:56:35 (16 years ago)
Author:
mattausch
Message:
 
File:
1 edited

Legend:

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

    r2762 r2763  
    295295{ 
    296296        // 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  
     297        if (!(node->mPlaneMask & (1 << i))) 
     298                return true; 
     299                         
     300        //////// 
     301        //-- test the n-vertex 
     302                 
     303        if ((node->mBox.GetDistance(sClipPlaneAABBVertexIndices[i * 2 + 0], sFrustum.mClipPlanes[i]) > 0.0f)) 
     304        { 
     305                // outside 
     306                node->mPreferredPlane = i; 
     307                return false; 
     308        } 
     309 
     310        //////////// 
     311        //-- test the p-vertex 
     312 
     313        if (node->mBox.GetDistance(sClipPlaneAABBVertexIndices[i * 2 + 1], sFrustum.mClipPlanes[i]) <= 0.0f) 
     314        { 
     315                // completely inside: children don't need to check against this plane no more 
     316                node->mPlaneMask^= 1 << i; 
     317        } 
     318        else  
     319        { 
     320                bIntersect = true; 
     321        } 
     322         
    327323        return true; 
    328324} 
     
    337333 
    338334 
    339         for (int i = 0; i < 6; ++ i) 
    340         { 
    341                 if (!TestPlane(node, i, bIntersect)) return 0; 
    342         } 
     335        //for (int i = 0; i < 6; ++ i) 
     336        //      if (!TestPlane(node, i, bIntersect)) return 0; 
     337         
    343338 
    344339        //////// 
    345340        //-- apply frustum culling for the planes [mPreferredPlane - 5] 
    346 /* 
     341 
    347342        for (int i = node->mPreferredPlane; i < 6; ++ i) 
    348         { 
    349343                if (!TestPlane(node, i, bIntersect)) return 0; 
    350         } 
    351  
     344         
    352345        ////////// 
    353346        //-- do the view frustum culling for the planes [0 - m_iPreferredPlane) 
    354347 
    355348        for (int i = 0; i < node->mPreferredPlane; ++ i) 
    356         { 
    357349                if (!TestPlane(node, i, bIntersect)) return 0; 
    358         } 
    359 */ 
     350         
    360351        return bIntersect ? -1 : 1; 
    361352} 
     
    373364        sFrustum.CalcNPVertexIndices(sClipPlaneAABBVertexIndices); 
    374365 
    375         for (int i = 0; i<12; ++ i) 
    376 //cout<<" x " << sClipPlaneAABBVertexIndices[i]; 
    377 //      cout<<"\n********\n"; 
    378         // near plane 
     366        // store near plane 
    379367        sNearPlane = Plane3(mCamera->GetDirection(), mCamera->GetPosition()); 
    380  
    381368//      Debug << "near: " << sNearPlane << " d " << mCamera->GetDirection() << " " << mCamera->GetPosition() << std::endl; 
    382369//      for (int i = 0; i < 6; ++ i) Debug << "plane: " << sFrustum.mClipPlanes[i] << std::endl; 
     
    392379void Bvh::RenderBoundingBox(BvhNode *node) 
    393380{ 
    394         static BvhNodeContainer dummy(1); 
     381        RenderBoundingBoxImmediate(node->GetBox()); 
     382        /**static BvhNodeContainer dummy(1); 
    395383        dummy[0] = node; 
    396         RenderBoundingBoxes(dummy); 
     384        RenderBoundingBoxes(dummy);*/ 
    397385} 
    398386 
     
    870858 
    871859 
    872 void 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  
    923860void Bvh::SetVirtualLeaves(int numTriangles)  
    924861{ 
     
    1006943 
    1007944 
    1008 } 
     945void Bvh::RenderBoundingBoxImmediate(const AxisAlignedBox3 &box) 
     946{ 
     947        const Vector3 l = box.Min(); 
     948        const Vector3 u = box.Max(); 
     949 
     950        /////////// 
     951        //-- render AABB as triangle strips 
     952 
     953        glVertex3f(l.x, l.y, u.z); 
     954        glVertex3f(u.x, l.y, u.z); 
     955        glVertex3f(l.x, u.y, u.z); 
     956        glVertex3f(u.x, u.y, u.z); 
     957        glVertex3f(l.x, u.y, l.z);  
     958        glVertex3f(u.x, u.y, l.z); 
     959        glVertex3f(l.x, l.y, l.z);  
     960        glVertex3f(u.x, l.y, l.z); 
     961 
     962        glPrimitiveRestartNV(); 
     963 
     964        //-- render second half of AABB 
     965        glVertex3f(l.x, u.y, u.z);  
     966        glVertex3f(l.x, u.y, l.z); 
     967        glVertex3f(l.x, l.y, u.z); 
     968        glVertex3f(l.x, l.y, l.z); 
     969        glVertex3f(u.x, l.y, u.z);  
     970        glVertex3f(u.x, l.y, l.z); 
     971        glVertex3f(u.x, u.y, u.z);  
     972        glVertex3f(u.x, u.y, l.z); 
     973} 
     974 
     975 
     976 
     977} 
Note: See TracChangeset for help on using the changeset viewer.