From f1be4ab221c0fb0222d2468c22c543cc24290ab3 Mon Sep 17 00:00:00 2001 From: ejcoumans Date: Mon, 10 Dec 2007 02:18:38 +0000 Subject: [PATCH] only update aabb of active objects, thanks Peter Tchernev for reporting (http://bulletphysics.com/Bullet/phpBB3/viewtopic.php?f=9&t=1764 ) move debug aabb rendering from updateAabb to debugDrawWorld --- Demos/BspDemo/BspDemo.cpp | 3 +++ Demos/CcdPhysicsDemo/CcdPhysicsDemo.cpp | 3 +++ Demos/ColladaDemo/ColladaDemo.cpp | 6 +++++- .../ConcaveConvexcastDemo.cpp | 3 +++ Demos/ConcaveDemo/ConcavePhysicsDemo.cpp | 3 +++ .../ConcaveRaycastDemo/ConcaveRaycastDemo.cpp | 3 +++ Demos/ConstraintDemo/ConstraintDemo.cpp | 14 +++++++++----- .../ConvexDecompositionDemo.cpp | 6 +++++- Demos/GenericJointDemo/GenericJointDemo.cpp | 6 +++++- Demos/GimpactTestDemo/GimpactTestDemo.cpp | 4 ++++ .../MovingConcaveDemo/ConcavePhysicsDemo.cpp | 3 +++ Demos/RagdollDemo/RagdollDemo.cpp | 5 +++++ .../UserCollisionAlgorithm.cpp | 3 +++ Demos/VehicleDemo/VehicleDemo.cpp | 3 +++ .../Dynamics/btDiscreteDynamicsWorld.cpp | 19 +++++++++++-------- 15 files changed, 68 insertions(+), 16 deletions(-) diff --git a/Demos/BspDemo/BspDemo.cpp b/Demos/BspDemo/BspDemo.cpp index 74e4ca806..bc4ffafd4 100644 --- a/Demos/BspDemo/BspDemo.cpp +++ b/Demos/BspDemo/BspDemo.cpp @@ -217,6 +217,9 @@ void BspDemo::clientMoveAndDisplay() m_dynamicsWorld->stepSimulation(dt); + //optional but useful: debug drawing + m_dynamicsWorld->debugDrawWorld(); + renderme(); glFlush(); diff --git a/Demos/CcdPhysicsDemo/CcdPhysicsDemo.cpp b/Demos/CcdPhysicsDemo/CcdPhysicsDemo.cpp index 8e4be2012..401783e27 100644 --- a/Demos/CcdPhysicsDemo/CcdPhysicsDemo.cpp +++ b/Demos/CcdPhysicsDemo/CcdPhysicsDemo.cpp @@ -246,6 +246,9 @@ void CcdPhysicsDemo::clientMoveAndDisplay() int numSimSteps = 0; numSimSteps = m_dynamicsWorld->stepSimulation(dt,maxSimSubSteps); + //optional but useful: debug drawing + m_dynamicsWorld->debugDrawWorld(); + #ifdef VERBOSE_TIMESTEPPING_CONSOLEOUTPUT if (!numSimSteps) printf("Interpolated transforms\n"); diff --git a/Demos/ColladaDemo/ColladaDemo.cpp b/Demos/ColladaDemo/ColladaDemo.cpp index c4e73fc8f..8d5437e33 100644 --- a/Demos/ColladaDemo/ColladaDemo.cpp +++ b/Demos/ColladaDemo/ColladaDemo.cpp @@ -212,6 +212,9 @@ void ColladaDemo::clientMoveAndDisplay() m_dynamicsWorld->stepSimulation(dt); + //optional but useful: debug drawing + m_dynamicsWorld->debugDrawWorld(); + renderme(); glFlush(); @@ -226,7 +229,8 @@ void ColladaDemo::displayCallback(void) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - m_dynamicsWorld->updateAabbs(); + if (m_dynamicsWorld) + m_dynamicsWorld->debugDrawWorld(); renderme(); diff --git a/Demos/ConcaveConvexcastDemo/ConcaveConvexcastDemo.cpp b/Demos/ConcaveConvexcastDemo/ConcaveConvexcastDemo.cpp index a9393b658..6fd3c3d68 100644 --- a/Demos/ConcaveConvexcastDemo/ConcaveConvexcastDemo.cpp +++ b/Demos/ConcaveConvexcastDemo/ConcaveConvexcastDemo.cpp @@ -377,6 +377,9 @@ void ConcaveConvexcastDemo::clientMoveAndDisplay() m_dynamicsWorld->stepSimulation(dt); + //optional but useful: debug drawing + m_dynamicsWorld->debugDrawWorld(); + convexcastBatch.move (dt); convexcastBatch.cast (m_dynamicsWorld); renderme(); diff --git a/Demos/ConcaveDemo/ConcavePhysicsDemo.cpp b/Demos/ConcaveDemo/ConcavePhysicsDemo.cpp index 940fb0856..3fe069fa1 100644 --- a/Demos/ConcaveDemo/ConcavePhysicsDemo.cpp +++ b/Demos/ConcaveDemo/ConcavePhysicsDemo.cpp @@ -325,6 +325,9 @@ void ConcaveDemo::clientMoveAndDisplay() } m_dynamicsWorld->stepSimulation(dt); + + //optional but useful: debug drawing + m_dynamicsWorld->debugDrawWorld(); renderme(); diff --git a/Demos/ConcaveRaycastDemo/ConcaveRaycastDemo.cpp b/Demos/ConcaveRaycastDemo/ConcaveRaycastDemo.cpp index 5d7460678..a95026090 100644 --- a/Demos/ConcaveRaycastDemo/ConcaveRaycastDemo.cpp +++ b/Demos/ConcaveRaycastDemo/ConcaveRaycastDemo.cpp @@ -351,6 +351,9 @@ void ConcaveRaycastDemo::clientMoveAndDisplay() m_dynamicsWorld->stepSimulation(dt); + //optional but useful: debug drawing + m_dynamicsWorld->debugDrawWorld(); + raycastBar.move (dt); raycastBar.cast (m_dynamicsWorld); renderme(); diff --git a/Demos/ConstraintDemo/ConstraintDemo.cpp b/Demos/ConstraintDemo/ConstraintDemo.cpp index eee1408e6..3aed5fe38 100644 --- a/Demos/ConstraintDemo/ConstraintDemo.cpp +++ b/Demos/ConstraintDemo/ConstraintDemo.cpp @@ -201,13 +201,17 @@ void ConstraintDemo::clientMoveAndDisplay() m_clock.reset(); //printf("dt = %f: ",dt); - { + { //during idle mode, just run 1 simulation step maximum int maxSimSubSteps = m_idle ? 1 : 1; if (m_idle) dt = 1.0/420.f; int numSimSteps = m_dynamicsWorld->stepSimulation(dt,maxSimSubSteps); + + //optional but useful: debug drawing + m_dynamicsWorld->debugDrawWorld(); + bool verbose = false; if (verbose) { @@ -225,7 +229,7 @@ void ConstraintDemo::clientMoveAndDisplay() } } } - } + } renderme(); drawLimit(); @@ -241,9 +245,9 @@ void ConstraintDemo::displayCallback(void) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - - m_dynamicsWorld->updateAabbs(); - + if (m_dynamicsWorld) + m_dynamicsWorld->debugDrawWorld(); + drawLimit(); renderme(); diff --git a/Demos/ConvexDecompositionDemo/ConvexDecompositionDemo.cpp b/Demos/ConvexDecompositionDemo/ConvexDecompositionDemo.cpp index a9b9082ab..455cd4b9a 100644 --- a/Demos/ConvexDecompositionDemo/ConvexDecompositionDemo.cpp +++ b/Demos/ConvexDecompositionDemo/ConvexDecompositionDemo.cpp @@ -372,6 +372,9 @@ void ConvexDecompositionDemo::clientMoveAndDisplay() m_dynamicsWorld->stepSimulation(dt); + //optional but useful: debug drawing + m_dynamicsWorld->debugDrawWorld(); + renderme(); glFlush(); @@ -386,7 +389,8 @@ void ConvexDecompositionDemo::displayCallback(void) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - m_dynamicsWorld->updateAabbs(); + if (m_dynamicsWorld) + m_dynamicsWorld->debugDrawWorld(); renderme(); diff --git a/Demos/GenericJointDemo/GenericJointDemo.cpp b/Demos/GenericJointDemo/GenericJointDemo.cpp index a03423ce0..251dd7faa 100644 --- a/Demos/GenericJointDemo/GenericJointDemo.cpp +++ b/Demos/GenericJointDemo/GenericJointDemo.cpp @@ -116,7 +116,11 @@ void GenericJointDemo::clientMoveAndDisplay() ms = minFPS; if (m_dynamicsWorld) + { m_dynamicsWorld->stepSimulation(ms / 1000000.f); + //optional but useful: debug drawing + m_dynamicsWorld->debugDrawWorld(); + } renderme(); @@ -130,7 +134,7 @@ void GenericJointDemo::displayCallback() glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); if (m_dynamicsWorld) - m_dynamicsWorld->updateAabbs(); + m_dynamicsWorld->debugDrawWorld(); renderme(); diff --git a/Demos/GimpactTestDemo/GimpactTestDemo.cpp b/Demos/GimpactTestDemo/GimpactTestDemo.cpp index 029ba2a39..5207b1b8c 100644 --- a/Demos/GimpactTestDemo/GimpactTestDemo.cpp +++ b/Demos/GimpactTestDemo/GimpactTestDemo.cpp @@ -598,6 +598,10 @@ void GimpactConcaveDemo::clientMoveAndDisplay() m_clock.reset(); m_dynamicsWorld->stepSimulation(dt); + + //optional but useful: debug drawing + m_dynamicsWorld->debugDrawWorld(); + m_steps_done++; //m_dynamicsWorld->stepSimulation(dts); diff --git a/Demos/MovingConcaveDemo/ConcavePhysicsDemo.cpp b/Demos/MovingConcaveDemo/ConcavePhysicsDemo.cpp index ec3218d60..8681de979 100644 --- a/Demos/MovingConcaveDemo/ConcavePhysicsDemo.cpp +++ b/Demos/MovingConcaveDemo/ConcavePhysicsDemo.cpp @@ -1890,6 +1890,9 @@ void ConcaveDemo::clientMoveAndDisplay() m_clock.reset(); m_dynamicsWorld->stepSimulation(dt); + //optional but useful: debug drawing + m_dynamicsWorld->debugDrawWorld(); + renderme(); glFlush(); diff --git a/Demos/RagdollDemo/RagdollDemo.cpp b/Demos/RagdollDemo/RagdollDemo.cpp index fe2bfd214..cb32a3ade 100644 --- a/Demos/RagdollDemo/RagdollDemo.cpp +++ b/Demos/RagdollDemo/RagdollDemo.cpp @@ -369,7 +369,12 @@ void RagdollDemo::clientMoveAndDisplay() ms = minFPS; if (m_dynamicsWorld) + { m_dynamicsWorld->stepSimulation(ms / 1000000.f); + //optional but useful: debug drawing + m_dynamicsWorld->debugDrawWorld(); + + } renderme(); diff --git a/Demos/UserCollisionAlgorithm/UserCollisionAlgorithm.cpp b/Demos/UserCollisionAlgorithm/UserCollisionAlgorithm.cpp index 4dc5b5aa7..271d44255 100644 --- a/Demos/UserCollisionAlgorithm/UserCollisionAlgorithm.cpp +++ b/Demos/UserCollisionAlgorithm/UserCollisionAlgorithm.cpp @@ -147,6 +147,9 @@ void UserCollisionAlgorithm::clientMoveAndDisplay() m_dynamicsWorld->stepSimulation(dt); + //optional but useful: debug drawing + m_dynamicsWorld->debugDrawWorld(); + renderme(); glFlush(); diff --git a/Demos/VehicleDemo/VehicleDemo.cpp b/Demos/VehicleDemo/VehicleDemo.cpp index 18a29d92f..522ec939f 100644 --- a/Demos/VehicleDemo/VehicleDemo.cpp +++ b/Demos/VehicleDemo/VehicleDemo.cpp @@ -453,6 +453,9 @@ void VehicleDemo::clientMoveAndDisplay() dt = 1.0/420.f; int numSimSteps = m_dynamicsWorld->stepSimulation(dt,maxSimSubSteps); + //optional but useful: debug drawing + m_dynamicsWorld->debugDrawWorld(); + //#define VERBOSE_FEEDBACK #ifdef VERBOSE_FEEDBACK diff --git a/src/BulletDynamics/Dynamics/btDiscreteDynamicsWorld.cpp b/src/BulletDynamics/Dynamics/btDiscreteDynamicsWorld.cpp index 2d8e8360b..9c4f334f0 100644 --- a/src/BulletDynamics/Dynamics/btDiscreteDynamicsWorld.cpp +++ b/src/BulletDynamics/Dynamics/btDiscreteDynamicsWorld.cpp @@ -125,7 +125,7 @@ void btDiscreteDynamicsWorld::saveKinematicState(btScalar timeStep) void btDiscreteDynamicsWorld::debugDrawWorld() { - if (getDebugDrawer() && getDebugDrawer()->getDebugMode() & btIDebugDraw::DBG_DrawWireframe) + if (getDebugDrawer() && getDebugDrawer()->getDebugMode() & (btIDebugDraw::DBG_DrawWireframe | btIDebugDraw::DBG_DrawAabb)) { int i; @@ -156,6 +156,14 @@ void btDiscreteDynamicsWorld::debugDrawWorld() debugDrawObject(colObj->getWorldTransform(),colObj->getCollisionShape(),color); } + if (m_debugDrawer && (m_debugDrawer->getDebugMode() & btIDebugDraw::DBG_DrawAabb)) + { + btPoint3 minAabb,maxAabb; + btVector3 colorvec(1,0,0); + colObj->getCollisionShape()->getAabb(colObj->getWorldTransform(), minAabb,maxAabb); + m_debugDrawer->drawAabb(minAabb,maxAabb,colorvec); + } + } for ( i=0;im_vehicles.size();i++) @@ -636,8 +644,6 @@ void btDiscreteDynamicsWorld::updateAabbs() { PROFILE("updateAabbs"); - - btVector3 colorvec(1,0,0); btTransform predictedTrans; for ( int i=0;iIsActive() && (!body->IsStatic())) + //only update aabb of active objects + if (body->isActive()) { btPoint3 minAabb,maxAabb; colObj->getCollisionShape()->getAabb(colObj->getWorldTransform(), minAabb,maxAabb); @@ -674,10 +681,6 @@ void btDiscreteDynamicsWorld::updateAabbs() } - if (m_debugDrawer && (m_debugDrawer->getDebugMode() & btIDebugDraw::DBG_DrawAabb)) - { - m_debugDrawer->drawAabb(minAabb,maxAabb,colorvec); - } } } }