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)
This commit is contained in:
erwin.coumans
2009-12-13 15:40:21 +00:00
parent 91f1e8117b
commit 8444d0e5c4
4 changed files with 90 additions and 63 deletions

View File

@@ -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);

View File

@@ -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;i<m_numPerturbationIterations;i++)
{
if (v0.length2()>SIMD_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);
}
}
}

View File

@@ -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.

View File

@@ -58,50 +58,12 @@ struct btHashString
const int BT_HASH_NULL=0xffffffff;
template <class Value>
class btHashKey
{
int m_uid;
public:
btHashKey(int uid)
:m_uid(uid)
{
}
int getUid1() const
{
return m_uid;
}
bool equals(const btHashKey<Value>& 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 Value>
class btHashKeyPtr
{
int m_uid;
public:
btHashKeyPtr(int uid) :m_uid(uid)
{
}
int getUid1() const
{
return m_uid;
}
bool equals(const btHashKeyPtr<Value>& 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 Value>
class btHashKey
{
int m_uid;
public:
btHashKey(int uid) :m_uid(uid)
{
}
int getUid1() const
{
return m_uid;
}
bool equals(const btHashKey<Value>& 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 <class Key, class Value>