From 8444d0e5c4e5c5ae68370733e59785828190fcf8 Mon Sep 17 00:00:00 2001 From: "erwin.coumans" Date: Sun, 13 Dec 2009 15:40:21 +0000 Subject: [PATCH] Fix shapekey swapping issue with triangle meshes, see http://code.google.com/p/bullet/issues/detail?id=316 Revert btHashKeyPtr and introduce btHashPtr (to avoid breaking API/COLLADA Converter), see http://code.google.com/p/bullet/issues/detail?id=318 Disable separating distance util (it just costs CPU cycles and is disabled by default in the API anyway) --- .../btConvexConcaveCollisionAlgorithm.cpp | 12 +- .../btConvexConvexAlgorithm.cpp | 12 +- .../btConvexConvexAlgorithm.h | 2 +- src/LinearMath/btHashMap.h | 127 ++++++++++-------- 4 files changed, 90 insertions(+), 63 deletions(-) diff --git a/src/BulletCollision/CollisionDispatch/btConvexConcaveCollisionAlgorithm.cpp b/src/BulletCollision/CollisionDispatch/btConvexConcaveCollisionAlgorithm.cpp index 6a556195b..1d0aeded9 100644 --- a/src/BulletCollision/CollisionDispatch/btConvexConcaveCollisionAlgorithm.cpp +++ b/src/BulletCollision/CollisionDispatch/btConvexConcaveCollisionAlgorithm.cpp @@ -121,12 +121,16 @@ void btConvexTriangleCallback::processTriangle(btVector3* triangle,int partId, i ob->internalSetTemporaryCollisionShape( &tm ); btCollisionAlgorithm* colAlgo = ci.m_dispatcher1->findAlgorithm(m_convexBody,m_triBody,m_manifoldPtr); - ///this should use the btDispatcher, so the actual registered algorithm is used - // btConvexConvexAlgorithm cvxcvxalgo(m_manifoldPtr,ci,m_convexBody,m_triBody); - m_resultOut->setShapeIdentifiersB(partId,triangleIndex); + if (m_resultOut->getBody0Internal() == m_triBody) + { + m_resultOut->setShapeIdentifiersA(partId,triangleIndex); + } + else + { + m_resultOut->setShapeIdentifiersB(partId,triangleIndex); + } -// cvxcvxalgo.processCollision(m_convexBody,m_triBody,*m_dispatchInfoPtr,m_resultOut); colAlgo->processCollision(m_convexBody,m_triBody,*m_dispatchInfoPtr,m_resultOut); colAlgo->~btCollisionAlgorithm(); ci.m_dispatcher1->freeCollisionAlgorithm(colAlgo); diff --git a/src/BulletCollision/CollisionDispatch/btConvexConvexAlgorithm.cpp b/src/BulletCollision/CollisionDispatch/btConvexConvexAlgorithm.cpp index 152506e58..b4fd4c6a6 100644 --- a/src/BulletCollision/CollisionDispatch/btConvexConvexAlgorithm.cpp +++ b/src/BulletCollision/CollisionDispatch/btConvexConvexAlgorithm.cpp @@ -332,7 +332,11 @@ void btConvexConvexAlgorithm ::processCollision (btCollisionObject* body0,btColl #ifdef USE_SEPDISTANCE_UTIL2 - m_sepDistance.updateSeparatingDistance(body0->getWorldTransform(),body1->getWorldTransform()); + if (dispatchInfo.m_useConvexConservativeDistanceUtil) + { + m_sepDistance.updateSeparatingDistance(body0->getWorldTransform(),body1->getWorldTransform()); + } + if (!dispatchInfo.m_useConvexConservativeDistanceUtil || m_sepDistance.getConservativeSeparatingDistance()<=0.f) #endif //USE_SEPDISTANCE_UTIL2 @@ -385,7 +389,7 @@ void btConvexConvexAlgorithm ::processCollision (btCollisionObject* body0,btColl //now perform 'm_numPerturbationIterations' collision queries with the perturbated collision objects //perform perturbation when more then 'm_minimumPointsPerturbationThreshold' points - if (resultOut->getPersistentManifold()->getNumContacts() < m_minimumPointsPerturbationThreshold) + if (m_numPerturbationIterations && resultOut->getPersistentManifold()->getNumContacts() < m_minimumPointsPerturbationThreshold) { int i; @@ -418,6 +422,8 @@ void btConvexConvexAlgorithm ::processCollision (btCollisionObject* body0,btColl for ( i=0;iSIMD_EPSILON) + { btQuaternion perturbeRot(v0,perturbeAngle); btScalar iterationAngle = i*(SIMD_2_PI/btScalar(m_numPerturbationIterations)); btQuaternion rotq(sepNormalWorldSpace,iterationAngle); @@ -441,7 +447,7 @@ void btConvexConvexAlgorithm ::processCollision (btCollisionObject* body0,btColl btPerturbedContactResult perturbedResultOut(resultOut,input.m_transformA,input.m_transformB,unPerturbedTransform,perturbeA,dispatchInfo.m_debugDraw); gjkPairDetector.getClosestPoints(input,perturbedResultOut,dispatchInfo.m_debugDraw); - + } } } diff --git a/src/BulletCollision/CollisionDispatch/btConvexConvexAlgorithm.h b/src/BulletCollision/CollisionDispatch/btConvexConvexAlgorithm.h index 4d10ffca7..d38aff686 100644 --- a/src/BulletCollision/CollisionDispatch/btConvexConvexAlgorithm.h +++ b/src/BulletCollision/CollisionDispatch/btConvexConvexAlgorithm.h @@ -32,7 +32,7 @@ class btConvexPenetrationDepthSolver; ///Either improve GJK for large size ratios (testing a 100 units versus a 0.1 unit object) or only enable the util ///for certain pairs that have a small size ratio -#define USE_SEPDISTANCE_UTIL2 1 +//#define USE_SEPDISTANCE_UTIL2 1 ///The convexConvexAlgorithm collision algorithm implements time of impact, convex closest points and penetration depth calculations between two convex objects. ///Multiple contact points are calculated by perturbing the orientation of the smallest object orthogonal to the separating normal. diff --git a/src/LinearMath/btHashMap.h b/src/LinearMath/btHashMap.h index 8491fd234..68eab4112 100644 --- a/src/LinearMath/btHashMap.h +++ b/src/LinearMath/btHashMap.h @@ -58,50 +58,12 @@ struct btHashString const int BT_HASH_NULL=0xffffffff; -template -class btHashKey -{ - int m_uid; -public: - - btHashKey(int uid) - :m_uid(uid) - { - } - - int getUid1() const - { - return m_uid; - } - - bool equals(const btHashKey& other) const - { - return getUid1() == other.getUid1(); - } - //to our success - SIMD_FORCE_INLINE unsigned int getHash()const - { - int key = m_uid; - // Thomas Wang's hash - key += ~(key << 15); - key ^= (key >> 10); - key += (key << 3); - key ^= (key >> 6); - key += ~(key << 11); - key ^= (key >> 16); - return key; - } - - -}; class btHashInt { int m_uid; public: - - btHashInt(int uid) - :m_uid(uid) + btHashInt(int uid) :m_uid(uid) { } @@ -119,22 +81,19 @@ public: { int key = m_uid; // Thomas Wang's hash - key += ~(key << 15); - key ^= (key >> 10); - key += (key << 3); - key ^= (key >> 6); - key += ~(key << 11); - key ^= (key >> 16); + key += ~(key << 15); key ^= (key >> 10); key += (key << 3); key ^= (key >> 6); key += ~(key << 11); key ^= (key >> 16); return key; } }; -class btHashKeyPtr + + +class btHashPtr { void* m_pointer; public: - btHashKeyPtr(void* ptr) + btHashPtr(void* ptr) :m_pointer(ptr) { } @@ -144,7 +103,7 @@ public: return m_pointer; } - bool equals(const btHashKeyPtr& other) const + bool equals(const btHashPtr& other) const { return getPointer() == other.getPointer(); } @@ -158,19 +117,77 @@ public: int key = VOID_IS_8? intPtr[0]+intPtr[1] : intPtr[0]; // Thomas Wang's hash - key += ~(key << 15); - key ^= (key >> 10); - key += (key << 3); - key ^= (key >> 6); - key += ~(key << 11); - key ^= (key >> 16); - + key += ~(key << 15); key ^= (key >> 10); key += (key << 3); key ^= (key >> 6); key += ~(key << 11); key ^= (key >> 16); return key; } }; + +template +class btHashKeyPtr +{ + int m_uid; +public: + + btHashKeyPtr(int uid) :m_uid(uid) + { + } + + int getUid1() const + { + return m_uid; + } + + bool equals(const btHashKeyPtr& other) const + { + return getUid1() == other.getUid1(); + } + + //to our success + SIMD_FORCE_INLINE unsigned int getHash()const + { + int key = m_uid; + // Thomas Wang's hash + key += ~(key << 15); key ^= (key >> 10); key += (key << 3); key ^= (key >> 6); key += ~(key << 11); key ^= (key >> 16); + return key; + } + + +}; + + +template +class btHashKey +{ + int m_uid; +public: + + btHashKey(int uid) :m_uid(uid) + { + } + + int getUid1() const + { + return m_uid; + } + + bool equals(const btHashKey& other) const + { + return getUid1() == other.getUid1(); + } + //to our success + SIMD_FORCE_INLINE unsigned int getHash()const + { + int key = m_uid; + // Thomas Wang's hash + key += ~(key << 15); key ^= (key >> 10); key += (key << 3); key ^= (key >> 6); key += ~(key << 11); key ^= (key >> 16); + return key; + } +}; + + ///The btHashMap template class implements a generic and lightweight hashmap. ///A basic sample of how to use btHashMap is located in Demos\BasicDemo\main.cpp template