Added a gCompoundChildShapePairCallback to filter (enable/disable) child shape collisions for a btCompoundShape.

Thanks to Rich McDaniel for the patch.
See MyCompoundChildShapeCallback in Demos/ConvexDecompositionDemo/ConvexDecompositionDemo.cpp for usage.
This commit is contained in:
erwin.coumans@gmail.com
2013-04-02 02:01:43 +00:00
parent 1f4f8c7e05
commit e8c2475c95
4 changed files with 57 additions and 4 deletions

View File

@@ -46,9 +46,12 @@ GLDebugDrawer gDebugDrawer;
#include "../../Extras/BulletMultiThreaded/SpuNarrowPhaseCollisionTask/SpuGatheringCollisionTask.h" #include "../../Extras/BulletMultiThreaded/SpuNarrowPhaseCollisionTask/SpuGatheringCollisionTask.h"
#endif//USE_PARALLEL_DISPATCHER #endif//USE_PARALLEL_DISPATCHER
#include "BulletCollision/CollisionDispatch/btCompoundCollisionAlgorithm.h"//for the callback
bool MyCompoundChildShapeCallback(const btCollisionShape* pShape0, const btCollisionShape* pShape1)
{
return true;
}
#include "GLDebugFont.h" #include "GLDebugFont.h"
#include <stdio.h> //printf debugging #include <stdio.h> //printf debugging
@@ -80,6 +83,7 @@ void ConvexDecompositionDemo::initPhysics()
///MyContactCallback is just an example to show how to get access to the child shape that collided ///MyContactCallback is just an example to show how to get access to the child shape that collided
bool MyContactCallback ( bool MyContactCallback (
btManifoldPoint& cp, btManifoldPoint& cp,
@@ -113,6 +117,7 @@ void ConvexDecompositionDemo::setupEmptyDynamicsWorld()
{ {
m_collisionConfiguration = new btDefaultCollisionConfiguration(); m_collisionConfiguration = new btDefaultCollisionConfiguration();
#ifdef USE_PARALLEL_DISPATCHER #ifdef USE_PARALLEL_DISPATCHER
#ifdef USE_WIN32_THREADING #ifdef USE_WIN32_THREADING
@@ -135,6 +140,7 @@ m_collisionConfiguration = new btDefaultCollisionConfiguration();
m_dispatcher = new btCollisionDispatcher(m_collisionConfiguration); m_dispatcher = new btCollisionDispatcher(m_collisionConfiguration);
#endif//USE_PARALLEL_DISPATCHER #endif//USE_PARALLEL_DISPATCHER
gCompoundChildShapePairCallback = MyCompoundChildShapeCallback;
convexDecompositionObjectOffset.setValue(10,0,0); convexDecompositionObjectOffset.setValue(10,0,0);
@@ -156,8 +162,6 @@ m_collisionConfiguration = new btDefaultCollisionConfiguration();
void ConvexDecompositionDemo::initPhysics(const char* filename) void ConvexDecompositionDemo::initPhysics(const char* filename)
{ {
sEnableSAT = !sEnableSAT;
gContactAddedCallback = &MyContactCallback; gContactAddedCallback = &MyContactCallback;
setupEmptyDynamicsWorld(); setupEmptyDynamicsWorld();
@@ -754,3 +758,22 @@ void ConvexDecompositionDemo::clientResetScene()
exitPhysics(); exitPhysics();
initPhysics("file.obj"); initPhysics("file.obj");
} }
void ConvexDecompositionDemo::keyboardCallback(unsigned char key, int x, int y)
{
if (key=='S')
{
sEnableSAT= !sEnableSAT;
if (sEnableSAT)
{
printf("SAT enabled after the next restart of the demo\n");
} else
{
printf("SAT disabled after the next restart of the demo\n");
}
} else
{
PlatformDemoApplication::keyboardCallback(key,x,y);
}
}

View File

@@ -75,6 +75,8 @@ public:
virtual void displayCallback(); virtual void displayCallback();
virtual void keyboardCallback(unsigned char key, int x, int y);
static DemoApplication* Create() static DemoApplication* Create()
{ {
ConvexDecompositionDemo* demo = new ConvexDecompositionDemo(); ConvexDecompositionDemo* demo = new ConvexDecompositionDemo();

View File

@@ -11,6 +11,9 @@ subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution. 3. This notice may not be removed or altered from any source distribution.
VERSION alterations
2013-Mar-21: Rich McDaniel - Added callback function to eliminate collisions based on shape testing
*/ */
#include "BulletCollision/CollisionDispatch/btCompoundCollisionAlgorithm.h" #include "BulletCollision/CollisionDispatch/btCompoundCollisionAlgorithm.h"
@@ -22,6 +25,8 @@ subject to the following restrictions:
#include "btManifoldResult.h" #include "btManifoldResult.h"
#include "BulletCollision/CollisionDispatch/btCollisionObjectWrapper.h" #include "BulletCollision/CollisionDispatch/btCollisionObjectWrapper.h"
btShapePairCallback gCompoundChildShapePairCallback = 0;
btCompoundCollisionAlgorithm::btCompoundCollisionAlgorithm( const btCollisionAlgorithmConstructionInfo& ci,const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap,bool isSwapped) btCompoundCollisionAlgorithm::btCompoundCollisionAlgorithm( const btCollisionAlgorithmConstructionInfo& ci,const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap,bool isSwapped)
:btActivatingCollisionAlgorithm(ci,body0Wrap,body1Wrap), :btActivatingCollisionAlgorithm(ci,body0Wrap,body1Wrap),
m_isSwapped(isSwapped), m_isSwapped(isSwapped),
@@ -129,6 +134,12 @@ public:
childShape->getAabb(newChildWorldTrans,aabbMin0,aabbMax0); childShape->getAabb(newChildWorldTrans,aabbMin0,aabbMax0);
m_otherObjWrap->getCollisionShape()->getAabb(m_otherObjWrap->getWorldTransform(),aabbMin1,aabbMax1); m_otherObjWrap->getCollisionShape()->getAabb(m_otherObjWrap->getWorldTransform(),aabbMin1,aabbMax1);
if (gCompoundChildShapePairCallback)
{
if (!gCompoundChildShapePairCallback(m_otherObjWrap->getCollisionShape(), childShape))
return;
}
if (TestAabbAgainstAabb2(aabbMin0,aabbMax0,aabbMin1,aabbMax1)) if (TestAabbAgainstAabb2(aabbMin0,aabbMax0,aabbMin1,aabbMax1))
{ {

View File

@@ -11,6 +11,10 @@ subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution. 3. This notice may not be removed or altered from any source distribution.
VERSION alterations
2013-Mar-21: Rich McDaniel - Added accessor to child algorithms in btCompoundCollisionAlgorithm
2013-Mar-21: Rich McDaniel - Added callback function to eliminate collisions based on shape testing
*/ */
#ifndef BT_COMPOUND_COLLISION_ALGORITHM_H #ifndef BT_COMPOUND_COLLISION_ALGORITHM_H
@@ -28,6 +32,11 @@ class btDispatcher;
class btDispatcher; class btDispatcher;
class btCollisionObject; class btCollisionObject;
/* 2013-Mar-21 - Rich McDaniel */
class btCollisionShape;
typedef bool (*btShapePairCallback)(const btCollisionShape* pShape0, const btCollisionShape* pShape1);
extern btShapePairCallback gCompoundChildShapePairCallback;
/// btCompoundCollisionAlgorithm supports collision between CompoundCollisionShapes and other collision shapes /// btCompoundCollisionAlgorithm supports collision between CompoundCollisionShapes and other collision shapes
class btCompoundCollisionAlgorithm : public btActivatingCollisionAlgorithm class btCompoundCollisionAlgorithm : public btActivatingCollisionAlgorithm
{ {
@@ -37,6 +46,7 @@ class btCompoundCollisionAlgorithm : public btActivatingCollisionAlgorithm
class btPersistentManifold* m_sharedManifold; class btPersistentManifold* m_sharedManifold;
bool m_ownsManifold; bool m_ownsManifold;
int m_compoundShapeRevision;//to keep track of changes, so that childAlgorithm array can be updated int m_compoundShapeRevision;//to keep track of changes, so that childAlgorithm array can be updated
void removeChildAlgorithms(); void removeChildAlgorithms();
@@ -49,6 +59,12 @@ public:
virtual ~btCompoundCollisionAlgorithm(); virtual ~btCompoundCollisionAlgorithm();
btCollisionAlgorithm* getChildAlgorithm (int n) const
{
return m_childCollisionAlgorithms[n];
}
virtual void processCollision (const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut); virtual void processCollision (const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut);
btScalar calculateTimeOfImpact(btCollisionObject* body0,btCollisionObject* body1,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut); btScalar calculateTimeOfImpact(btCollisionObject* body0,btCollisionObject* body1,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut);
@@ -63,6 +79,7 @@ public:
} }
} }
struct CreateFunc :public btCollisionAlgorithmCreateFunc struct CreateFunc :public btCollisionAlgorithmCreateFunc
{ {
virtual btCollisionAlgorithm* CreateCollisionAlgorithm(btCollisionAlgorithmConstructionInfo& ci, const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap) virtual btCollisionAlgorithm* CreateCollisionAlgorithm(btCollisionAlgorithmConstructionInfo& ci, const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap)