ContactTestResultCallback: do not rely on col1 being the object tested against

Unsure why, but in some cases col0 and col1 are swapped.
This commit is contained in:
scrawl 2015-11-18 20:41:49 +01:00
parent 3453353091
commit 9fce428929

View file

@ -936,6 +936,13 @@ namespace MWPhysics
class ContactTestResultCallback : public btCollisionWorld::ContactResultCallback class ContactTestResultCallback : public btCollisionWorld::ContactResultCallback
{ {
public: public:
ContactTestResultCallback(const btCollisionObject* testedAgainst)
: mTestedAgainst(testedAgainst)
{
}
const btCollisionObject* mTestedAgainst;
std::vector<MWWorld::Ptr> mResult; std::vector<MWWorld::Ptr> mResult;
#if BT_BULLET_VERSION >= 281 #if BT_BULLET_VERSION >= 281
@ -944,11 +951,15 @@ namespace MWPhysics
const btCollisionObjectWrapper* col1Wrap,int partId1,int index1) const btCollisionObjectWrapper* col1Wrap,int partId1,int index1)
{ {
const btCollisionObject* collisionObject = col0Wrap->m_collisionObject; const btCollisionObject* collisionObject = col0Wrap->m_collisionObject;
if (collisionObject == mTestedAgainst)
collisionObject = col1Wrap->m_collisionObject;
#else #else
virtual btScalar addSingleResult(btManifoldPoint& cp, const btCollisionObject* col0, int partId0, int index0, virtual btScalar addSingleResult(btManifoldPoint& cp, const btCollisionObject* col0, int partId0, int index0,
const btCollisionObject* col1, int partId1, int index1) const btCollisionObject* col1, int partId1, int index1)
{ {
const btCollisionObject* collisionObject = col0; const btCollisionObject* collisionObject = col0;
if (collisionObject == mTestedAgainst)
collisionObject = col1;
#endif #endif
const PtrHolder* holder = static_cast<const PtrHolder*>(collisionObject->getUserPointer()); const PtrHolder* holder = static_cast<const PtrHolder*>(collisionObject->getUserPointer());
if (holder) if (holder)
@ -967,7 +978,7 @@ namespace MWPhysics
else else
return std::vector<MWWorld::Ptr>(); return std::vector<MWWorld::Ptr>();
ContactTestResultCallback resultCallback; ContactTestResultCallback resultCallback (me);
resultCallback.m_collisionFilterGroup = collisionGroup; resultCallback.m_collisionFilterGroup = collisionGroup;
resultCallback.m_collisionFilterMask = collisionMask; resultCallback.m_collisionFilterMask = collisionMask;
mCollisionWorld->contactTest(me, resultCallback); mCollisionWorld->contactTest(me, resultCallback);