- Timestamp:
- Mar 31, 2009, 8:05:51 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk/src/bullet/BulletCollision/BroadphaseCollision/btDbvtBroadphase.cpp
r2662 r2882 101 101 btDbvtProxy* pb=(btDbvtProxy*)nb->data; 102 102 #if DBVT_BP_SORTPAIRS 103 if(pa>pb) btSwap(pa,pb); 103 if(pa->m_uniqueId>pb->m_uniqueId) 104 btSwap(pa,pb); 104 105 #endif 105 106 pbp->m_paircache->addOverlappingPair(pa,pb); … … 133 134 m_updates_done = 0; 134 135 m_updates_ratio = 0; 135 m_paircache = paircache? 136 paircache : 137 new(btAlignedAlloc(sizeof(btHashedOverlappingPairCache),16)) btHashedOverlappingPairCache(); 136 m_paircache = paircache? paircache : new(btAlignedAlloc(sizeof(btHashedOverlappingPairCache),16)) btHashedOverlappingPairCache(); 138 137 m_gid = 0; 139 138 m_pid = 0; … … 211 210 } 212 211 212 struct BroadphaseRayTester : btDbvt::ICollide 213 { 214 btBroadphaseRayCallback& m_rayCallback; 215 BroadphaseRayTester(btBroadphaseRayCallback& orgCallback) 216 :m_rayCallback(orgCallback) 217 { 218 } 219 void Process(const btDbvtNode* leaf) 220 { 221 btDbvtProxy* proxy=(btDbvtProxy*)leaf->data; 222 m_rayCallback.process(proxy); 223 } 224 }; 225 213 226 void btDbvtBroadphase::rayTest(const btVector3& rayFrom,const btVector3& rayTo, btBroadphaseRayCallback& rayCallback,const btVector3& aabbMin,const btVector3& aabbMax) 214 227 { 215 216 struct BroadphaseRayTester : btDbvt::ICollide217 {218 btBroadphaseRayCallback& m_rayCallback;219 BroadphaseRayTester(btBroadphaseRayCallback& orgCallback)220 :m_rayCallback(orgCallback)221 {222 }223 void Process(const btDbvtNode* leaf)224 {225 btDbvtProxy* proxy=(btDbvtProxy*)leaf->data;226 m_rayCallback.process(proxy);227 }228 };229 230 228 BroadphaseRayTester callback(rayCallback); 231 229 … … 342 340 } 343 341 #endif 342 343 performDeferredRemoval(dispatcher); 344 345 } 346 347 void btDbvtBroadphase::performDeferredRemoval(btDispatcher* dispatcher) 348 { 349 350 if (m_paircache->hasDeferredRemoval()) 351 { 352 353 btBroadphasePairArray& overlappingPairArray = m_paircache->getOverlappingPairArray(); 354 355 //perform a sort, to find duplicates and to sort 'invalid' pairs to the end 356 overlappingPairArray.quickSort(btBroadphasePairSortPredicate()); 357 358 int invalidPair = 0; 359 360 361 int i; 362 363 btBroadphasePair previousPair; 364 previousPair.m_pProxy0 = 0; 365 previousPair.m_pProxy1 = 0; 366 previousPair.m_algorithm = 0; 367 368 369 for (i=0;i<overlappingPairArray.size();i++) 370 { 371 372 btBroadphasePair& pair = overlappingPairArray[i]; 373 374 bool isDuplicate = (pair == previousPair); 375 376 previousPair = pair; 377 378 bool needsRemoval = false; 379 380 if (!isDuplicate) 381 { 382 //important to perform AABB check that is consistent with the broadphase 383 btDbvtProxy* pa=(btDbvtProxy*)pair.m_pProxy0; 384 btDbvtProxy* pb=(btDbvtProxy*)pair.m_pProxy1; 385 bool hasOverlap = Intersect(pa->leaf->volume,pb->leaf->volume); 386 387 if (hasOverlap) 388 { 389 needsRemoval = false; 390 } else 391 { 392 needsRemoval = true; 393 } 394 } else 395 { 396 //remove duplicate 397 needsRemoval = true; 398 //should have no algorithm 399 btAssert(!pair.m_algorithm); 400 } 401 402 if (needsRemoval) 403 { 404 m_paircache->cleanOverlappingPair(pair,dispatcher); 405 406 pair.m_pProxy0 = 0; 407 pair.m_pProxy1 = 0; 408 invalidPair++; 409 } 410 411 } 412 413 //perform a sort, to sort 'invalid' pairs to the end 414 overlappingPairArray.quickSort(btBroadphasePairSortPredicate()); 415 overlappingPairArray.resize(overlappingPairArray.size() - invalidPair); 416 } 344 417 } 345 418 … … 347 420 void btDbvtBroadphase::collide(btDispatcher* dispatcher) 348 421 { 422 /*printf("---------------------------------------------------------\n"); 423 printf("m_sets[0].m_leaves=%d\n",m_sets[0].m_leaves); 424 printf("m_sets[1].m_leaves=%d\n",m_sets[1].m_leaves); 425 printf("numPairs = %d\n",getOverlappingPairCache()->getNumOverlappingPairs()); 426 { 427 int i; 428 for (i=0;i<getOverlappingPairCache()->getNumOverlappingPairs();i++) 429 { 430 printf("pair[%d]=(%d,%d),",i,getOverlappingPairCache()->getOverlappingPairArray()[i].m_pProxy0->getUid(), 431 getOverlappingPairCache()->getOverlappingPairArray()[i].m_pProxy1->getUid()); 432 } 433 printf("\n"); 434 } 435 */ 436 437 438 349 439 SPC(m_profiling.m_total); 350 440 /* optimize */ … … 402 492 if(pairs.size()>0) 403 493 { 404 const int ci=pairs.size(); 405 int ni=btMin( ci,btMax<int>(m_newpairs,(ci*m_cupdates)/100));494 495 int ni=btMin(pairs.size(),btMax<int>(m_newpairs,(pairs.size()*m_cupdates)/100)); 406 496 for(int i=0;i<ni;++i) 407 497 { 408 btBroadphasePair& p=pairs[(m_cid+i)% ci];498 btBroadphasePair& p=pairs[(m_cid+i)%pairs.size()]; 409 499 btDbvtProxy* pa=(btDbvtProxy*)p.m_pProxy0; 410 500 btDbvtProxy* pb=(btDbvtProxy*)p.m_pProxy1; … … 412 502 { 413 503 #if DBVT_BP_SORTPAIRS 414 if(pa>pb) btSwap(pa,pb); 504 if(pa->m_uniqueId>pb->m_uniqueId) 505 btSwap(pa,pb); 415 506 #endif 416 507 m_paircache->removeOverlappingPair(pa,pb,dispatcher); … … 467 558 aabbMin=bounds.Mins(); 468 559 aabbMax=bounds.Maxs(); 560 } 561 562 void btDbvtBroadphase::resetPool(btDispatcher* dispatcher) 563 { 564 565 int totalObjects = m_sets[0].m_leaves + m_sets[1].m_leaves; 566 if (!totalObjects) 567 { 568 //reset internal dynamic tree data structures 569 m_sets[0].clear(); 570 m_sets[1].clear(); 571 572 m_deferedcollide = false; 573 m_needcleanup = true; 574 m_prediction = 1/(btScalar)2; 575 m_stageCurrent = 0; 576 m_fixedleft = 0; 577 m_fupdates = 1; 578 m_dupdates = 0; 579 m_cupdates = 10; 580 m_newpairs = 1; 581 m_updates_call = 0; 582 m_updates_done = 0; 583 m_updates_ratio = 0; 584 585 m_gid = 0; 586 m_pid = 0; 587 m_cid = 0; 588 for(int i=0;i<=STAGECOUNT;++i) 589 { 590 m_stageRoots[i]=0; 591 } 592 } 469 593 } 470 594 … … 601 725 #undef SPC 602 726 #endif 727
Note: See TracChangeset
for help on using the changeset viewer.