added brute-force triangle iteration method, to allow graphics to skip aabb traversal (useful for debugging)

This commit is contained in:
ejcoumans 2007-06-13 22:35:14 +00:00
parent 05cbd96972
commit effb5a8b62
7 changed files with 80 additions and 16 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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