Fix issues with btSortedOverlappingPairCache, both for btAxisSweep3 and btDbvtBroadphase.

This commit is contained in:
erwin.coumans
2009-02-09 22:57:52 +00:00
parent cf751f5493
commit 98436a85c3
5 changed files with 80 additions and 5 deletions

View File

@@ -54,6 +54,6 @@ int main(int argc,char** argv)
return glutmain(argc, argv,640,480,"Bullet Quake BSP Physics Viewer http://bullet.sourceforge.net",bspDemo);
return glutmain(argc, argv,640,480,"Bullet Quake BSP Physics Viewer http://bulletphysics.org",bspDemo);
}

View File

@@ -98,7 +98,7 @@ int main(int argc,char** argv)
colladaDemo->setCameraDistance(26.f);
return glutmain(argc, argv,640,480,"Bullet COLLADA Physics Viewer http://bullet.sourceforge.net",colladaDemo);
return glutmain(argc, argv,640,480,"Bullet COLLADA Physics Viewer http://bulletphysics.org",colladaDemo);
}
void ColladaDemo::initPhysics(const char* filename)

View File

@@ -278,7 +278,7 @@ void DemoApplication::keyboardCallback(unsigned char key, int x, int y)
m_lastKey = 0;
#ifndef BT_NO_PROFILE
if (key >= 0x31 && key < 0x37)
if (key >= 0x31 && key <= 0x39)
{
int child = key-0x31;
m_profileIterator->Enter_Child(child);
@@ -1248,6 +1248,7 @@ void DemoApplication::renderme()
updateCamera();
}
#include "BulletCollision/BroadphaseCollision/btAxisSweep3.h"
void DemoApplication::clientResetScene()
{
@@ -1290,6 +1291,8 @@ void DemoApplication::clientResetScene()
}
}
btAxisSweep3* sap = (btAxisSweep3*)m_dynamicsWorld->getBroadphase();
sap->resetPool();
/*
//quickly search some issue at a certain simulation frame, pressing space to reset
int fixed=18;

View File

@@ -229,8 +229,13 @@ class btBroadphasePairSortPredicate
bool operator() ( const btBroadphasePair& a, const btBroadphasePair& b )
{
return a.m_pProxy0->m_uniqueId > b.m_pProxy0->m_uniqueId ||
(a.m_pProxy0 == b.m_pProxy0 && a.m_pProxy1->m_uniqueId > b.m_pProxy1->m_uniqueId) ||
const int uidA0 = a.m_pProxy0 ? a.m_pProxy0->m_uniqueId : -1;
const int uidB0 = b.m_pProxy0 ? b.m_pProxy0->m_uniqueId : -1;
const int uidA1 = a.m_pProxy1 ? a.m_pProxy1->m_uniqueId : -1;
const int uidB1 = b.m_pProxy1 ? b.m_pProxy1->m_uniqueId : -1;
return uidA0 > uidB0 ||
(a.m_pProxy0 == b.m_pProxy0 && uidA1 > uidB1) ||
(a.m_pProxy0 == b.m_pProxy0 && a.m_pProxy1 == b.m_pProxy1 && a.m_algorithm > b.m_algorithm);
}
};

View File

@@ -341,6 +341,73 @@ void btDbvtBroadphase::calculateOverlappingPairs(btDispatcher* dispatcher)
m_clock.reset();
}
#endif
if (m_paircache->hasDeferredRemoval())
{
btBroadphasePairArray& overlappingPairArray = m_paircache->getOverlappingPairArray();
//perform a sort, to find duplicates and to sort 'invalid' pairs to the end
overlappingPairArray.quickSort(btBroadphasePairSortPredicate());
int invalidPair = 0;
int i;
btBroadphasePair previousPair;
previousPair.m_pProxy0 = 0;
previousPair.m_pProxy1 = 0;
previousPair.m_algorithm = 0;
for (i=0;i<overlappingPairArray.size();i++)
{
btBroadphasePair& pair = overlappingPairArray[i];
bool isDuplicate = (pair == previousPair);
previousPair = pair;
bool needsRemoval = false;
if (!isDuplicate)
{
btDbvtProxy* pa=(btDbvtProxy*)pair.m_pProxy0;
btDbvtProxy* pb=(btDbvtProxy*)pair.m_pProxy1;
bool hasOverlap = Intersect(pa->leaf->volume,pb->leaf->volume);
if (hasOverlap)
{
needsRemoval = false;//callback->processOverlap(pair);
} else
{
needsRemoval = true;
}
} else
{
//remove duplicate
needsRemoval = true;
//should have no algorithm
btAssert(!pair.m_algorithm);
}
if (needsRemoval)
{
m_paircache->cleanOverlappingPair(pair,dispatcher);
pair.m_pProxy0 = 0;
pair.m_pProxy1 = 0;
invalidPair++;
}
}
//perform a sort, to sort 'invalid' pairs to the end
overlappingPairArray.quickSort(btBroadphasePairSortPredicate());
overlappingPairArray.resize(overlappingPairArray.size() - invalidPair);
}
}
//