From be175e888e407db2c6c2be9fb4bf20291c572a45 Mon Sep 17 00:00:00 2001 From: ejcoumans Date: Tue, 14 Nov 2006 05:09:11 +0000 Subject: [PATCH] --- .../EPAPenDepthDemo/PenetrationTestBullet.cpp | 23 ++++++++++++++++- Demos/OpenGL/DemoApplication.cpp | 9 +++++++ Extras/GIMPACT/include/GIMPACT/gim_memory.h | 2 ++ Extras/GIMPACT/src/gim_memory.cpp | 15 ++++++----- .../CollisionDispatch/btCollisionWorld.cpp | 8 +++--- .../CollisionDispatch/btCollisionWorld.h | 4 +-- .../btConvexConvexAlgorithm.cpp | 25 +++++++++++++++++++ .../Dynamics/btDiscreteDynamicsWorld.cpp | 8 +++++- .../Dynamics/btSimpleDynamicsWorld.cpp | 7 +++++- 9 files changed, 86 insertions(+), 15 deletions(-) diff --git a/Demos/EPAPenDepthDemo/PenetrationTestBullet.cpp b/Demos/EPAPenDepthDemo/PenetrationTestBullet.cpp index 2b2b3635f..5b19bc105 100644 --- a/Demos/EPAPenDepthDemo/PenetrationTestBullet.cpp +++ b/Demos/EPAPenDepthDemo/PenetrationTestBullet.cpp @@ -35,7 +35,10 @@ #include "../Extras/ExtraSolid35/Solid3JohnsonSimplexSolver.h" #include "../Extras/EPA/EpaPenetrationDepthSolver.h" - +#define USE_ORIGINAL 1 +#ifndef USE_ORIGINAL +#include "BulletCollision/NarrowPhaseCollision/btGjkEpa.h" +#endif //USE_ORIGINAL static bool gRefMode = false; static int gMethod = 0; @@ -295,6 +298,9 @@ static bool TestEPA(const MyConvex& hull0, const MyConvex& hull1) else Solver = &Solver2; + +#ifdef USE_ORIGINAL + btGjkPairDetector GJK(&convexA, &convexB, &simplexSolver, Solver); GJK.m_catchDegeneracies = 1; convexA.setMargin(0.01f); @@ -309,6 +315,21 @@ static bool TestEPA(const MyConvex& hull0, const MyConvex& hull1) gLastUsedMethod = GJK.m_lastUsedMethod; gNumGjkIterations = GJK.m_curIter; gLastDegenerateSimplex= GJK.m_degenerateSimplex; +#else + MyResult output; + btVector3 witnesses[2]; + btVector3 normal; + btScalar depth; + + btGjkEpaSolver::Collide(&convexA,hull0.mTransform, + &convexB,hull1.mTransform, + 0.01,0.01, + witnesses,normal,depth); + if (depth>0) + { + output.addContactPoint(normal,witnesses[1],-depth); + } +#endif return true; } diff --git a/Demos/OpenGL/DemoApplication.cpp b/Demos/OpenGL/DemoApplication.cpp index b74a1b4df..e8c2ca022 100644 --- a/Demos/OpenGL/DemoApplication.cpp +++ b/Demos/OpenGL/DemoApplication.cpp @@ -892,5 +892,14 @@ void DemoApplication::clientResetScene() btRigidBody::upcast(colObj)->setAngularVelocity(btVector3(0,0,0)); } } + + /* + //quickly search some issue at a certain simulation frame, pressing space to reset + int fixed=18; + for (int i=0;istepSimulation(1./60.f,1); + } + */ } } diff --git a/Extras/GIMPACT/include/GIMPACT/gim_memory.h b/Extras/GIMPACT/include/GIMPACT/gim_memory.h index 329807ac8..21070169d 100644 --- a/Extras/GIMPACT/include/GIMPACT/gim_memory.h +++ b/Extras/GIMPACT/include/GIMPACT/gim_memory.h @@ -126,7 +126,9 @@ get current memory management functions. */ //! @{ gim_alloc_function *gim_get_alloc_handler (void); +#ifdef ALLOCA_GIMPACT gim_alloca_function *gim_get_alloca_handler(void); +#endif // gim_realloc_function *gim_get_realloc_handler (void); gim_free_function *gim_get_free_handler (void); //! @} diff --git a/Extras/GIMPACT/src/gim_memory.cpp b/Extras/GIMPACT/src/gim_memory.cpp index 9b1a0b28c..1c8b36d55 100644 --- a/Extras/GIMPACT/src/gim_memory.cpp +++ b/Extras/GIMPACT/src/gim_memory.cpp @@ -133,10 +133,13 @@ void * gim_alloc(size_t size) return ptr; } +#ifdef ALLOCA_GIMPACT void * gim_alloca(size_t size) { - if (g_allocafn) return g_allocafn(size); else return alloca(size); + if (g_allocafn) return g_allocafn(size); else + return alloca(size); } +#endif void * gim_realloc(void *ptr, size_t oldsize, size_t newsize) @@ -305,13 +308,13 @@ void gim_destroy_buffer_manager(GUINT buffer_manager_id) GBUFFER_DATA * buffers = GIM_DYNARRAY_POINTER(GBUFFER_DATA,bm_data->m_buffer_array); GUINT i, buffer_count = bm_data->m_buffer_array.m_size; - for (i=0;im_prototype.free_fn(buffers[i].m_buffer_handle,buffers[i].m_size); - } + } } //destroy buffer array @@ -339,7 +342,7 @@ void gim_get_buffer_manager_data(GUINT buffer_manager_id,GBUFFER_MANAGER_DATA ** void gim_init_buffer_managers() { GUINT i; - for (i=0;i(body0->getCollisionShape())); + btConvexShape* shape1(static_cast(body1->getCollisionShape())); + const btScalar margin(shape0->getMargin()+shape1->getMargin()); + resultOut->setPersistentManifold(m_manifoldPtr); + if(btGjkEpaSolver::Collide( shape0,body0->getWorldTransform(), + shape1,body1->getWorldTransform(), + shape0->getMargin(),shape1->getMargin(), + witnesses,normal,depth)) + { + + + //optional: draw the contact+normal + //dispatchInfo.m_debugDraw->drawLine(witnesses[1],witnesses[1]+normal,btVector3(255,0,0)); + resultOut->addContactPoint(normal,witnesses[1],-depth); + } + #else checkPenetrationDepthSolver(); btConvexShape* min0 = static_cast(body0->getCollisionShape()); @@ -175,6 +199,7 @@ void btConvexConvexAlgorithm ::processCollision (btCollisionObject* body0,btColl resultOut->setPersistentManifold(m_manifoldPtr); m_gjkPairDetector.getClosestPoints(input,*resultOut,dispatchInfo.m_debugDraw); + #endif } diff --git a/src/BulletDynamics/Dynamics/btDiscreteDynamicsWorld.cpp b/src/BulletDynamics/Dynamics/btDiscreteDynamicsWorld.cpp index c97da84e0..a4e210290 100644 --- a/src/BulletDynamics/Dynamics/btDiscreteDynamicsWorld.cpp +++ b/src/BulletDynamics/Dynamics/btDiscreteDynamicsWorld.cpp @@ -267,8 +267,14 @@ void btDiscreteDynamicsWorld::internalSingleStepSimulation(float timeStep) ///apply gravity, predict motion predictUnconstraintMotion(timeStep); + btDispatcherInfo dispatchInfo; + dispatchInfo.m_timeStep = timeStep; + dispatchInfo.m_stepCount = 0; + dispatchInfo.m_debugDraw = getDebugDrawer(); + + ///perform collision detection - performDiscreteCollisionDetection(); + performDiscreteCollisionDetection(dispatchInfo); calculateSimulationIslands(); diff --git a/src/BulletDynamics/Dynamics/btSimpleDynamicsWorld.cpp b/src/BulletDynamics/Dynamics/btSimpleDynamicsWorld.cpp index 4d5c789c8..72f05acad 100644 --- a/src/BulletDynamics/Dynamics/btSimpleDynamicsWorld.cpp +++ b/src/BulletDynamics/Dynamics/btSimpleDynamicsWorld.cpp @@ -52,8 +52,13 @@ int btSimpleDynamicsWorld::stepSimulation( float timeStep,int maxSubSteps, floa ///apply gravity, predict motion predictUnconstraintMotion(timeStep); + btDispatcherInfo dispatchInfo; + dispatchInfo.m_timeStep = timeStep; + dispatchInfo.m_stepCount = 0; + dispatchInfo.m_debugDraw = getDebugDrawer(); + ///perform collision detection - performDiscreteCollisionDetection(); + performDiscreteCollisionDetection(dispatchInfo ); ///solve contact constraints int numManifolds = m_dispatcher1->getNumManifolds();