diff --git a/Demos/ConcaveDemo/ConcavePhysicsDemo.cpp b/Demos/ConcaveDemo/ConcavePhysicsDemo.cpp index 7a5842477..d87887c33 100644 --- a/Demos/ConcaveDemo/ConcavePhysicsDemo.cpp +++ b/Demos/ConcaveDemo/ConcavePhysicsDemo.cpp @@ -20,6 +20,12 @@ subject to the following restrictions: #include "GL_ShapeDrawer.h" #include "GlutStuff.h" +//#define USE_PARALLEL_DISPATCHER 1 +#ifdef USE_PARALLEL_DISPATCHER +#include "../../Extras/BulletMultiThreaded/SpuGatheringCollisionDispatcher.h" +#endif//USE_PARALLEL_DISPATCHER + + GLDebugDrawer debugDrawer; class btIDebugDraw* debugDrawerPtr=0; @@ -187,12 +193,22 @@ void ConcaveDemo::initPhysics() // btCollisionShape* groundShape = new btBoxShape(btVector3(50,3,50)); - btCollisionDispatcher* dispatcher = new btCollisionDispatcher(); + +#ifdef USE_PARALLEL_DISPATCHER + btCollisionDispatcher* dispatcher = new SpuGatheringCollisionDispatcher(); +#else + btCollisionDispatcher* dispatcher = new btCollisionDispatcher(); +#endif//USE_PARALLEL_DISPATCHER + + btVector3 worldMin(-1000,-1000,-1000); btVector3 worldMax(1000,1000,1000); btOverlappingPairCache* pairCache = new btAxisSweep3(worldMin,worldMax); btConstraintSolver* constraintSolver = new btSequentialImpulseConstraintSolver(); m_dynamicsWorld = new btDiscreteDynamicsWorld(dispatcher,pairCache,constraintSolver); +#ifdef USE_PARALLEL_DISPATCHER + m_dynamicsWorld->getDispatchInfo().m_enableSPU=true; +#endif //USE_PARALLEL_DISPATCHER m_dynamicsWorld->setDebugDrawer(&debugDrawer); debugDrawerPtr = &debugDrawer; @@ -201,6 +217,17 @@ void ConcaveDemo::initPhysics() startTransform.setIdentity(); startTransform.setOrigin(btVector3(0,-2,0)); + { + for (int i=0;i<10;i++) + { + //btCollisionShape* boxShape = new btBoxShape(btVector3(1,1,1)); + btCollisionShape* boxShape = new btSphereShape(1.f); + startTransform.setOrigin(btVector3(2*i,10,1)); + localCreateRigidBody(1, startTransform,boxShape); + } + } + + startTransform.setIdentity(); staticBody = localCreateRigidBody(mass, startTransform,trimeshShape); staticBody->setCollisionFlags(staticBody->getCollisionFlags() | btCollisionObject::CF_STATIC_OBJECT); @@ -208,14 +235,7 @@ void ConcaveDemo::initPhysics() //enable custom material callback staticBody->setCollisionFlags(staticBody->getCollisionFlags() | btCollisionObject::CF_CUSTOM_MATERIAL_CALLBACK); - { - for (int i=0;i<10;i++) - { - btCollisionShape* boxShape = new btBoxShape(btVector3(1,1,1)); - startTransform.setOrigin(btVector3(2*i,10,1)); - localCreateRigidBody(1, startTransform,boxShape); - } - } + } diff --git a/Demos/ConvexDecompositionDemo/ConvexDecompositionDemo.cpp b/Demos/ConvexDecompositionDemo/ConvexDecompositionDemo.cpp index f9339c0c3..be7902d9e 100644 --- a/Demos/ConvexDecompositionDemo/ConvexDecompositionDemo.cpp +++ b/Demos/ConvexDecompositionDemo/ConvexDecompositionDemo.cpp @@ -22,6 +22,12 @@ subject to the following restrictions: #include "LinearMath/btIDebugDraw.h" #include "LinearMath/btGeometryUtil.h" +//#define USE_PARALLEL_DISPATCHER 1 +#ifdef USE_PARALLEL_DISPATCHER +#include "../../Extras/BulletMultiThreaded/SpuGatheringCollisionDispatcher.h" +#endif//USE_PARALLEL_DISPATCHER + + #include "GLDebugDrawer.h" #include "BMF_Api.h" @@ -83,7 +89,13 @@ void ConvexDecompositionDemo::initPhysics(const char* filename) //when running this app from visual studio, the default starting folder is different, so make a second attempt... tcount = wo.loadObj("../../file.obj"); } - btCollisionDispatcher* dispatcher = new btCollisionDispatcher(); + +#ifdef USE_PARALLEL_DISPATCHER + btCollisionDispatcher* dispatcher = new SpuGatheringCollisionDispatcher(); +#else + btCollisionDispatcher* dispatcher = new btCollisionDispatcher(); +#endif//USE_PARALLEL_DISPATCHER + btVector3 worldAabbMin(-10000,-10000,-10000); @@ -95,6 +107,10 @@ void ConvexDecompositionDemo::initPhysics(const char* filename) btConstraintSolver* solver = new btSequentialImpulseConstraintSolver(); m_dynamicsWorld = new btDiscreteDynamicsWorld(dispatcher,broadphase,solver); +#ifdef USE_PARALLEL_DISPATCHER + m_dynamicsWorld->getDispatchInfo().m_enableSPU = true; +#endif //USE_PARALLEL_DISPATCHER + btTransform startTransform; startTransform.setIdentity(); startTransform.setOrigin(btVector3(0,-4.5,0)); @@ -227,8 +243,13 @@ void ConvexDecompositionDemo::initPhysics(const char* filename) #else //SHRINK_OBJECT_INWARDS - //btCollisionShape* convexShape = new btConvexHullShape(&(vertices[0].getX()),vertices.size()); +#ifdef USE_PARALLEL_DISPATCHER + //SPU/multi threaded version only supports convex hull with contiguous vertices at the moment + btCollisionShape* convexShape = new btConvexHullShape(&(vertices[0].getX()),vertices.size()); +#else btCollisionShape* convexShape = new btConvexTriangleMeshShape(trimesh); +#endif //USE_PARALLEL_DISPATCHER + #endif convexShape->setMargin(0.01); diff --git a/Demos/MovingConcaveDemo/ConcavePhysicsDemo.cpp b/Demos/MovingConcaveDemo/ConcavePhysicsDemo.cpp index 03df126b7..e3b0247c2 100644 --- a/Demos/MovingConcaveDemo/ConcavePhysicsDemo.cpp +++ b/Demos/MovingConcaveDemo/ConcavePhysicsDemo.cpp @@ -23,6 +23,11 @@ subject to the following restrictions: #include "../Extras/GIMPACTBullet/btGIMPACTMeshShape.h" #include "../Extras/GIMPACTBullet/btConcaveConcaveCollisionAlgorithm.h" +//#define USE_PARALLEL_DISPATCHER 1 +#ifdef USE_PARALLEL_DISPATCHER +#include "../../Extras/BulletMultiThreaded/SpuGatheringCollisionDispatcher.h" +#endif//USE_PARALLEL_DISPATCHER + #include "BMF_Api.h" @@ -1630,13 +1635,22 @@ void ConcaveDemo::initPhysics() g_trimeshData = new btGIMPACTMeshData(indexVertexArrays); //btConstraintSolver* solver = new btSequentialImpulseConstraintSolver; - btCollisionDispatcher* dispatcher = new btCollisionDispatcher(); + +#ifdef USE_PARALLEL_DISPATCHER + btCollisionDispatcher* dispatcher = new SpuGatheringCollisionDispatcher(); +#else + btCollisionDispatcher* dispatcher = new btCollisionDispatcher(); +#endif//USE_PARALLEL_DISPATCHER + + + //btOverlappingPairCache* broadphase = new btSimpleBroadphase(); btOverlappingPairCache* broadphase = new btSimpleBroadphase(); btConstraintSolver* constraintSolver = new btSequentialImpulseConstraintSolver(); m_dynamicsWorld = new btDiscreteDynamicsWorld(dispatcher,broadphase,constraintSolver); + m_gimpactCollisionCreateFunc = new btConcaveConcaveCollisionAlgorithm::CreateFunc; dispatcher->registerCollisionCreateFunc(GIMPACT_SHAPE_PROXYTYPE,GIMPACT_SHAPE_PROXYTYPE,m_gimpactCollisionCreateFunc); dispatcher->registerCollisionCreateFunc(TRIANGLE_MESH_SHAPE_PROXYTYPE,GIMPACT_SHAPE_PROXYTYPE,m_gimpactCollisionCreateFunc); diff --git a/Demos/OpenGL/GL_ShapeDrawer.cpp b/Demos/OpenGL/GL_ShapeDrawer.cpp index cb3254cdb..f668eea3e 100644 --- a/Demos/OpenGL/GL_ShapeDrawer.cpp +++ b/Demos/OpenGL/GL_ShapeDrawer.cpp @@ -520,7 +520,7 @@ void GL_ShapeDrawer::drawOpenGL(btScalar* m, const btCollisionShape* shape, cons GlDrawcallback drawCallback; drawCallback.m_wireframe = (debugMode & btIDebugDraw::DBG_DrawWireframe)!=0; - concaveMesh->processAllTriangles(&drawCallback,aabbMin,aabbMax); + concaveMesh->processAllTrianglesBruteForce(&drawCallback,aabbMin,aabbMax); } #endif diff --git a/src/BulletCollision/CollisionShapes/btConcaveShape.h b/src/BulletCollision/CollisionShapes/btConcaveShape.h index 73f974e4e..be7b33044 100644 --- a/src/BulletCollision/CollisionShapes/btConcaveShape.h +++ b/src/BulletCollision/CollisionShapes/btConcaveShape.h @@ -34,6 +34,9 @@ public: virtual ~btConcaveShape(); virtual void processAllTriangles(btTriangleCallback* callback,const btVector3& aabbMin,const btVector3& aabbMax) const = 0; + virtual void processAllTrianglesBruteForce(btTriangleCallback* callback,const btVector3& aabbMin,const btVector3& aabbMax) const = 0; + + virtual btScalar getMargin() const { return m_collisionMargin; diff --git a/src/BulletCollision/CollisionShapes/btTriangleMeshShape.cpp b/src/BulletCollision/CollisionShapes/btTriangleMeshShape.cpp index c9fc51870..15ac240ef 100644 --- a/src/BulletCollision/CollisionShapes/btTriangleMeshShape.cpp +++ b/src/BulletCollision/CollisionShapes/btTriangleMeshShape.cpp @@ -138,10 +138,9 @@ const btVector3& btTriangleMeshShape::getLocalScaling() const //#define DEBUG_TRIANGLE_MESH -void btTriangleMeshShape::processAllTriangles(btTriangleCallback* callback,const btVector3& aabbMin,const btVector3& aabbMax) const +void btTriangleMeshShape::processAllTrianglesBruteForce(btTriangleCallback* callback,const btVector3& aabbMin,const btVector3& aabbMax) const { - - struct FilteredCallback : public btInternalTriangleIndexCallback + struct FilteredCallback : public btInternalTriangleIndexCallback { btTriangleCallback* m_callback; btVector3 m_aabbMin; @@ -169,7 +168,12 @@ void btTriangleMeshShape::processAllTriangles(btTriangleCallback* callback,const FilteredCallback filterCallback(callback,aabbMin,aabbMax); m_meshInterface->InternalProcessAllTriangles(&filterCallback,aabbMin,aabbMax); +} + +void btTriangleMeshShape::processAllTriangles(btTriangleCallback* callback,const btVector3& aabbMin,const btVector3& aabbMax) const +{ + processAllTrianglesBruteForce(callback,aabbMin,aabbMax); } diff --git a/src/BulletCollision/CollisionShapes/btTriangleMeshShape.h b/src/BulletCollision/CollisionShapes/btTriangleMeshShape.h index e6173e476..7687526eb 100644 --- a/src/BulletCollision/CollisionShapes/btTriangleMeshShape.h +++ b/src/BulletCollision/CollisionShapes/btTriangleMeshShape.h @@ -53,6 +53,8 @@ public: virtual void processAllTriangles(btTriangleCallback* callback,const btVector3& aabbMin,const btVector3& aabbMax) const; + virtual void processAllTrianglesBruteForce(btTriangleCallback* callback,const btVector3& aabbMin,const btVector3& aabbMax) const; + virtual void calculateLocalInertia(btScalar mass,btVector3& inertia); virtual void setLocalScaling(const btVector3& scaling);