Changeset 2882 for code/trunk/src/bullet/BulletCollision
- Timestamp:
- Mar 31, 2009, 8:05:51 PM (16 years ago)
- Location:
- code/trunk/src/bullet/BulletCollision
- Files:
-
- 68 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk/src/bullet/BulletCollision/BroadphaseCollision/btAxisSweep3.cpp
r2662 r2882 20 20 #include "btAxisSweep3.h" 21 21 22 #include <assert.h>23 22 24 23 btAxisSweep3::btAxisSweep3(const btVector3& worldAabbMin,const btVector3& worldAabbMax, unsigned short int maxHandles, btOverlappingPairCache* pairCache, bool disableRaycastAccelerator) -
code/trunk/src/bullet/BulletCollision/BroadphaseCollision/btAxisSweep3.h
r2662 r2882 43 43 public: 44 44 45 BT_DECLARE_ALIGNED_ALLOCATOR(); 45 46 46 47 class Edge … … 139 140 SIMD_FORCE_INLINE Handle* getHandle(BP_FP_INT_TYPE index) const {return m_pHandles + index;} 140 141 141 v oid resetPool();142 virtual void resetPool(btDispatcher* dispatcher); 142 143 143 144 void processAllOverlappingPairs(btOverlapCallback* callback); … … 221 222 222 223 if (checkCardinality) 223 assert(numEdges == m_numHandles*2+1);224 btAssert(numEdges == m_numHandles*2+1); 224 225 } 225 226 #endif //DEBUG_BROADPHASE … … 347 348 } 348 349 349 // assert(bounds.HasVolume());350 //btAssert(bounds.HasVolume()); 350 351 351 352 // init bounds … … 453 454 BP_FP_INT_TYPE btAxisSweep3Internal<BP_FP_INT_TYPE>::allocHandle() 454 455 { 455 assert(m_firstFreeHandle);456 btAssert(m_firstFreeHandle); 456 457 457 458 BP_FP_INT_TYPE handle = m_firstFreeHandle; … … 465 466 void btAxisSweep3Internal<BP_FP_INT_TYPE>::freeHandle(BP_FP_INT_TYPE handle) 466 467 { 467 assert(handle > 0 && handle < m_maxHandles);468 btAssert(handle > 0 && handle < m_maxHandles); 468 469 469 470 getHandle(handle)->SetNextFree(m_firstFreeHandle); … … 588 589 589 590 template <typename BP_FP_INT_TYPE> 590 void btAxisSweep3Internal<BP_FP_INT_TYPE>::resetPool( )591 void btAxisSweep3Internal<BP_FP_INT_TYPE>::resetPool(btDispatcher* dispatcher) 591 592 { 592 593 if (m_numHandles == 0) … … 642 643 if (!isDuplicate) 643 644 { 645 ///important to use an AABB test that is consistent with the broadphase 644 646 bool hasOverlap = testAabbOverlap(pair.m_pProxy0,pair.m_pProxy1); 645 647 … … 687 689 } 688 690 689 690 691 692 693 691 } 694 692 … … 731 729 void btAxisSweep3Internal<BP_FP_INT_TYPE>::updateHandle(BP_FP_INT_TYPE handle, const btVector3& aabbMin,const btVector3& aabbMax,btDispatcher* dispatcher) 732 730 { 733 // assert(bounds.IsFinite());734 // assert(bounds.HasVolume());731 // btAssert(bounds.IsFinite()); 732 //btAssert(bounds.HasVolume()); 735 733 736 734 Handle* pHandle = getHandle(handle); -
code/trunk/src/bullet/BulletCollision/BroadphaseCollision/btBroadphaseInterface.h
r2662 r2882 65 65 virtual void getBroadphaseAabb(btVector3& aabbMin,btVector3& aabbMax) const =0; 66 66 67 ///reset broadphase internal structures, to ensure determinism/reproducability 68 virtual void resetPool(btDispatcher* dispatcher) {}; 69 67 70 virtual void printStats() = 0; 68 71 -
code/trunk/src/bullet/BulletCollision/BroadphaseCollision/btBroadphaseProxy.h
r2662 r2882 70 70 71 71 SOFTBODY_SHAPE_PROXYTYPE, 72 72 HFFLUID_SHAPE_PROXYTYPE, 73 HFFLUID_BUOYANT_CONVEX_SHAPE_PROXYTYPE, 73 74 INVALID_SHAPE_PROXYTYPE, 74 75 … … 188 189 189 190 //keep them sorted, so the std::set operations work 190 if ( &proxy0 < &proxy1)191 if (proxy0.m_uniqueId < proxy1.m_uniqueId) 191 192 { 192 193 m_pProxy0 = &proxy0; … … 229 230 bool operator() ( const btBroadphasePair& a, const btBroadphasePair& b ) 230 231 { 231 return a.m_pProxy0 > b.m_pProxy0 || 232 (a.m_pProxy0 == b.m_pProxy0 && a.m_pProxy1 > b.m_pProxy1) || 232 const int uidA0 = a.m_pProxy0 ? a.m_pProxy0->m_uniqueId : -1; 233 const int uidB0 = b.m_pProxy0 ? b.m_pProxy0->m_uniqueId : -1; 234 const int uidA1 = a.m_pProxy1 ? a.m_pProxy1->m_uniqueId : -1; 235 const int uidB1 = b.m_pProxy1 ? b.m_pProxy1->m_uniqueId : -1; 236 237 return uidA0 > uidB0 || 238 (a.m_pProxy0 == b.m_pProxy0 && uidA1 > uidB1) || 233 239 (a.m_pProxy0 == b.m_pProxy0 && a.m_pProxy1 == b.m_pProxy1 && a.m_algorithm > b.m_algorithm); 234 240 } -
code/trunk/src/bullet/BulletCollision/BroadphaseCollision/btDbvt.cpp
r2662 r2882 394 394 } 395 395 396 // 396 #if 0 397 397 static DBVT_INLINE btDbvtNode* walkup(btDbvtNode* n,int count) 398 398 { … … 400 400 return(n); 401 401 } 402 #endif 402 403 403 404 // … … 424 425 void btDbvt::clear() 425 426 { 426 if(m_root) recursedeletenode(this,m_root); 427 if(m_root) 428 recursedeletenode(this,m_root); 427 429 btAlignedFree(m_free); 428 430 m_free=0; 431 m_lkhd = -1; 432 m_stkStack.clear(); 433 m_opath = 0; 434 429 435 } 430 436 -
code/trunk/src/bullet/BulletCollision/BroadphaseCollision/btDbvt.h
r2662 r2882 58 58 59 59 //SSE gives errors on a MSVC 7.1 60 #if (defined (WIN32) && (_MSC_VER) && _MSC_VER >= 1400) && (!defined (BT_USE_DOUBLE_PRECISION))60 #ifdef BT_USE_SSE 61 61 #define DBVT_SELECT_IMPL DBVT_IMPL_SSE 62 62 #define DBVT_MERGE_IMPL DBVT_IMPL_SSE … … 83 83 #define DBVT_PREFIX template <typename T> 84 84 #define DBVT_IPOLICY T& policy 85 #define DBVT_CHECKTYPE static const ICollide& typechecker=*(T*) 0;85 #define DBVT_CHECKTYPE static const ICollide& typechecker=*(T*)1;(void)typechecker; 86 86 #else 87 87 #define DBVT_VIRTUAL_DTOR(a) virtual ~a() {} … … 147 147 DBVT_INLINE friend bool Intersect( const btDbvtAabbMm& a, 148 148 const btDbvtAabbMm& b); 149 DBVT_INLINE friend bool Intersect( const btDbvtAabbMm& a, 150 const btDbvtAabbMm& b, 151 const btTransform& xform); 149 152 150 DBVT_INLINE friend bool Intersect( const btDbvtAabbMm& a, 153 151 const btVector3& b); … … 305 303 const btDbvtNode* root1, 306 304 DBVT_IPOLICY); 307 305 #if 0 308 306 DBVT_PREFIX 309 307 void collideTT( const btDbvtNode* root0, … … 317 315 const btTransform& xform1, 318 316 DBVT_IPOLICY); 317 #endif 318 319 319 DBVT_PREFIX 320 320 void collideTV( const btDbvtNode* root, … … 531 531 } 532 532 533 // 534 DBVT_INLINE bool Intersect( const btDbvtAabbMm& a, 535 const btDbvtAabbMm& b, 536 const btTransform& xform) 537 { 538 const btVector3 d0=xform*b.Center()-a.Center(); 539 const btVector3 d1=d0*xform.getBasis(); 540 btScalar s0[2]={0,0}; 541 btScalar s1[2]={dot(xform.getOrigin(),d0),s1[0]}; 542 a.AddSpan(d0,s0[0],s0[1]); 543 b.AddSpan(d1,s1[0],s1[1]); 544 if(s0[0]>(s1[1])) return(false); 545 if(s0[1]<(s1[0])) return(false); 546 return(true); 547 } 533 548 534 549 535 // … … 849 835 } 850 836 851 837 #if 0 852 838 // 853 839 DBVT_PREFIX … … 905 891 } 906 892 } 907 908 893 // 909 894 DBVT_PREFIX … … 917 902 collideTT(root0,root1,xform,policy); 918 903 } 904 #endif 919 905 920 906 // -
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 -
code/trunk/src/bullet/BulletCollision/BroadphaseCollision/btDbvtBroadphase.h
r2662 r2882 25 25 26 26 #define DBVT_BP_PROFILE 0 27 #define DBVT_BP_SORTPAIRS 127 //#define DBVT_BP_SORTPAIRS 1 28 28 #define DBVT_BP_PREVENTFALSEUPDATE 0 29 29 #define DBVT_BP_ACCURATESLEEPING 0 … … 115 115 void printStats(); 116 116 static void benchmark(btBroadphaseInterface*); 117 118 119 void performDeferredRemoval(btDispatcher* dispatcher); 120 121 ///reset broadphase internal structures, to ensure determinism/reproducability 122 virtual void resetPool(btDispatcher* dispatcher); 123 117 124 }; 118 125 -
code/trunk/src/bullet/BulletCollision/BroadphaseCollision/btMultiSapBroadphase.cpp
r2662 r2882 483 483 484 484 } 485 486 void btMultiSapBroadphase::resetPool(btDispatcher* dispatcher) 487 { 488 // not yet 489 } -
code/trunk/src/bullet/BulletCollision/BroadphaseCollision/btMultiSapBroadphase.h
r2662 r2882 144 144 void quicksort (btBroadphasePairArray& a, int lo, int hi); 145 145 146 ///reset broadphase internal structures, to ensure determinism/reproducability 147 virtual void resetPool(btDispatcher* dispatcher); 148 146 149 }; 147 150 -
code/trunk/src/bullet/BulletCollision/BroadphaseCollision/btOverlappingPairCache.cpp
r2662 r2882 20 20 #include "btDispatcher.h" 21 21 #include "btCollisionAlgorithm.h" 22 #include "LinearMath/btAabbUtil2.h" 22 23 23 24 #include <stdio.h> … … 136 137 { 137 138 gFindPairs++; 138 if(proxy0>proxy1) btSwap(proxy0,proxy1); 139 if(proxy0->m_uniqueId>proxy1->m_uniqueId) 140 btSwap(proxy0,proxy1); 139 141 int proxyId1 = proxy0->getUid(); 140 142 int proxyId2 = proxy1->getUid(); … … 212 214 btBroadphasePair* btHashedOverlappingPairCache::internalAddPair(btBroadphaseProxy* proxy0, btBroadphaseProxy* proxy1) 213 215 { 214 if(proxy0>proxy1) btSwap(proxy0,proxy1); 216 if(proxy0->m_uniqueId>proxy1->m_uniqueId) 217 btSwap(proxy0,proxy1); 215 218 int proxyId1 = proxy0->getUid(); 216 219 int proxyId2 = proxy1->getUid(); … … 271 274 { 272 275 gRemovePairs++; 273 if(proxy0>proxy1) btSwap(proxy0,proxy1); 276 if(proxy0->m_uniqueId>proxy1->m_uniqueId) 277 btSwap(proxy0,proxy1); 274 278 int proxyId1 = proxy0->getUid(); 275 279 int proxyId2 = proxy1->getUid(); … … 393 397 } 394 398 399 void btHashedOverlappingPairCache::sortOverlappingPairs(btDispatcher* dispatcher) 400 { 401 ///need to keep hashmap in sync with pair address, so rebuild all 402 btBroadphasePairArray tmpPairs; 403 int i; 404 for (i=0;i<m_overlappingPairArray.size();i++) 405 { 406 tmpPairs.push_back(m_overlappingPairArray[i]); 407 } 408 409 for (i=0;i<tmpPairs.size();i++) 410 { 411 removeOverlappingPair(tmpPairs[i].m_pProxy0,tmpPairs[i].m_pProxy1,dispatcher); 412 } 413 414 for (i = 0; i < m_next.size(); i++) 415 { 416 m_next[i] = BT_NULL_PAIR; 417 } 418 419 tmpPairs.quickSort(btBroadphasePairSortPredicate()); 420 421 for (i=0;i<tmpPairs.size();i++) 422 { 423 addOverlappingPair(tmpPairs[i].m_pProxy0,tmpPairs[i].m_pProxy1); 424 } 425 426 427 } 395 428 396 429 … … 430 463 { 431 464 //don't add overlap with own 432 assert(proxy0 != proxy1);465 btAssert(proxy0 != proxy1); 433 466 434 467 if (!needsBroadphaseCollision(proxy0,proxy1)) … … 461 494 if (findIndex < m_overlappingPairArray.size()) 462 495 { 463 // assert(it != m_overlappingPairSet.end());496 //btAssert(it != m_overlappingPairSet.end()); 464 497 btBroadphasePair* pair = &m_overlappingPairArray[findIndex]; 465 498 return pair; … … 491 524 { 492 525 cleanOverlappingPair(*pair,dispatcher); 493 494 m_overlappingPairArray.swap(i,m_overlappingPairArray.capacity()-1); 526 pair->m_pProxy0 = 0; 527 pair->m_pProxy1 = 0; 528 m_overlappingPairArray.swap(i,m_overlappingPairArray.size()-1); 495 529 m_overlappingPairArray.pop_back(); 496 530 gOverlappingPairs--; … … 592 626 processAllOverlappingPairs(&removeCallback,dispatcher); 593 627 } 628 629 void btSortedOverlappingPairCache::sortOverlappingPairs(btDispatcher* dispatcher) 630 { 631 //should already be sorted 632 } 633 -
code/trunk/src/bullet/BulletCollision/BroadphaseCollision/btOverlappingPairCache.h
r2662 r2882 84 84 85 85 virtual void setInternalGhostPairCallback(btOverlappingPairCallback* ghostPairCallback)=0; 86 87 virtual void sortOverlappingPairs(btDispatcher* dispatcher) = 0; 88 86 89 87 90 }; … … 260 263 } 261 264 262 public: 265 virtual void sortOverlappingPairs(btDispatcher* dispatcher); 266 267 268 protected: 263 269 264 270 btAlignedObjectArray<int> m_hashTable; … … 370 376 } 371 377 378 virtual void sortOverlappingPairs(btDispatcher* dispatcher); 379 372 380 373 381 }; … … 448 456 } 449 457 458 virtual void sortOverlappingPairs(btDispatcher* dispatcher) 459 { 460 } 450 461 451 462 -
code/trunk/src/bullet/BulletCollision/BroadphaseCollision/btQuantizedBvh.cpp
r2662 r2882 470 470 471 471 #ifdef RAYAABB2 472 btVector3 rayFrom = raySource;473 472 btVector3 rayDir = (rayTarget-raySource); 474 473 rayDir.normalize (); … … 559 558 560 559 #ifdef RAYAABB2 561 btVector3 rayFrom = raySource;562 560 btVector3 rayDirection = (rayTarget-raySource); 563 561 rayDirection.normalize (); … … 818 816 #include <new> 819 817 818 #if 0 820 819 //PCK: consts 821 820 static const unsigned BVH_ALIGNMENT = 16; … … 823 822 824 823 static const unsigned BVH_ALIGNMENT_BLOCKS = 2; 825 824 #endif 826 825 827 826 … … 1147 1146 1148 1147 1148 -
code/trunk/src/bullet/BulletCollision/BroadphaseCollision/btSimpleBroadphase.cpp
r2662 r2882 325 325 } 326 326 327 328 327 void btSimpleBroadphase::resetPool(btDispatcher* dispatcher) 328 { 329 //not yet 330 } -
code/trunk/src/bullet/BulletCollision/BroadphaseCollision/btSimpleBroadphase.h
r2662 r2882 109 109 } 110 110 111 ///reset broadphase internal structures, to ensure determinism/reproducability 112 virtual void resetPool(btDispatcher* dispatcher); 113 111 114 112 115 void validate(); -
code/trunk/src/bullet/BulletCollision/CollisionDispatch/btCollisionDispatcher.cpp
r2662 r2882 53 53 { 54 54 m_doubleDispatch[i][j] = m_collisionConfiguration->getCollisionAlgorithmCreateFunc(i,j); 55 assert(m_doubleDispatch[i][j]);55 btAssert(m_doubleDispatch[i][j]); 56 56 } 57 57 } … … 80 80 btCollisionObject* body1 = (btCollisionObject*)b1; 81 81 82 btScalar contactBreakingThreshold = btMin(gContactBreakingThreshold,btMin(body0->getCollisionShape()->getContactBreakingThreshold(),body1->getCollisionShape()->getContactBreakingThreshold())); 83 82 //test for Bullet 2.74: use a relative contact breaking threshold without clamping against 'gContactBreakingThreshold' 83 //btScalar contactBreakingThreshold = btMin(gContactBreakingThreshold,btMin(body0->getCollisionShape()->getContactBreakingThreshold(),body1->getCollisionShape()->getContactBreakingThreshold())); 84 btScalar contactBreakingThreshold = btMin(body0->getCollisionShape()->getContactBreakingThreshold(),body1->getCollisionShape()->getContactBreakingThreshold()); 85 86 btScalar contactProcessingThreshold = btMin(body0->getContactProcessingThreshold(),body1->getContactProcessingThreshold()); 87 84 88 void* mem = 0; 85 89 … … 92 96 93 97 } 94 btPersistentManifold* manifold = new(mem) btPersistentManifold (body0,body1,0,contactBreakingThreshold );98 btPersistentManifold* manifold = new(mem) btPersistentManifold (body0,body1,0,contactBreakingThreshold,contactProcessingThreshold); 95 99 manifold->m_index1a = m_manifoldsPtr.size(); 96 100 m_manifoldsPtr.push_back(manifold); … … 143 147 return algo; 144 148 } 145 146 149 147 150 … … 161 164 bool btCollisionDispatcher::needsCollision(btCollisionObject* body0,btCollisionObject* body1) 162 165 { 163 assert(body0);164 assert(body1);166 btAssert(body0); 167 btAssert(body1); 165 168 166 169 bool needsCollision = true; -
code/trunk/src/bullet/BulletCollision/CollisionDispatch/btCollisionObject.cpp
r2662 r2882 18 18 19 19 btCollisionObject::btCollisionObject() 20 : m_broadphaseHandle(0), 20 : m_anisotropicFriction(1.f,1.f,1.f), 21 m_hasAnisotropicFriction(false), 22 m_contactProcessingThreshold(1e30f), 23 m_broadphaseHandle(0), 21 24 m_collisionShape(0), 22 25 m_rootCollisionShape(0), -
code/trunk/src/bullet/BulletCollision/CollisionDispatch/btCollisionObject.h
r2662 r2882 53 53 btVector3 m_interpolationLinearVelocity; 54 54 btVector3 m_interpolationAngularVelocity; 55 56 btVector3 m_anisotropicFriction; 57 bool m_hasAnisotropicFriction; 58 btScalar m_contactProcessingThreshold; 59 55 60 btBroadphaseProxy* m_broadphaseHandle; 56 61 btCollisionShape* m_collisionShape; … … 115 120 CO_COLLISION_OBJECT =1, 116 121 CO_RIGID_BODY, 117 CO_SOFT_BODY,118 122 ///CO_GHOST_OBJECT keeps track of all objects overlapping its AABB and that pass its collision filter 119 123 ///It is useful for collision sensors, explosion objects, character controller etc. 120 CO_GHOST_OBJECT 124 CO_GHOST_OBJECT, 125 CO_SOFT_BODY, 126 CO_HF_FLUID 121 127 }; 122 128 … … 127 133 } 128 134 135 const btVector3& getAnisotropicFriction() const 136 { 137 return m_anisotropicFriction; 138 } 139 void setAnisotropicFriction(const btVector3& anisotropicFriction) 140 { 141 m_anisotropicFriction = anisotropicFriction; 142 m_hasAnisotropicFriction = (anisotropicFriction[0]!=1.f) || (anisotropicFriction[1]!=1.f) || (anisotropicFriction[2]!=1.f); 143 } 144 bool hasAnisotropicFriction() const 145 { 146 return m_hasAnisotropicFriction; 147 } 148 149 ///the constraint solver can discard solving contacts, if the distance is above this threshold. 0 by default. 150 ///Note that using contacts with positive distance can improve stability. It increases, however, the chance of colliding with degerate contacts, such as 'interior' triangle edges 151 void setContactProcessingThreshold( btScalar contactProcessingThreshold) 152 { 153 m_contactProcessingThreshold = contactProcessingThreshold; 154 } 155 btScalar getContactProcessingThreshold() const 156 { 157 return m_contactProcessingThreshold; 158 } 129 159 130 160 SIMD_FORCE_INLINE bool isStaticObject() const { -
code/trunk/src/bullet/BulletCollision/CollisionDispatch/btCollisionWorld.cpp
r2662 r2882 70 70 getBroadphase()->getOverlappingPairCache()->cleanProxyFromPairs(bp,m_dispatcher1); 71 71 getBroadphase()->destroyProxy(bp,m_dispatcher1); 72 collisionObject->setBroadphaseHandle(0); 72 73 } 73 74 } … … 119 120 120 121 122 void btCollisionWorld::updateSingleAabb(btCollisionObject* colObj) 123 { 124 btVector3 minAabb,maxAabb; 125 colObj->getCollisionShape()->getAabb(colObj->getWorldTransform(), minAabb,maxAabb); 126 //need to increase the aabb for contact thresholds 127 btVector3 contactThreshold(gContactBreakingThreshold,gContactBreakingThreshold,gContactBreakingThreshold); 128 minAabb -= contactThreshold; 129 maxAabb += contactThreshold; 130 131 btBroadphaseInterface* bp = (btBroadphaseInterface*)m_broadphasePairCache; 132 133 //moving objects should be moderately sized, probably something wrong if not 134 if ( colObj->isStaticObject() || ((maxAabb-minAabb).length2() < btScalar(1e12))) 135 { 136 bp->setAabb(colObj->getBroadphaseHandle(),minAabb,maxAabb, m_dispatcher1); 137 } else 138 { 139 //something went wrong, investigate 140 //this assert is unwanted in 3D modelers (danger of loosing work) 141 colObj->setActivationState(DISABLE_SIMULATION); 142 143 static bool reportMe = true; 144 if (reportMe && m_debugDrawer) 145 { 146 reportMe = false; 147 m_debugDrawer->reportErrorWarning("Overflow in AABB, object removed from simulation"); 148 m_debugDrawer->reportErrorWarning("If you can reproduce this, please email bugs@continuousphysics.com\n"); 149 m_debugDrawer->reportErrorWarning("Please include above information, your Platform, version of OS.\n"); 150 m_debugDrawer->reportErrorWarning("Thanks.\n"); 151 } 152 } 153 } 154 121 155 void btCollisionWorld::updateAabbs() 122 156 { … … 131 165 if (colObj->isActive()) 132 166 { 133 btVector3 minAabb,maxAabb; 134 colObj->getCollisionShape()->getAabb(colObj->getWorldTransform(), minAabb,maxAabb); 135 //need to increase the aabb for contact thresholds 136 btVector3 contactThreshold(gContactBreakingThreshold,gContactBreakingThreshold,gContactBreakingThreshold); 137 minAabb -= contactThreshold; 138 maxAabb += contactThreshold; 139 140 btBroadphaseInterface* bp = (btBroadphaseInterface*)m_broadphasePairCache; 141 142 //moving objects should be moderately sized, probably something wrong if not 143 if ( colObj->isStaticObject() || ((maxAabb-minAabb).length2() < btScalar(1e12))) 144 { 145 bp->setAabb(colObj->getBroadphaseHandle(),minAabb,maxAabb, m_dispatcher1); 146 } else 147 { 148 //something went wrong, investigate 149 //this assert is unwanted in 3D modelers (danger of loosing work) 150 colObj->setActivationState(DISABLE_SIMULATION); 151 152 static bool reportMe = true; 153 if (reportMe && m_debugDrawer) 154 { 155 reportMe = false; 156 m_debugDrawer->reportErrorWarning("Overflow in AABB, object removed from simulation"); 157 m_debugDrawer->reportErrorWarning("If you can reproduce this, please email bugs@continuousphysics.com\n"); 158 m_debugDrawer->reportErrorWarning("Please include above information, your Platform, version of OS.\n"); 159 m_debugDrawer->reportErrorWarning("Thanks.\n"); 160 } 161 } 162 } 163 } 164 167 updateSingleAabb(colObj); 168 } 169 } 165 170 } 166 171 … … 294 299 BridgeTriangleRaycastCallback( const btVector3& from,const btVector3& to, 295 300 btCollisionWorld::RayResultCallback* resultCallback, btCollisionObject* collisionObject,btTriangleMeshShape* triangleMesh): 296 btTriangleRaycastCallback(from,to), 301 //@BP Mod 302 btTriangleRaycastCallback(from,to, resultCallback->m_flags), 297 303 m_resultCallback(resultCallback), 298 304 m_collisionObject(collisionObject), … … 343 349 BridgeTriangleRaycastCallback( const btVector3& from,const btVector3& to, 344 350 btCollisionWorld::RayResultCallback* resultCallback, btCollisionObject* collisionObject,btConcaveShape* triangleMesh): 345 btTriangleRaycastCallback(from,to), 351 //@BP Mod 352 btTriangleRaycastCallback(from,to, resultCallback->m_flags), 346 353 m_resultCallback(resultCallback), 347 354 m_collisionObject(collisionObject), … … 664 671 //RigidcollisionObject* collisionObject = ctrl->GetRigidcollisionObject(); 665 672 //btVector3 collisionObjectAabbMin,collisionObjectAabbMax; 666 673 #if 0 667 674 #ifdef RECALCULATE_AABB 668 675 btVector3 collisionObjectAabbMin,collisionObjectAabbMax; … … 672 679 const btVector3& collisionObjectAabbMin = collisionObject->getBroadphaseHandle()->m_aabbMin; 673 680 const btVector3& collisionObjectAabbMax = collisionObject->getBroadphaseHandle()->m_aabbMax; 681 #endif 674 682 #endif 675 683 //btScalar hitLambda = m_resultCallback.m_closestHitFraction; -
code/trunk/src/bullet/BulletCollision/CollisionDispatch/btCollisionWorld.h
r2877 r2882 139 139 } 140 140 141 void updateSingleAabb(btCollisionObject* colObj); 142 141 143 virtual void updateAabbs(); 142 143 144 144 145 … … 193 194 short int m_collisionFilterGroup; 194 195 short int m_collisionFilterMask; 196 //@BP Mod - Custom flags, currently used to enable backface culling on tri-meshes, see btRaycastCallback 197 unsigned int m_flags; 195 198 196 199 virtual ~RayResultCallback() … … 206 209 m_collisionObject(0), 207 210 m_collisionFilterGroup(btBroadphaseProxy::DefaultFilter), 208 m_collisionFilterMask(btBroadphaseProxy::AllFilter) 211 m_collisionFilterMask(btBroadphaseProxy::AllFilter), 212 //@BP Mod 213 m_flags(0) 209 214 { 210 215 } -
code/trunk/src/bullet/BulletCollision/CollisionDispatch/btCompoundCollisionAlgorithm.cpp
r2662 r2882 20 20 #include "LinearMath/btIDebugDraw.h" 21 21 #include "LinearMath/btAabbUtil2.h" 22 #include "btManifoldResult.h" 22 23 23 24 btCompoundCollisionAlgorithm::btCompoundCollisionAlgorithm( const btCollisionAlgorithmConstructionInfo& ci,btCollisionObject* body0,btCollisionObject* body1,bool isSwapped) … … 29 30 30 31 btCollisionObject* colObj = m_isSwapped? body1 : body0; 32 btAssert (colObj->getCollisionShape()->isCompound()); 33 34 btCompoundShape* compoundShape = static_cast<btCompoundShape*>(colObj->getCollisionShape()); 35 m_compoundShapeRevision = compoundShape->getUpdateRevision(); 36 37 preallocateChildAlgorithms(body0,body1); 38 } 39 40 void btCompoundCollisionAlgorithm::preallocateChildAlgorithms(btCollisionObject* body0,btCollisionObject* body1) 41 { 42 btCollisionObject* colObj = m_isSwapped? body1 : body0; 31 43 btCollisionObject* otherObj = m_isSwapped? body0 : body1; 32 assert (colObj->getCollisionShape()->isCompound());44 btAssert (colObj->getCollisionShape()->isCompound()); 33 45 34 46 btCompoundShape* compoundShape = static_cast<btCompoundShape*>(colObj->getCollisionShape()); 47 35 48 int numChildren = compoundShape->getNumChildShapes(); 36 49 int i; … … 47 60 btCollisionShape* childShape = compoundShape->getChildShape(i); 48 61 colObj->internalSetTemporaryCollisionShape( childShape ); 49 m_childCollisionAlgorithms[i] = ci.m_dispatcher1->findAlgorithm(colObj,otherObj,m_sharedManifold);62 m_childCollisionAlgorithms[i] = m_dispatcher->findAlgorithm(colObj,otherObj,m_sharedManifold); 50 63 colObj->internalSetTemporaryCollisionShape( tmpShape ); 51 64 } … … 53 66 } 54 67 55 56 btCompoundCollisionAlgorithm::~btCompoundCollisionAlgorithm() 68 void btCompoundCollisionAlgorithm::removeChildAlgorithms() 57 69 { 58 70 int numChildren = m_childCollisionAlgorithms.size(); … … 66 78 } 67 79 } 80 } 81 82 btCompoundCollisionAlgorithm::~btCompoundCollisionAlgorithm() 83 { 84 removeChildAlgorithms(); 68 85 } 69 86 … … 168 185 btCollisionObject* otherObj = m_isSwapped? body0 : body1; 169 186 170 assert (colObj->getCollisionShape()->isCompound()); 187 188 189 btAssert (colObj->getCollisionShape()->isCompound()); 171 190 btCompoundShape* compoundShape = static_cast<btCompoundShape*>(colObj->getCollisionShape()); 191 192 ///btCompoundShape might have changed: 193 ////make sure the internal child collision algorithm caches are still valid 194 if (compoundShape->getUpdateRevision() != m_compoundShapeRevision) 195 { 196 ///clear and update all 197 removeChildAlgorithms(); 198 199 preallocateChildAlgorithms(body0,body1); 200 } 201 172 202 173 203 btDbvt* tree = compoundShape->getDynamicAabbTree(); … … 175 205 btCompoundLeafCallback callback(colObj,otherObj,m_dispatcher,dispatchInfo,resultOut,&m_childCollisionAlgorithms[0],m_sharedManifold); 176 206 207 ///we need to refresh all contact manifolds 208 ///note that we should actually recursively traverse all children, btCompoundShape can nested more then 1 level deep 209 ///so we should add a 'refreshManifolds' in the btCollisionAlgorithm 210 { 211 int i; 212 btManifoldArray manifoldArray; 213 for (i=0;i<m_childCollisionAlgorithms.size();i++) 214 { 215 if (m_childCollisionAlgorithms[i]) 216 { 217 m_childCollisionAlgorithms[i]->getAllContactManifolds(manifoldArray); 218 for (int m=0;m<manifoldArray.size();m++) 219 { 220 if (manifoldArray[m]->getNumContacts()) 221 { 222 resultOut->setPersistentManifold(manifoldArray[m]); 223 resultOut->refreshContactPoints(); 224 resultOut->setPersistentManifold(0);//??necessary? 225 } 226 } 227 manifoldArray.clear(); 228 } 229 } 230 } 177 231 178 232 if (tree) … … 243 297 btCollisionObject* otherObj = m_isSwapped? body0 : body1; 244 298 245 assert (colObj->getCollisionShape()->isCompound());299 btAssert (colObj->getCollisionShape()->isCompound()); 246 300 247 301 btCompoundShape* compoundShape = static_cast<btCompoundShape*>(colObj->getCollisionShape()); … … 286 340 287 341 342 -
code/trunk/src/bullet/BulletCollision/CollisionDispatch/btCompoundCollisionAlgorithm.h
r2662 r2882 27 27 #include "LinearMath/btAlignedObjectArray.h" 28 28 class btDispatcher; 29 class btCollisionObject; 29 30 30 31 /// btCompoundCollisionAlgorithm supports collision between CompoundCollisionShapes and other collision shapes … … 36 37 class btPersistentManifold* m_sharedManifold; 37 38 bool m_ownsManifold; 39 40 int m_compoundShapeRevision;//to keep track of changes, so that childAlgorithm array can be updated 38 41 42 void removeChildAlgorithms(); 43 44 void preallocateChildAlgorithms(btCollisionObject* body0,btCollisionObject* body1); 45 39 46 public: 40 47 -
code/trunk/src/bullet/BulletCollision/CollisionDispatch/btConvexConvexAlgorithm.cpp
r2662 r2882 52 52 btConvexConvexAlgorithm::CreateFunc::CreateFunc(btSimplexSolverInterface* simplexSolver, btConvexPenetrationDepthSolver* pdSolver) 53 53 { 54 m_numPerturbationIterations = 0; 55 m_minimumPointsPerturbationThreshold = 3; 54 56 m_simplexSolver = simplexSolver; 55 57 m_pdSolver = pdSolver; … … 60 62 } 61 63 62 btConvexConvexAlgorithm::btConvexConvexAlgorithm(btPersistentManifold* mf,const btCollisionAlgorithmConstructionInfo& ci,btCollisionObject* body0,btCollisionObject* body1,btSimplexSolverInterface* simplexSolver, btConvexPenetrationDepthSolver* pdSolver )64 btConvexConvexAlgorithm::btConvexConvexAlgorithm(btPersistentManifold* mf,const btCollisionAlgorithmConstructionInfo& ci,btCollisionObject* body0,btCollisionObject* body1,btSimplexSolverInterface* simplexSolver, btConvexPenetrationDepthSolver* pdSolver,int numPerturbationIterations, int minimumPointsPerturbationThreshold) 63 65 : btActivatingCollisionAlgorithm(ci,body0,body1), 64 66 m_simplexSolver(simplexSolver), … … 66 68 m_ownManifold (false), 67 69 m_manifoldPtr(mf), 68 m_lowLevelOfDetail(false) 70 m_lowLevelOfDetail(false), 69 71 #ifdef USE_SEPDISTANCE_UTIL2 70 72 ,m_sepDistance((static_cast<btConvexShape*>(body0->getCollisionShape()))->getAngularMotionDisc(), 71 (static_cast<btConvexShape*>(body1->getCollisionShape()))->getAngularMotionDisc()) 73 (static_cast<btConvexShape*>(body1->getCollisionShape()))->getAngularMotionDisc()), 72 74 #endif 75 m_numPerturbationIterations(numPerturbationIterations), 76 m_minimumPointsPerturbationThreshold(minimumPointsPerturbationThreshold) 73 77 { 74 78 (void)body0; … … 94 98 95 99 96 97 100 struct btPerturbedContactResult : public btManifoldResult 101 { 102 btManifoldResult* m_originalManifoldResult; 103 btTransform m_transformA; 104 btTransform m_transformB; 105 btTransform m_unPerturbedTransform; 106 bool m_perturbA; 107 btIDebugDraw* m_debugDrawer; 108 109 110 btPerturbedContactResult(btManifoldResult* originalResult,const btTransform& transformA,const btTransform& transformB,const btTransform& unPerturbedTransform,bool perturbA,btIDebugDraw* debugDrawer) 111 :m_originalManifoldResult(originalResult), 112 m_transformA(transformA), 113 m_transformB(transformB), 114 m_perturbA(perturbA), 115 m_unPerturbedTransform(unPerturbedTransform), 116 m_debugDrawer(debugDrawer) 117 { 118 } 119 virtual ~ btPerturbedContactResult() 120 { 121 } 122 123 virtual void addContactPoint(const btVector3& normalOnBInWorld,const btVector3& pointInWorld,btScalar orgDepth) 124 { 125 btVector3 endPt,startPt; 126 btScalar newDepth; 127 btVector3 newNormal; 128 129 if (m_perturbA) 130 { 131 btVector3 endPtOrg = pointInWorld + normalOnBInWorld*orgDepth; 132 endPt = (m_unPerturbedTransform*m_transformA.inverse())(endPtOrg); 133 newDepth = (endPt - pointInWorld).dot(normalOnBInWorld); 134 startPt = endPt+normalOnBInWorld*newDepth; 135 } else 136 { 137 endPt = pointInWorld + normalOnBInWorld*orgDepth; 138 startPt = (m_unPerturbedTransform*m_transformB.inverse())(pointInWorld); 139 newDepth = (endPt - startPt).dot(normalOnBInWorld); 140 141 } 142 143 //#define DEBUG_CONTACTS 1 144 #ifdef DEBUG_CONTACTS 145 m_debugDrawer->drawLine(startPt,endPt,btVector3(1,0,0)); 146 m_debugDrawer->drawSphere(startPt,0.05,btVector3(0,1,0)); 147 m_debugDrawer->drawSphere(endPt,0.05,btVector3(0,0,1)); 148 #endif //DEBUG_CONTACTS 149 150 151 m_originalManifoldResult->addContactPoint(normalOnBInWorld,startPt,newDepth); 152 } 153 154 }; 155 156 extern btScalar gContactBreakingThreshold; 98 157 99 158 // … … 111 170 resultOut->setPersistentManifold(m_manifoldPtr); 112 171 172 //comment-out next line to test multi-contact generation 173 //resultOut->getPersistentManifold()->clearManifold(); 113 174 114 175 … … 147 208 148 209 gjkPairDetector.getClosestPoints(input,*resultOut,dispatchInfo.m_debugDraw); 149 150 210 btScalar sepDist = gjkPairDetector.getCachedSeparatingDistance()+dispatchInfo.m_convexConservativeDistanceThreshold; 211 212 //now perturbe directions to get multiple contact points 213 btVector3 v0,v1; 214 btVector3 sepNormalWorldSpace = gjkPairDetector.getCachedSeparatingAxis().normalized(); 215 btPlaneSpace1(sepNormalWorldSpace,v0,v1); 216 //now perform 'm_numPerturbationIterations' collision queries with the perturbated collision objects 217 218 //perform perturbation when more then 'm_minimumPointsPerturbationThreshold' points 219 if (resultOut->getPersistentManifold()->getNumContacts() < m_minimumPointsPerturbationThreshold) 220 { 221 222 int i; 223 224 bool perturbeA = true; 225 const btScalar angleLimit = 0.125f * SIMD_PI; 226 btScalar perturbeAngle; 227 btScalar radiusA = min0->getAngularMotionDisc(); 228 btScalar radiusB = min1->getAngularMotionDisc(); 229 if (radiusA < radiusB) 230 { 231 perturbeAngle = gContactBreakingThreshold /radiusA; 232 perturbeA = true; 233 } else 234 { 235 perturbeAngle = gContactBreakingThreshold / radiusB; 236 perturbeA = false; 237 } 238 if ( perturbeAngle > angleLimit ) 239 perturbeAngle = angleLimit; 240 241 btTransform unPerturbedTransform; 242 if (perturbeA) 243 { 244 unPerturbedTransform = input.m_transformA; 245 } else 246 { 247 unPerturbedTransform = input.m_transformB; 248 } 249 250 for ( i=0;i<m_numPerturbationIterations;i++) 251 { 252 btQuaternion perturbeRot(v0,perturbeAngle); 253 btScalar iterationAngle = i*(SIMD_2_PI/btScalar(m_numPerturbationIterations)); 254 btQuaternion rotq(sepNormalWorldSpace,iterationAngle); 255 256 257 if (perturbeA) 258 { 259 input.m_transformA.setBasis( btMatrix3x3(rotq.inverse()*perturbeRot*rotq)*body0->getWorldTransform().getBasis()); 260 input.m_transformB = body1->getWorldTransform(); 261 #ifdef DEBUG_CONTACTS 262 dispatchInfo.m_debugDraw->drawTransform(input.m_transformA,10.0); 263 #endif //DEBUG_CONTACTS 264 } else 265 { 266 input.m_transformA = body0->getWorldTransform(); 267 input.m_transformB.setBasis( btMatrix3x3(rotq.inverse()*perturbeRot*rotq)*body1->getWorldTransform().getBasis()); 268 #ifdef DEBUG_CONTACTS 269 dispatchInfo.m_debugDraw->drawTransform(input.m_transformB,10.0); 270 #endif 271 } 272 273 btPerturbedContactResult perturbedResultOut(resultOut,input.m_transformA,input.m_transformB,unPerturbedTransform,perturbeA,dispatchInfo.m_debugDraw); 274 gjkPairDetector.getClosestPoints(input,perturbedResultOut,dispatchInfo.m_debugDraw); 275 276 277 } 278 } 279 280 151 281 152 282 #ifdef USE_SEPDISTANCE_UTIL2 -
code/trunk/src/bullet/BulletCollision/CollisionDispatch/btConvexConvexAlgorithm.h
r2662 r2882 34 34 ///#define USE_SEPDISTANCE_UTIL2 1 35 35 36 ///ConvexConvexAlgorithm collision algorithm implements time of impact, convex closest points and penetration depth calculations. 36 ///The convexConvexAlgorithm collision algorithm implements time of impact, convex closest points and penetration depth calculations between two convex objects. 37 ///Multiple contact points are calculated by perturbing the orientation of the smallest object orthogonal to the separating normal. 38 ///This idea was described by Gino van den Bergen in this forum topic http://www.bulletphysics.com/Bullet/phpBB3/viewtopic.php?f=4&t=288&p=888#p888 37 39 class btConvexConvexAlgorithm : public btActivatingCollisionAlgorithm 38 40 { … … 48 50 bool m_lowLevelOfDetail; 49 51 52 int m_numPerturbationIterations; 53 int m_minimumPointsPerturbationThreshold; 54 55 50 56 ///cache separating vector to speedup collision detection 51 57 … … 53 59 public: 54 60 55 btConvexConvexAlgorithm(btPersistentManifold* mf,const btCollisionAlgorithmConstructionInfo& ci,btCollisionObject* body0,btCollisionObject* body1, btSimplexSolverInterface* simplexSolver, btConvexPenetrationDepthSolver* pdSolver); 61 btConvexConvexAlgorithm(btPersistentManifold* mf,const btCollisionAlgorithmConstructionInfo& ci,btCollisionObject* body0,btCollisionObject* body1, btSimplexSolverInterface* simplexSolver, btConvexPenetrationDepthSolver* pdSolver, int numPerturbationIterations, int minimumPointsPerturbationThreshold); 62 56 63 57 64 virtual ~btConvexConvexAlgorithm(); … … 79 86 struct CreateFunc :public btCollisionAlgorithmCreateFunc 80 87 { 88 81 89 btConvexPenetrationDepthSolver* m_pdSolver; 82 90 btSimplexSolverInterface* m_simplexSolver; 83 91 int m_numPerturbationIterations; 92 int m_minimumPointsPerturbationThreshold; 93 84 94 CreateFunc(btSimplexSolverInterface* simplexSolver, btConvexPenetrationDepthSolver* pdSolver); 85 95 … … 89 99 { 90 100 void* mem = ci.m_dispatcher1->allocateCollisionAlgorithm(sizeof(btConvexConvexAlgorithm)); 91 return new(mem) btConvexConvexAlgorithm(ci.m_manifold,ci,body0,body1,m_simplexSolver,m_pdSolver );101 return new(mem) btConvexConvexAlgorithm(ci.m_manifold,ci,body0,body1,m_simplexSolver,m_pdSolver,m_numPerturbationIterations,m_minimumPointsPerturbationThreshold); 92 102 } 93 103 }; -
code/trunk/src/bullet/BulletCollision/CollisionDispatch/btConvexPlaneCollisionAlgorithm.cpp
r2662 r2882 5 5 This software is provided 'as-is', without any express or implied warranty. 6 6 In no event will the authors be held liable for any damages arising from the use of this software. 7 Permission is granted to anyone to use this software for any purpose, 8 including commercial applications, and to alter it and redistribute it freely, 7 Permission is granted to anyone to use this software for any purpose, 8 including commercial applications, and to alter it and redistribute it freely, 9 9 subject to the following restrictions: 10 10 … … 23 23 //#include <stdio.h> 24 24 25 btConvexPlaneCollisionAlgorithm::btConvexPlaneCollisionAlgorithm(btPersistentManifold* mf,const btCollisionAlgorithmConstructionInfo& ci,btCollisionObject* col0,btCollisionObject* col1, bool isSwapped )25 btConvexPlaneCollisionAlgorithm::btConvexPlaneCollisionAlgorithm(btPersistentManifold* mf,const btCollisionAlgorithmConstructionInfo& ci,btCollisionObject* col0,btCollisionObject* col1, bool isSwapped, int numPerturbationIterations,int minimumPointsPerturbationThreshold) 26 26 : btCollisionAlgorithm(ci), 27 27 m_ownManifold(false), 28 28 m_manifoldPtr(mf), 29 m_isSwapped(isSwapped) 29 m_isSwapped(isSwapped), 30 m_numPerturbationIterations(numPerturbationIterations), 31 m_minimumPointsPerturbationThreshold(minimumPointsPerturbationThreshold) 30 32 { 31 33 btCollisionObject* convexObj = m_isSwapped? col1 : col0; 32 34 btCollisionObject* planeObj = m_isSwapped? col0 : col1; 33 35 34 36 if (!m_manifoldPtr && m_dispatcher->needsCollision(convexObj,planeObj)) 35 37 { … … 49 51 } 50 52 51 52 53 void btConvexPlaneCollisionAlgorithm::processCollision (btCollisionObject* body0,btCollisionObject* body1,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut) 53 void btConvexPlaneCollisionAlgorithm::collideSingleContact (const btQuaternion& perturbeRot, btCollisionObject* body0,btCollisionObject* body1,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut) 54 54 { 55 (void)dispatchInfo; 56 (void)resultOut; 57 if (!m_manifoldPtr) 58 return; 59 60 btCollisionObject* convexObj = m_isSwapped? body1 : body0; 55 btCollisionObject* convexObj = m_isSwapped? body1 : body0; 61 56 btCollisionObject* planeObj = m_isSwapped? body0: body1; 62 57 … … 64 59 btStaticPlaneShape* planeShape = (btStaticPlaneShape*) planeObj->getCollisionShape(); 65 60 66 61 bool hasCollision = false; 67 62 const btVector3& planeNormal = planeShape->getPlaneNormal(); 68 63 const btScalar& planeConstant = planeShape->getPlaneConstant(); 64 65 btTransform convexWorldTransform = convexObj->getWorldTransform(); 66 btTransform convexInPlaneTrans; 67 convexInPlaneTrans= planeObj->getWorldTransform().inverse() * convexWorldTransform; 68 //now perturbe the convex-world transform 69 convexWorldTransform.getBasis()*=btMatrix3x3(perturbeRot); 69 70 btTransform planeInConvex; 70 planeInConvex= convex Obj->getWorldTransform().inverse() * planeObj->getWorldTransform();71 btTransform convexInPlaneTrans;72 convexInPlaneTrans= planeObj->getWorldTransform().inverse() * convexObj->getWorldTransform();71 planeInConvex= convexWorldTransform.inverse() * planeObj->getWorldTransform(); 72 73 btVector3 vtx = convexShape->localGetSupportingVertex(planeInConvex.getBasis()*-planeNormal); 73 74 74 btVector3 vtx = convexShape->localGetSupportingVertex(planeInConvex.getBasis()*-planeNormal);75 75 btVector3 vtxInPlane = convexInPlaneTrans(vtx); 76 76 btScalar distance = (planeNormal.dot(vtxInPlane) - planeConstant); … … 88 88 resultOut->addContactPoint(normalOnSurfaceB,pOnB,distance); 89 89 } 90 } 91 92 93 void btConvexPlaneCollisionAlgorithm::processCollision (btCollisionObject* body0,btCollisionObject* body1,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut) 94 { 95 (void)dispatchInfo; 96 if (!m_manifoldPtr) 97 return; 98 99 btCollisionObject* convexObj = m_isSwapped? body1 : body0; 100 btCollisionObject* planeObj = m_isSwapped? body0: body1; 101 102 btConvexShape* convexShape = (btConvexShape*) convexObj->getCollisionShape(); 103 btStaticPlaneShape* planeShape = (btStaticPlaneShape*) planeObj->getCollisionShape(); 104 105 bool hasCollision = false; 106 const btVector3& planeNormal = planeShape->getPlaneNormal(); 107 const btScalar& planeConstant = planeShape->getPlaneConstant(); 108 109 //first perform a collision query with the non-perturbated collision objects 110 { 111 btQuaternion rotq(0,0,0,1); 112 collideSingleContact(rotq,body0,body1,dispatchInfo,resultOut); 113 } 114 115 if (resultOut->getPersistentManifold()->getNumContacts()<m_minimumPointsPerturbationThreshold) 116 { 117 btVector3 v0,v1; 118 btPlaneSpace1(planeNormal,v0,v1); 119 //now perform 'm_numPerturbationIterations' collision queries with the perturbated collision objects 120 121 const btScalar angleLimit = 0.125f * SIMD_PI; 122 btScalar perturbeAngle; 123 btScalar radius = convexShape->getAngularMotionDisc(); 124 perturbeAngle = gContactBreakingThreshold / radius; 125 if ( perturbeAngle > angleLimit ) 126 perturbeAngle = angleLimit; 127 128 btQuaternion perturbeRot(v0,perturbeAngle); 129 for (int i=0;i<m_numPerturbationIterations;i++) 130 { 131 btScalar iterationAngle = i*(SIMD_2_PI/btScalar(m_numPerturbationIterations)); 132 btQuaternion rotq(planeNormal,iterationAngle); 133 collideSingleContact(rotq.inverse()*perturbeRot*rotq,body0,body1,dispatchInfo,resultOut); 134 } 135 } 136 90 137 if (m_ownManifold) 91 138 { -
code/trunk/src/bullet/BulletCollision/CollisionDispatch/btConvexPlaneCollisionAlgorithm.h
r2662 r2882 5 5 This software is provided 'as-is', without any express or implied warranty. 6 6 In no event will the authors be held liable for any damages arising from the use of this software. 7 Permission is granted to anyone to use this software for any purpose, 8 including commercial applications, and to alter it and redistribute it freely, 7 Permission is granted to anyone to use this software for any purpose, 8 including commercial applications, and to alter it and redistribute it freely, 9 9 subject to the following restrictions: 10 10 … … 29 29 class btConvexPlaneCollisionAlgorithm : public btCollisionAlgorithm 30 30 { 31 bool m_ownManifold;31 bool m_ownManifold; 32 32 btPersistentManifold* m_manifoldPtr; 33 bool m_isSwapped; 34 33 bool m_isSwapped; 34 int m_numPerturbationIterations; 35 int m_minimumPointsPerturbationThreshold; 36 35 37 public: 36 38 37 btConvexPlaneCollisionAlgorithm(btPersistentManifold* mf,const btCollisionAlgorithmConstructionInfo& ci,btCollisionObject* col0,btCollisionObject* col1, bool isSwapped );39 btConvexPlaneCollisionAlgorithm(btPersistentManifold* mf,const btCollisionAlgorithmConstructionInfo& ci,btCollisionObject* col0,btCollisionObject* col1, bool isSwapped, int numPerturbationIterations,int minimumPointsPerturbationThreshold); 38 40 39 41 virtual ~btConvexPlaneCollisionAlgorithm(); 40 42 41 43 virtual void processCollision (btCollisionObject* body0,btCollisionObject* body1,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut); 44 45 void collideSingleContact (const btQuaternion& perturbeRot, btCollisionObject* body0,btCollisionObject* body1,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut); 42 46 43 47 virtual btScalar calculateTimeOfImpact(btCollisionObject* body0,btCollisionObject* body1,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut); … … 53 57 struct CreateFunc :public btCollisionAlgorithmCreateFunc 54 58 { 59 int m_numPerturbationIterations; 60 int m_minimumPointsPerturbationThreshold; 61 62 CreateFunc() 63 : m_numPerturbationIterations(3), 64 m_minimumPointsPerturbationThreshold(3) 65 { 66 } 67 55 68 virtual btCollisionAlgorithm* CreateCollisionAlgorithm(btCollisionAlgorithmConstructionInfo& ci, btCollisionObject* body0,btCollisionObject* body1) 56 69 { … … 58 71 if (!m_swapped) 59 72 { 60 return new(mem) btConvexPlaneCollisionAlgorithm(0,ci,body0,body1,false );73 return new(mem) btConvexPlaneCollisionAlgorithm(0,ci,body0,body1,false,m_numPerturbationIterations,m_minimumPointsPerturbationThreshold); 61 74 } else 62 75 { 63 return new(mem) btConvexPlaneCollisionAlgorithm(0,ci,body0,body1,true );76 return new(mem) btConvexPlaneCollisionAlgorithm(0,ci,body0,body1,true,m_numPerturbationIterations,m_minimumPointsPerturbationThreshold); 64 77 } 65 78 } -
code/trunk/src/bullet/BulletCollision/CollisionDispatch/btDefaultCollisionConfiguration.cpp
r2662 r2882 289 289 return m_emptyCreateFunc; 290 290 } 291 292 void btDefaultCollisionConfiguration::setConvexConvexMultipointIterations(int numPerturbationIterations, int minimumPointsPerturbationThreshold) 293 { 294 btConvexConvexAlgorithm::CreateFunc* convexConvex = (btConvexConvexAlgorithm::CreateFunc*) m_convexConvexCreateFunc; 295 convexConvex->m_numPerturbationIterations = numPerturbationIterations; 296 convexConvex->m_minimumPointsPerturbationThreshold = minimumPointsPerturbationThreshold; 297 } -
code/trunk/src/bullet/BulletCollision/CollisionDispatch/btDefaultCollisionConfiguration.h
r2662 r2882 112 112 virtual btCollisionAlgorithmCreateFunc* getCollisionAlgorithmCreateFunc(int proxyType0,int proxyType1); 113 113 114 ///Use this method to allow to generate multiple contact points between at once, between two objects using the generic convex-convex algorithm. 115 ///By default, this feature is disabled for best performance. 116 ///@param numPerturbationIterations controls the number of collision queries. Set it to zero to disable the feature. 117 ///@param minimumPointsPerturbationThreshold is the minimum number of points in the contact cache, above which the feature is disabled 118 ///3 is a good value for both params, if you want to enable the feature. This is because the default contact cache contains a maximum of 4 points, and one collision query at the unperturbed orientation is performed first. 119 ///See Bullet/Demos/CollisionDemo for an example how this feature gathers multiple points. 120 ///@todo we could add a per-object setting of those parameters, for level-of-detail collision detection. 121 void setConvexConvexMultipointIterations(int numPerturbationIterations=3, int minimumPointsPerturbationThreshold = 3); 114 122 115 123 }; -
code/trunk/src/bullet/BulletCollision/CollisionDispatch/btGhostObject.cpp
r2662 r2882 64 64 btPairCachingGhostObject::~btPairCachingGhostObject() 65 65 { 66 m_hashPairCache->~btHashedOverlappingPairCache(); 66 67 btAlignedFree( m_hashPairCache ); 67 68 } -
code/trunk/src/bullet/BulletCollision/CollisionDispatch/btManifoldResult.cpp
r2662 r2882 56 56 void btManifoldResult::addContactPoint(const btVector3& normalOnBInWorld,const btVector3& pointInWorld,btScalar depth) 57 57 { 58 assert(m_manifoldPtr);58 btAssert(m_manifoldPtr); 59 59 //order in manifold needs to match 60 60 … … 93 93 newPt.m_index0 = m_index0; 94 94 newPt.m_index1 = m_index1; 95 95 //printf("depth=%f\n",depth); 96 96 ///@todo, check this for any side effects 97 97 if (insertIndex >= 0) -
code/trunk/src/bullet/BulletCollision/CollisionDispatch/btManifoldResult.h
r2662 r2882 46 46 int m_index0; 47 47 int m_index1; 48 49 48 50 public: 49 51 … … 78 80 } 79 81 82 80 83 virtual void addContactPoint(const btVector3& normalOnBInWorld,const btVector3& pointInWorld,btScalar depth); 81 84 -
code/trunk/src/bullet/BulletCollision/CollisionDispatch/btSimulationIslandManager.cpp
r2662 r2882 25 25 #include "LinearMath/btQuickprof.h" 26 26 27 btSimulationIslandManager::btSimulationIslandManager() 27 btSimulationIslandManager::btSimulationIslandManager(): 28 m_splitIslands(true) 28 29 { 29 30 } … … 44 45 45 46 { 46 btBroadphasePair* pairPtr = colWorld->getPairCache()->getOverlappingPairArrayPtr(); 47 47 48 48 for (int i=0;i<colWorld->getPairCache()->getNumOverlappingPairs();i++) 49 49 { 50 btBroadphasePair* pairPtr = colWorld->getPairCache()->getOverlappingPairArrayPtr(); 50 51 const btBroadphasePair& collisionPair = pairPtr[i]; 51 52 btCollisionObject* colObj0 = (btCollisionObject*)collisionPair.m_pProxy0->m_clientObject; … … 186 187 } 187 188 188 assert((colObj0->getIslandTag() == islandId) || (colObj0->getIslandTag() == -1));189 btAssert((colObj0->getIslandTag() == islandId) || (colObj0->getIslandTag() == -1)); 189 190 if (colObj0->getIslandTag() == islandId) 190 191 { … … 213 214 } 214 215 215 assert((colObj0->getIslandTag() == islandId) || (colObj0->getIslandTag() == -1));216 btAssert((colObj0->getIslandTag() == islandId) || (colObj0->getIslandTag() == -1)); 216 217 217 218 if (colObj0->getIslandTag() == islandId) … … 234 235 } 235 236 236 assert((colObj0->getIslandTag() == islandId) || (colObj0->getIslandTag() == -1));237 btAssert((colObj0->getIslandTag() == islandId) || (colObj0->getIslandTag() == -1)); 237 238 238 239 if (colObj0->getIslandTag() == islandId) … … 252 253 int maxNumManifolds = dispatcher->getNumManifolds(); 253 254 254 #define SPLIT_ISLANDS 1255 #ifdef SPLIT_ISLANDS256 257 258 #endif //SPLIT_ISLANDS255 //#define SPLIT_ISLANDS 1 256 //#ifdef SPLIT_ISLANDS 257 258 259 //#endif //SPLIT_ISLANDS 259 260 260 261 … … 280 281 colObj0->activate(); 281 282 } 282 #ifdef SPLIT_ISLANDS 283 // //filtering for response 284 if (dispatcher->needsResponse(colObj0,colObj1)) 285 m_islandmanifold.push_back(manifold); 286 #endif //SPLIT_ISLANDS 283 if(m_splitIslands) 284 { 285 //filtering for response 286 if (dispatcher->needsResponse(colObj0,colObj1)) 287 m_islandmanifold.push_back(manifold); 288 } 287 289 } 288 290 } … … 304 306 BT_PROFILE("processIslands"); 305 307 306 #ifndef SPLIT_ISLANDS 307 btPersistentManifold** manifold = dispatcher->getInternalManifoldPointer(); 308 309 callback->ProcessIsland(&collisionObjects[0],collisionObjects.size(),manifold,maxNumManifolds, -1); 310 #else 311 // Sort manifolds, based on islands 312 // Sort the vector using predicate and std::sort 313 //std::sort(islandmanifold.begin(), islandmanifold.end(), btPersistentManifoldSortPredicate); 314 315 int numManifolds = int (m_islandmanifold.size()); 316 317 //we should do radix sort, it it much faster (O(n) instead of O (n log2(n)) 318 m_islandmanifold.quickSort(btPersistentManifoldSortPredicate()); 319 320 //now process all active islands (sets of manifolds for now) 321 322 int startManifoldIndex = 0; 323 int endManifoldIndex = 1; 324 325 //int islandId; 326 327 328 329 // printf("Start Islands\n"); 330 331 //traverse the simulation islands, and call the solver, unless all objects are sleeping/deactivated 332 for ( startIslandIndex=0;startIslandIndex<numElem;startIslandIndex = endIslandIndex) 333 { 334 int islandId = getUnionFind().getElement(startIslandIndex).m_id; 335 336 337 bool islandSleeping = false; 338 339 for (endIslandIndex = startIslandIndex;(endIslandIndex<numElem) && (getUnionFind().getElement(endIslandIndex).m_id == islandId);endIslandIndex++) 340 { 341 int i = getUnionFind().getElement(endIslandIndex).m_sz; 342 btCollisionObject* colObj0 = collisionObjects[i]; 343 m_islandBodies.push_back(colObj0); 344 if (!colObj0->isActive()) 345 islandSleeping = true; 346 } 347 348 349 //find the accompanying contact manifold for this islandId 350 int numIslandManifolds = 0; 351 btPersistentManifold** startManifold = 0; 352 353 if (startManifoldIndex<numManifolds) 354 { 355 int curIslandId = getIslandId(m_islandmanifold[startManifoldIndex]); 356 if (curIslandId == islandId) 357 { 358 startManifold = &m_islandmanifold[startManifoldIndex]; 308 if(!m_splitIslands) 309 { 310 btPersistentManifold** manifold = dispatcher->getInternalManifoldPointer(); 311 int maxNumManifolds = dispatcher->getNumManifolds(); 312 callback->ProcessIsland(&collisionObjects[0],collisionObjects.size(),manifold,maxNumManifolds, -1); 313 } 314 else 315 { 316 // Sort manifolds, based on islands 317 // Sort the vector using predicate and std::sort 318 //std::sort(islandmanifold.begin(), islandmanifold.end(), btPersistentManifoldSortPredicate); 319 320 int numManifolds = int (m_islandmanifold.size()); 321 322 //we should do radix sort, it it much faster (O(n) instead of O (n log2(n)) 323 m_islandmanifold.quickSort(btPersistentManifoldSortPredicate()); 324 325 //now process all active islands (sets of manifolds for now) 326 327 int startManifoldIndex = 0; 328 int endManifoldIndex = 1; 329 330 //int islandId; 331 332 333 334 // printf("Start Islands\n"); 335 336 //traverse the simulation islands, and call the solver, unless all objects are sleeping/deactivated 337 for ( startIslandIndex=0;startIslandIndex<numElem;startIslandIndex = endIslandIndex) 338 { 339 int islandId = getUnionFind().getElement(startIslandIndex).m_id; 340 341 342 bool islandSleeping = false; 343 344 for (endIslandIndex = startIslandIndex;(endIslandIndex<numElem) && (getUnionFind().getElement(endIslandIndex).m_id == islandId);endIslandIndex++) 345 { 346 int i = getUnionFind().getElement(endIslandIndex).m_sz; 347 btCollisionObject* colObj0 = collisionObjects[i]; 348 m_islandBodies.push_back(colObj0); 349 if (!colObj0->isActive()) 350 islandSleeping = true; 351 } 352 353 354 //find the accompanying contact manifold for this islandId 355 int numIslandManifolds = 0; 356 btPersistentManifold** startManifold = 0; 357 358 if (startManifoldIndex<numManifolds) 359 { 360 int curIslandId = getIslandId(m_islandmanifold[startManifoldIndex]); 361 if (curIslandId == islandId) 362 { 363 startManifold = &m_islandmanifold[startManifoldIndex]; 364 365 for (endManifoldIndex = startManifoldIndex+1;(endManifoldIndex<numManifolds) && (islandId == getIslandId(m_islandmanifold[endManifoldIndex]));endManifoldIndex++) 366 { 367 368 } 369 /// Process the actual simulation, only if not sleeping/deactivated 370 numIslandManifolds = endManifoldIndex-startManifoldIndex; 371 } 372 373 } 374 375 if (!islandSleeping) 376 { 377 callback->ProcessIsland(&m_islandBodies[0],m_islandBodies.size(),startManifold,numIslandManifolds, islandId); 378 // printf("Island callback of size:%d bodies, %d manifolds\n",islandBodies.size(),numIslandManifolds); 379 } 359 380 360 for (endManifoldIndex = startManifoldIndex+1;(endManifoldIndex<numManifolds) && (islandId == getIslandId(m_islandmanifold[endManifoldIndex]));endManifoldIndex++) 361 { 362 363 } 364 /// Process the actual simulation, only if not sleeping/deactivated 365 numIslandManifolds = endManifoldIndex-startManifoldIndex; 366 } 367 368 } 369 370 if (!islandSleeping) 371 { 372 callback->ProcessIsland(&m_islandBodies[0],m_islandBodies.size(),startManifold,numIslandManifolds, islandId); 373 // printf("Island callback of size:%d bodies, %d manifolds\n",islandBodies.size(),numIslandManifolds); 374 } 375 376 if (numIslandManifolds) 377 { 378 startManifoldIndex = endManifoldIndex; 379 } 380 381 m_islandBodies.resize(0); 382 } 383 #endif //SPLIT_ISLANDS 384 385 386 } 381 if (numIslandManifolds) 382 { 383 startManifoldIndex = endManifoldIndex; 384 } 385 386 m_islandBodies.resize(0); 387 } 388 } // else if(!splitIslands) 389 390 } -
code/trunk/src/bullet/BulletCollision/CollisionDispatch/btSimulationIslandManager.h
r2662 r2882 36 36 btAlignedObjectArray<btCollisionObject* > m_islandBodies; 37 37 38 bool m_splitIslands; 38 39 39 40 public: … … 66 67 void buildIslands(btDispatcher* dispatcher,btCollisionWorld* colWorld); 67 68 69 bool getSplitIslands() 70 { 71 return m_splitIslands; 72 } 73 void setSplitIslands(bool doSplitIslands) 74 { 75 m_splitIslands = doSplitIslands; 76 } 77 68 78 }; 69 79 -
code/trunk/src/bullet/BulletCollision/CollisionDispatch/btSphereSphereCollisionAlgorithm.cpp
r2662 r2882 79 79 80 80 ///point on A (worldspace) 81 btVector3 pos0 = col0->getWorldTransform().getOrigin() - radius0 * normalOnSurfaceB;81 ///btVector3 pos0 = col0->getWorldTransform().getOrigin() - radius0 * normalOnSurfaceB; 82 82 ///point on B (worldspace) 83 83 btVector3 pos1 = col1->getWorldTransform().getOrigin() + radius1* normalOnSurfaceB; -
code/trunk/src/bullet/BulletCollision/CollisionDispatch/btUnionFind.cpp
r2662 r2882 15 15 16 16 #include "btUnionFind.h" 17 #include <assert.h>18 19 17 20 18 -
code/trunk/src/bullet/BulletCollision/CollisionDispatch/btUnionFind.h
r2662 r2882 99 99 int find(int x) 100 100 { 101 // assert(x < m_N);102 // assert(x >= 0);101 //btAssert(x < m_N); 102 //btAssert(x >= 0); 103 103 104 104 while (x != m_elements[x].m_id) … … 111 111 #endif // 112 112 x = m_elements[x].m_id; 113 // assert(x < m_N);114 // assert(x >= 0);113 //btAssert(x < m_N); 114 //btAssert(x >= 0); 115 115 116 116 } -
code/trunk/src/bullet/BulletCollision/CollisionShapes/btBoxShape.h
r2662 r2882 162 162 { 163 163 case 0: 164 plane.setValue(btScalar(1.),btScalar(0.),btScalar(0.)); 165 plane[3] = -halfExtents.x(); 164 plane.setValue(btScalar(1.),btScalar(0.),btScalar(0.),-halfExtents.x()); 166 165 break; 167 166 case 1: 168 plane.setValue(btScalar(-1.),btScalar(0.),btScalar(0.)); 169 plane[3] = -halfExtents.x(); 167 plane.setValue(btScalar(-1.),btScalar(0.),btScalar(0.),-halfExtents.x()); 170 168 break; 171 169 case 2: 172 plane.setValue(btScalar(0.),btScalar(1.),btScalar(0.)); 173 plane[3] = -halfExtents.y(); 170 plane.setValue(btScalar(0.),btScalar(1.),btScalar(0.),-halfExtents.y()); 174 171 break; 175 172 case 3: 176 plane.setValue(btScalar(0.),btScalar(-1.),btScalar(0.)); 177 plane[3] = -halfExtents.y(); 173 plane.setValue(btScalar(0.),btScalar(-1.),btScalar(0.),-halfExtents.y()); 178 174 break; 179 175 case 4: 180 plane.setValue(btScalar(0.),btScalar(0.),btScalar(1.)); 181 plane[3] = -halfExtents.z(); 176 plane.setValue(btScalar(0.),btScalar(0.),btScalar(1.),-halfExtents.z()); 182 177 break; 183 178 case 5: 184 plane.setValue(btScalar(0.),btScalar(0.),btScalar(-1.)); 185 plane[3] = -halfExtents.z(); 179 plane.setValue(btScalar(0.),btScalar(0.),btScalar(-1.),-halfExtents.z()); 186 180 break; 187 181 default: 188 assert(0);182 btAssert(0); 189 183 } 190 184 } … … 313 307 break; 314 308 default: 315 assert(0);309 btAssert(0); 316 310 } 317 311 } -
code/trunk/src/bullet/BulletCollision/CollisionShapes/btCollisionShape.cpp
r2662 r2882 15 15 16 16 #include "BulletCollision/CollisionShapes/btCollisionShape.h" 17 18 19 btScalar gContactThresholdFactor=btScalar(0.02); 17 20 18 21 … … 45 48 btScalar btCollisionShape::getContactBreakingThreshold() const 46 49 { 47 ///@todo make this 0.1 configurable 48 return getAngularMotionDisc() * btScalar(0.1); 50 return getAngularMotionDisc() * gContactThresholdFactor; 49 51 } 50 52 btScalar btCollisionShape::getAngularMotionDisc() const -
code/trunk/src/bullet/BulletCollision/CollisionShapes/btCompoundShape.cpp
r2662 r2882 23 23 m_collisionMargin(btScalar(0.)), 24 24 m_localScaling(btScalar(1.),btScalar(1.),btScalar(1.)), 25 m_dynamicAabbTree(0) 25 m_dynamicAabbTree(0), 26 m_updateRevision(1) 26 27 { 27 28 m_shapeType = COMPOUND_SHAPE_PROXYTYPE; … … 47 48 void btCompoundShape::addChildShape(const btTransform& localTransform,btCollisionShape* shape) 48 49 { 50 m_updateRevision++; 49 51 //m_childTransforms.push_back(localTransform); 50 52 //m_childShapes.push_back(shape); … … 55 57 child.m_childMargin = shape->getMargin(); 56 58 57 m_children.push_back(child); 58 59 59 60 //extend the local aabbMin/aabbMax 60 61 btVector3 localAabbMin,localAabbMax; … … 75 76 { 76 77 const btDbvtVolume bounds=btDbvtVolume::FromMM(localAabbMin,localAabbMax); 77 int index = m_children.size() -1;78 int index = m_children.size(); 78 79 child.m_node = m_dynamicAabbTree->insert(bounds,(void*)index); 79 80 } 81 82 m_children.push_back(child); 80 83 81 84 } … … 100 103 void btCompoundShape::removeChildShapeByIndex(int childShapeIndex) 101 104 { 105 m_updateRevision++; 102 106 btAssert(childShapeIndex >=0 && childShapeIndex < m_children.size()); 103 107 if (m_dynamicAabbTree) … … 114 118 void btCompoundShape::removeChildShape(btCollisionShape* shape) 115 119 { 120 m_updateRevision++; 116 121 // Find the children containing the shape specified, and remove those children. 117 122 //note: there might be multiple children using the same shape! … … 140 145 // Recalculate the local aabb 141 146 // Brute force, it iterates over all the shapes left. 147 142 148 m_localAabbMin = btVector3(btScalar(1e30),btScalar(1e30),btScalar(1e30)); 143 149 m_localAabbMax = btVector3(btScalar(-1e30),btScalar(-1e30),btScalar(-1e30)); … … 162 168 { 163 169 btVector3 localHalfExtents = btScalar(0.5)*(m_localAabbMax-m_localAabbMin); 170 btVector3 localCenter = btScalar(0.5)*(m_localAabbMax+m_localAabbMin); 171 172 //avoid an illegal AABB when there are no children 173 if (!m_children.size()) 174 { 175 localHalfExtents.setValue(0,0,0); 176 localCenter.setValue(0,0,0); 177 } 164 178 localHalfExtents += btVector3(getMargin(),getMargin(),getMargin()); 165 btVector3 localCenter = btScalar(0.5)*(m_localAabbMax+m_localAabbMin);179 166 180 167 181 btMatrix3x3 abs_b = trans.getBasis().absolute(); … … 174 188 aabbMin = center-extent; 175 189 aabbMax = center+extent; 176 190 177 191 } 178 192 -
code/trunk/src/bullet/BulletCollision/CollisionShapes/btCompoundShape.h
r2662 r2882 59 59 60 60 btDbvt* m_dynamicAabbTree; 61 62 ///increment m_updateRevision when adding/removing/replacing child shapes, so that some caches can be updated 63 int m_updateRevision; 61 64 62 65 public: … … 153 156 void calculatePrincipalAxisTransform(btScalar* masses, btTransform& principal, btVector3& inertia) const; 154 157 158 int getUpdateRevision() const 159 { 160 return m_updateRevision; 161 } 155 162 156 163 private: -
code/trunk/src/bullet/BulletCollision/CollisionShapes/btConeShape.cpp
r2662 r2882 61 61 break; 62 62 default: 63 assert(0);63 btAssert(0); 64 64 }; 65 65 } -
code/trunk/src/bullet/BulletCollision/CollisionShapes/btConvexHullShape.cpp
r2662 r2882 182 182 bool btConvexHullShape::isInside(const btVector3& ,btScalar ) const 183 183 { 184 assert(0);184 btAssert(0); 185 185 return false; 186 186 } -
code/trunk/src/bullet/BulletCollision/CollisionShapes/btConvexPointCloudShape.cpp
r2662 r2882 151 151 bool btConvexPointCloudShape::isInside(const btVector3& ,btScalar ) const 152 152 { 153 assert(0);153 btAssert(0); 154 154 return false; 155 155 } -
code/trunk/src/bullet/BulletCollision/CollisionShapes/btConvexShape.cpp
r2662 r2882 155 155 156 156 btCapsuleShape* capsuleShape = (btCapsuleShape*)this; 157 btVector3 halfExtents = capsuleShape->getImplicitShapeDimensions();158 157 btScalar halfHeight = capsuleShape->getHalfHeight(); 159 158 int capsuleUpAxis = capsuleShape->getUpAxis(); … … 302 301 { 303 302 btSphereShape* sphereShape = (btSphereShape*)this; 304 floatradius = sphereShape->getImplicitShapeDimensions().getX();// * convexShape->getLocalScaling().getX();305 floatmargin = radius + sphereShape->getMarginNonVirtual();303 btScalar radius = sphereShape->getImplicitShapeDimensions().getX();// * convexShape->getLocalScaling().getX(); 304 btScalar margin = radius + sphereShape->getMarginNonVirtual(); 306 305 const btVector3& center = t.getOrigin(); 307 306 btVector3 extent(margin,margin,margin); … … 315 314 { 316 315 btBoxShape* convexShape = (btBoxShape*)this; 317 floatmargin=convexShape->getMarginNonVirtual();316 btScalar margin=convexShape->getMarginNonVirtual(); 318 317 btVector3 halfExtents = convexShape->getImplicitShapeDimensions(); 319 318 halfExtents += btVector3(margin,margin,margin); -
code/trunk/src/bullet/BulletCollision/CollisionShapes/btHeightfieldTerrainShape.cpp
r2662 r2882 145 145 } 146 146 147 btScalar btHeightfieldTerrainShape::getHeightFieldValue(int x,int y) const 147 148 /// This returns the "raw" (user's initial) height, not the actual height. 149 /// The actual height needs to be adjusted to be relative to the center 150 /// of the heightfield's AABB. 151 btScalar 152 btHeightfieldTerrainShape::getRawHeightFieldValue(int x,int y) const 148 153 { 149 154 btScalar val = 0.f; … … 182 187 183 188 184 189 /// this returns the vertex in bullet-local coordinates 185 190 void btHeightfieldTerrainShape::getVertex(int x,int y,btVector3& vertex) const 186 191 { 187 188 192 btAssert(x>=0); 189 193 btAssert(y>=0); … … 191 195 btAssert(y<m_heightStickLength); 192 196 193 194 btScalar height = getHeightFieldValue(x,y); 197 btScalar height = getRawHeightFieldValue(x,y); 195 198 196 199 switch (m_upAxis) … … 199 202 { 200 203 vertex.setValue( 201 height ,204 height - m_localOrigin.getX(), 202 205 (-m_width/btScalar(2.0)) + x, 203 206 (-m_length/btScalar(2.0) ) + y … … 209 212 vertex.setValue( 210 213 (-m_width/btScalar(2.0)) + x, 211 height ,214 height - m_localOrigin.getY(), 212 215 (-m_length/btScalar(2.0)) + y 213 216 ); … … 219 222 (-m_width/btScalar(2.0)) + x, 220 223 (-m_length/btScalar(2.0)) + y, 221 height 224 height - m_localOrigin.getZ() 222 225 ); 223 226 break; … … 231 234 232 235 vertex*=m_localScaling; 233 234 236 } 235 237 … … 239 241 getQuantized 240 242 ( 241 floatx243 btScalar x 242 244 ) 243 245 { -
code/trunk/src/bullet/BulletCollision/CollisionShapes/btHeightfieldTerrainShape.h
r2662 r2882 30 30 center (as determined by width and length and height, with each 31 31 axis multiplied by the localScaling). 32 33 \b NOTE: be careful with coordinates. If you have a heightfield with a local 34 min height of -100m, and a max height of +500m, you may be tempted to place it 35 at the origin (0,0) and expect the heights in world coordinates to be 36 -100 to +500 meters. 37 Actually, the heights will be -300 to +300m, because bullet will re-center 38 the heightfield based on its AABB (which is determined by the min/max 39 heights). So keep in mind that once you create a btHeightfieldTerrainShape 40 object, the heights will be adjusted relative to the center of the AABB. This 41 is different to the behavior of many rendering engines, but is useful for 42 physics engines. 32 43 33 44 Most (but not all) rendering and heightfield libraries assume upAxis = 1 … … 89 100 btVector3 m_localScaling; 90 101 91 virtual btScalar get HeightFieldValue(int x,int y) const;102 virtual btScalar getRawHeightFieldValue(int x,int y) const; 92 103 void quantizeWithClamp(int* out, const btVector3& point,int isMax) const; 93 104 void getVertex(int x,int y,btVector3& vertex) const; -
code/trunk/src/bullet/BulletCollision/CollisionShapes/btMinkowskiSumShape.cpp
r2662 r2882 29 29 btVector3 btMinkowskiSumShape::localGetSupportingVertexWithoutMargin(const btVector3& vec)const 30 30 { 31 btVector3 supVertexA = m_transA(m_shapeA->localGetSupportingVertexWithoutMargin( -vec*m_transA.getBasis()));32 btVector3 supVertexB = m_transB(m_shapeB->localGetSupportingVertexWithoutMargin( vec*m_transB.getBasis()));31 btVector3 supVertexA = m_transA(m_shapeA->localGetSupportingVertexWithoutMargin(vec*m_transA.getBasis())); 32 btVector3 supVertexB = m_transB(m_shapeB->localGetSupportingVertexWithoutMargin(-vec*m_transB.getBasis())); 33 33 return supVertexA - supVertexB; 34 34 } -
code/trunk/src/bullet/BulletCollision/CollisionShapes/btMultimaterialTriangleMeshShape.h
r2662 r2882 32 32 BT_DECLARE_ALIGNED_ALLOCATOR(); 33 33 34 btMultimaterialTriangleMeshShape(): btBvhTriangleMeshShape() { }34 btMultimaterialTriangleMeshShape(): btBvhTriangleMeshShape() {m_shapeType = MULTIMATERIAL_TRIANGLE_MESH_PROXYTYPE;} 35 35 btMultimaterialTriangleMeshShape(btStridingMeshInterface* meshInterface, bool useQuantizedAabbCompression, bool buildBvh = true): 36 36 btBvhTriangleMeshShape(meshInterface, useQuantizedAabbCompression, buildBvh) 37 37 { 38 m_shapeType = MULTIMATERIAL_TRIANGLE_MESH_PROXYTYPE; 39 38 40 btVector3 m_triangle[3]; 39 41 const unsigned char *vertexbase; … … 68 70 btBvhTriangleMeshShape(meshInterface, useQuantizedAabbCompression, bvhAabbMin, bvhAabbMax, buildBvh) 69 71 { 72 m_shapeType = MULTIMATERIAL_TRIANGLE_MESH_PROXYTYPE; 73 70 74 btVector3 m_triangle[3]; 71 75 const unsigned char *vertexbase; … … 108 112 */ 109 113 } 110 virtual int getShapeType() const111 {112 return MULTIMATERIAL_TRIANGLE_MESH_PROXYTYPE;113 }114 115 114 //debugging 116 115 virtual const char* getName()const {return "MULTIMATERIALTRIANGLEMESH";} -
code/trunk/src/bullet/BulletCollision/CollisionShapes/btSphereShape.h
r2662 r2882 48 48 btScalar getRadius() const { return m_implicitShapeDimensions.getX() * m_localScaling.getX();} 49 49 50 void setUnscaledRadius(btScalar radius) 51 { 52 m_implicitShapeDimensions.setX(radius); 53 btConvexInternalShape::setMargin(radius); 54 } 55 50 56 //debugging 51 57 virtual const char* getName()const {return "SPHERE";} -
code/trunk/src/bullet/BulletCollision/CollisionShapes/btTriangleIndexVertexArray.cpp
r2662 r2882 83 83 } 84 84 85 void btTriangleIndexVertexArray::setPremadeAabb(const btVector3& aabbMin, const btVector3& aabbMax ) 85 86 void btTriangleIndexVertexArray::setPremadeAabb(const btVector3& aabbMin, const btVector3& aabbMax ) const 86 87 { 87 88 m_aabbMin = aabbMin; … … 96 97 } 97 98 99 -
code/trunk/src/bullet/BulletCollision/CollisionShapes/btTriangleIndexVertexArray.h
r2662 r2882 53 53 IndexedMeshArray m_indexedMeshes; 54 54 int m_pad[2]; 55 int m_hasAabb; // using int instead of bool to maintain alignment56 btVector3 m_aabbMin;57 btVector3 m_aabbMax;55 mutable int m_hasAabb; // using int instead of bool to maintain alignment 56 mutable btVector3 m_aabbMin; 57 mutable btVector3 m_aabbMax; 58 58 59 59 public: … … 107 107 108 108 virtual bool hasPremadeAabb() const; 109 virtual void setPremadeAabb(const btVector3& aabbMin, const btVector3& aabbMax ) ;109 virtual void setPremadeAabb(const btVector3& aabbMin, const btVector3& aabbMax ) const; 110 110 virtual void getPremadeAabb(btVector3* aabbMin, btVector3* aabbMax ) const; 111 111 -
code/trunk/src/bullet/BulletCollision/CollisionShapes/btTriangleIndexVertexMaterialArray.cpp
r2662 r2882 1 1 2 /* 2 3 Bullet Continuous Collision Detection and Physics Library -
code/trunk/src/bullet/BulletCollision/CollisionShapes/btTriangleMesh.cpp
r2662 r2882 36 36 { 37 37 m_indexedMeshes[0].m_numTriangles = m_32bitIndices.size()/3; 38 m_indexedMeshes[0].m_triangleIndexBase = (unsigned char*) &m_32bitIndices[0];38 m_indexedMeshes[0].m_triangleIndexBase = 0; 39 39 m_indexedMeshes[0].m_indexType = PHY_INTEGER; 40 40 m_indexedMeshes[0].m_triangleIndexStride = 3*sizeof(int); … … 42 42 { 43 43 m_indexedMeshes[0].m_numTriangles = m_16bitIndices.size()/3; 44 m_indexedMeshes[0].m_triangleIndexBase = (unsigned char*) &m_16bitIndices[0];44 m_indexedMeshes[0].m_triangleIndexBase = 0; 45 45 m_indexedMeshes[0].m_indexType = PHY_SHORT; 46 46 m_indexedMeshes[0].m_triangleIndexStride = 3*sizeof(short int); … … 50 50 { 51 51 m_indexedMeshes[0].m_numVertices = m_4componentVertices.size(); 52 m_indexedMeshes[0].m_vertexBase = (unsigned char*)&m_4componentVertices[0];52 m_indexedMeshes[0].m_vertexBase = 0; 53 53 m_indexedMeshes[0].m_vertexStride = sizeof(btVector3); 54 54 } else 55 55 { 56 56 m_indexedMeshes[0].m_numVertices = m_3componentVertices.size()/3; 57 m_indexedMeshes[0].m_vertexBase = (unsigned char*)&m_3componentVertices[0];57 m_indexedMeshes[0].m_vertexBase = 0; 58 58 m_indexedMeshes[0].m_vertexStride = 3*sizeof(btScalar); 59 59 } … … 112 112 } 113 113 } 114 m_3componentVertices.push_back( vertex.getX());115 m_3componentVertices.push_back( vertex.getY());116 m_3componentVertices.push_back( vertex.getZ());114 m_3componentVertices.push_back((float)vertex.getX()); 115 m_3componentVertices.push_back((float)vertex.getY()); 116 m_3componentVertices.push_back((float)vertex.getZ()); 117 117 m_indexedMeshes[0].m_numVertices++; 118 118 m_indexedMeshes[0].m_vertexBase = (unsigned char*)&m_3componentVertices[0]; -
code/trunk/src/bullet/BulletCollision/CollisionShapes/btTriangleMeshShape.h
r2662 r2882 41 41 virtual btVector3 localGetSupportingVertexWithoutMargin(const btVector3& vec)const 42 42 { 43 assert(0);43 btAssert(0); 44 44 return localGetSupportingVertex(vec); 45 45 } -
code/trunk/src/bullet/BulletCollision/Gimpact/btGImpactBvh.cpp
r2662 r2882 151 151 } 152 152 153 bool unbal = (splitIndex==startIndex) || (splitIndex == (endIndex)); 154 btAssert(!unbal); 153 btAssert(!((splitIndex==startIndex) || (splitIndex == (endIndex)))); 155 154 156 155 return splitIndex; -
code/trunk/src/bullet/BulletCollision/Gimpact/btGImpactQuantizedBvh.cpp
r2662 r2882 172 172 } 173 173 174 bool unbal = (splitIndex==startIndex) || (splitIndex == (endIndex)); 175 btAssert(!unbal); 174 btAssert(!((splitIndex==startIndex) || (splitIndex == (endIndex)))); 176 175 177 176 return splitIndex; -
code/trunk/src/bullet/BulletCollision/Gimpact/btGImpactShape.h
r2662 r2882 882 882 class btGImpactMeshShape : public btGImpactShapeInterface 883 883 { 884 btStridingMeshInterface* m_meshInterface; 885 884 886 protected: 885 887 btAlignedObjectArray<btGImpactMeshShapePart*> m_mesh_parts; … … 908 910 btGImpactMeshShape(btStridingMeshInterface * meshInterface) 909 911 { 912 m_meshInterface = meshInterface; 910 913 buildMeshParts(meshInterface); 911 914 } … … 923 926 924 927 928 btStridingMeshInterface* getMeshInterface() 929 { 930 return m_meshInterface; 931 } 932 933 const btStridingMeshInterface* getMeshInterface() const 934 { 935 return m_meshInterface; 936 } 925 937 926 938 int getMeshPartCount() const … … 1034 1046 1035 1047 //! call when reading child shapes 1036 virtual void lockChildShapes() 1037 { 1038 btAssert(0); 1039 } 1040 1041 virtual void unlockChildShapes() 1048 virtual void lockChildShapes() const 1049 { 1050 btAssert(0); 1051 } 1052 1053 virtual void unlockChildShapes() const 1042 1054 { 1043 1055 btAssert(0); -
code/trunk/src/bullet/BulletCollision/Gimpact/gim_box_set.cpp
r2662 r2882 111 111 } 112 112 113 bool unbal = (splitIndex==startIndex) || (splitIndex == (endIndex)); 114 btAssert(!unbal); 113 btAssert(!((splitIndex==startIndex) || (splitIndex == (endIndex)))); 115 114 116 115 return splitIndex; … … 181 180 } 182 181 182 -
code/trunk/src/bullet/BulletCollision/Gimpact/gim_math.h
r2662 r2882 108 108 #define GIM_CLAMP(number,minval,maxval) (number<minval?minval:(number>maxval?maxval:number)) 109 109 110 #define GIM_GREATER(x, y) fabsf(x) > (y)110 #define GIM_GREATER(x, y) btFabs(x) > (y) 111 111 112 112 ///Swap numbers -
code/trunk/src/bullet/BulletCollision/Gimpact/gim_tri_collision.h
r2662 r2882 276 276 else 277 277 { 278 floatsumuv;278 btScalar sumuv; 279 279 sumuv = u+v; 280 280 if(sumuv<-G_EPSILON) -
code/trunk/src/bullet/BulletCollision/NarrowPhaseCollision/btContinuousConvexCollision.cpp
r2662 r2882 136 136 //btScalar clippedDist = dist; 137 137 138 //don't report time of impact for motion away from the contact normal (or causes minor penetration) 139 if ((projectedLinearVelocity+ maxAngularProjectedVelocity)<=SIMD_EPSILON) 140 return false; 138 141 139 142 dLambda = dist / (projectedLinearVelocity+ maxAngularProjectedVelocity); … … 197 200 198 201 } 199 200 //don't report time of impact for motion away from the contact normal (or causes minor penetration) 202 201 203 if ((projectedLinearVelocity+ maxAngularProjectedVelocity)<=result.m_allowedPenetration)//SIMD_EPSILON) 202 204 return false; 203 205 204 206 result.m_fraction = lambda; 205 207 result.m_normal = n; -
code/trunk/src/bullet/BulletCollision/NarrowPhaseCollision/btGjkPairDetector.cpp
r2662 r2882 151 151 if ((delta > btScalar(0.0)) && (delta * delta > squaredDistance * input.m_maximumDistanceSquared)) 152 152 { 153 checkPenetration = false; 153 checkSimplex=true; 154 //checkPenetration = false; 154 155 break; 155 156 } -
code/trunk/src/bullet/BulletCollision/NarrowPhaseCollision/btManifoldPoint.h
r2662 r2882 113 113 } 114 114 115 ///this returns the most recent applied impulse, to satisfy contact constraints by the constraint solver 116 btScalar getAppliedImpulse() const 117 { 118 return m_appliedImpulse; 119 } 120 115 121 116 122 -
code/trunk/src/bullet/BulletCollision/NarrowPhaseCollision/btPersistentManifold.cpp
r2662 r2882 184 184 185 185 } 186 if (insertIndex<0) 187 insertIndex=0; 188 186 189 btAssert(m_pointCache[insertIndex].m_userPersistentData==0); 187 190 m_pointCache[insertIndex] = newPoint; -
code/trunk/src/bullet/BulletCollision/NarrowPhaseCollision/btPersistentManifold.h
r2662 r2882 56 56 57 57 btScalar m_contactBreakingThreshold; 58 btScalar m_contactProcessingThreshold; 58 59 59 60 … … 71 72 btPersistentManifold(); 72 73 73 btPersistentManifold(void* body0,void* body1,int , btScalar contactBreakingThreshold )74 btPersistentManifold(void* body0,void* body1,int , btScalar contactBreakingThreshold,btScalar contactProcessingThreshold) 74 75 : m_body0(body0),m_body1(body1),m_cachedPoints(0), 75 m_contactBreakingThreshold(contactBreakingThreshold) 76 m_contactBreakingThreshold(contactBreakingThreshold), 77 m_contactProcessingThreshold(contactProcessingThreshold) 76 78 { 77 79 … … 112 114 ///@todo: get this margin from the current physics / collision environment 113 115 btScalar getContactBreakingThreshold() const; 116 117 btScalar getContactProcessingThreshold() const 118 { 119 return m_contactProcessingThreshold; 120 } 114 121 115 122 int getCacheEntry(const btManifoldPoint& newPoint) const; -
code/trunk/src/bullet/BulletCollision/NarrowPhaseCollision/btRaycastCallback.cpp
r2662 r2882 24 24 #include "btRaycastCallback.h" 25 25 26 btTriangleRaycastCallback::btTriangleRaycastCallback(const btVector3& from,const btVector3& to )26 btTriangleRaycastCallback::btTriangleRaycastCallback(const btVector3& from,const btVector3& to, unsigned int flags) 27 27 : 28 28 m_from(from), 29 29 m_to(to), 30 //@BP Mod 31 m_flags(flags), 30 32 m_hitFraction(btScalar(1.)) 31 33 { … … 56 58 return ; // same sign 57 59 } 60 //@BP Mod - Backface filtering 61 if (((m_flags & kF_FilterBackfaces) != 0) && (dist_a > btScalar(0.0))) 62 { 63 // Backface, skip check 64 return; 65 } 58 66 59 67 const btScalar proj_length=dist_a-dist_b; … … 90 98 if ( (btScalar)(cp2.dot(triangleNormal)) >=edge_tolerance) 91 99 { 100 //@BP Mod 101 // Triangle normal isn't normalized 102 triangleNormal.normalize(); 92 103 93 if ( dist_a > 0 ) 104 //@BP Mod - Allow for unflipped normal when raycasting against backfaces 105 if (((m_flags & kF_KeepUnflippedNormal) != 0) || (dist_a <= btScalar(0.0))) 94 106 { 95 m_hitFraction = reportHit( triangleNormal,distance,partId,triangleIndex);107 m_hitFraction = reportHit(-triangleNormal,distance,partId,triangleIndex); 96 108 } 97 109 else 98 110 { 99 m_hitFraction = reportHit(-triangleNormal,distance,partId,triangleIndex);111 m_hitFraction = reportHit(triangleNormal,distance,partId,triangleIndex); 100 112 } 101 113 } -
code/trunk/src/bullet/BulletCollision/NarrowPhaseCollision/btRaycastCallback.h
r2662 r2882 30 30 btVector3 m_to; 31 31 32 //@BP Mod - allow backface filtering and unflipped normals 33 enum EFlags 34 { 35 kF_None = 0, 36 kF_FilterBackfaces = 1 << 0, 37 kF_KeepUnflippedNormal = 1 << 1, // Prevents returned face normal getting flipped when a ray hits a back-facing triangle 38 39 kF_Terminator = 0xFFFFFFFF 40 }; 41 unsigned int m_flags; 42 32 43 btScalar m_hitFraction; 33 44 34 btTriangleRaycastCallback(const btVector3& from,const btVector3& to );45 btTriangleRaycastCallback(const btVector3& from,const btVector3& to, unsigned int flags=0); 35 46 36 47 virtual void processTriangle(btVector3* triangle, int partId, int triangleIndex); -
code/trunk/src/bullet/BulletCollision/NarrowPhaseCollision/btVoronoiSimplexSolver.cpp
r2662 r2882 26 26 27 27 #include "btVoronoiSimplexSolver.h" 28 #include <assert.h>29 //#include <stdio.h>30 28 31 29 #define VERTA 0 … … 38 36 { 39 37 40 assert(m_numVertices>0);38 btAssert(m_numVertices>0); 41 39 m_numVertices--; 42 40 m_simplexVectorW[index] = m_simplexVectorW[m_numVertices];
Note: See TracChangeset
for help on using the changeset viewer.