Changeset 2762 for GTP/trunk/App/Demos/Vis/CHC_revisited/Bvh.cpp
- Timestamp:
- 06/15/08 23:35:07 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Vis/CHC_revisited/Bvh.cpp
r2761 r2762 292 292 293 293 294 bool 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 294 331 int Bvh::IsWithinViewFrustum(BvhNode *node) 295 332 { … … 300 337 301 338 339 for (int i = 0; i < 6; ++ i) 340 { 341 if (!TestPlane(node, i, bIntersect)) return 0; 342 } 343 302 344 //////// 303 //-- do the viewfrustum culling for the planes [mPreferredPlane - 5]304 345 //-- apply frustum culling for the planes [mPreferredPlane - 5] 346 /* 305 347 for (int i = node->mPreferredPlane; i < 6; ++ i) 306 348 { 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; 329 350 } 330 351 … … 334 355 for (int i = 0; i < node->mPreferredPlane; ++ i) 335 356 { 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 */ 360 360 return bIntersect ? -1 : 1; 361 361 } … … 373 373 sFrustum.CalcNPVertexIndices(sClipPlaneAABBVertexIndices); 374 374 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; 378 383 } 379 384 … … 865 870 866 871 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 867 923 void Bvh::SetVirtualLeaves(int numTriangles) 868 924 {
Note: See TracChangeset
for help on using the changeset viewer.