diff --git a/Demos/BasicDemo/BasicDemo.cpp b/Demos/BasicDemo/BasicDemo.cpp index e0702b4c6..d4099d8ac 100644 --- a/Demos/BasicDemo/BasicDemo.cpp +++ b/Demos/BasicDemo/BasicDemo.cpp @@ -36,10 +36,16 @@ subject to the following restrictions: #include "btBulletDynamicsCommon.h" #include //printf debugging +#include "GLDebugDrawer.h" + +static GLDebugDrawer sDebugDrawer; + BasicDemo::BasicDemo() -:m_usePredictiveContacts(true) +:m_ccdMode(USE_SPECULULATIVE_CONTACTS) { + setDebugMode(btIDebugDraw::DBG_DrawText); + setCameraDistance(btScalar(SCALING*50.)); } @@ -71,7 +77,7 @@ void BasicDemo::clientMoveAndDisplay() void BasicDemo::displayText() { - int lineWidth=450; + int lineWidth=400; int xStart = m_glutScreenWidth - lineWidth; int yStart = 20; @@ -83,20 +89,42 @@ void BasicDemo::displayText() char buf[124]; glRasterPos3f(xStart, yStart, 0); - if (this->m_usePredictiveContacts) + switch (m_ccdMode) { - sprintf(buf,"Predictive contacts enabled"); - } else - { - sprintf(buf,"Conservative advancement enabled"); - } + case USE_SPECULULATIVE_CONTACTS: + { + sprintf(buf,"Predictive contacts enabled"); + break; + } + case USE_CONSERVATIVE_ADVANCEMENT: + { + sprintf(buf,"Conservative advancement enabled"); + break; + }; + case USE_NO_CCD: + { + sprintf(buf,"CCD disabled"); + break; + } + default: + { + sprintf(buf,"unknown CCD setting"); + }; + }; + GLDebugDrawString(xStart,20,buf); - yStart+=20; glRasterPos3f(xStart, yStart, 0); - sprintf(buf,"Press 'p' to toggle CCD mode"); + sprintf(buf,"Press 'p' to change CCD mode"); yStart+=20; GLDebugDrawString(xStart,yStart,buf); glRasterPos3f(xStart, yStart, 0); + sprintf(buf,"Press '.' or right mouse to shoot boxes"); + yStart+=20; + GLDebugDrawString(xStart,yStart,buf); + glRasterPos3f(xStart, yStart, 0); + sprintf(buf,"space to restart, h(elp), t(ext), w(ire)"); + yStart+=20; + GLDebugDrawString(xStart,yStart,buf); resetPerspectiveProjection(); glEnable(GL_LIGHTING); @@ -133,7 +161,6 @@ void BasicDemo::initPhysics() m_ShootBoxInitialSpeed = 1000.f; - setCameraDistance(btScalar(SCALING*50.)); ///collision configuration contains default setup for memory, collision setup m_collisionConfiguration = new btDefaultCollisionConfiguration(); @@ -150,9 +177,9 @@ void BasicDemo::initPhysics() m_solver = sol; m_dynamicsWorld = new btDiscreteDynamicsWorld(m_dispatcher,m_broadphase,m_solver,m_collisionConfiguration); - setDebugMode(btIDebugDraw::DBG_DrawText|btIDebugDraw::DBG_NoHelpText); + m_dynamicsWorld ->setDebugDrawer(&sDebugDrawer); - if (m_usePredictiveContacts) + if (m_ccdMode==USE_SPECULULATIVE_CONTACTS) { m_dynamicsWorld->getDispatchInfo().m_convexMaxDistanceUseCPT = true; } @@ -231,7 +258,7 @@ void BasicDemo::initPhysics() btDefaultMotionState* myMotionState = new btDefaultMotionState(startTransform); btRigidBody::btRigidBodyConstructionInfo rbInfo(mass,myMotionState,colShape,localInertia); btRigidBody* body = new btRigidBody(rbInfo); - if (m_usePredictiveContacts) + if (m_ccdMode==USE_SPECULULATIVE_CONTACTS) body->setContactProcessingThreshold(1e30); m_dynamicsWorld->addRigidBody(body); @@ -253,7 +280,24 @@ void BasicDemo::keyboardCallback(unsigned char key, int x, int y) { if (key=='p') { - m_usePredictiveContacts = !m_usePredictiveContacts; + switch (m_ccdMode) + { + case USE_SPECULULATIVE_CONTACTS: + { + m_ccdMode = USE_CONSERVATIVE_ADVANCEMENT; + break; + } + case USE_CONSERVATIVE_ADVANCEMENT: + { + m_ccdMode = USE_NO_CCD; + break; + }; + case USE_NO_CCD: + default: + { + m_ccdMode = USE_SPECULULATIVE_CONTACTS; + } + }; clientResetScene(); } else { @@ -289,11 +333,11 @@ void BasicDemo::shootBox(const btVector3& destination) body->setAngularVelocity(btVector3(0,0,0)); body->setContactProcessingThreshold(1e30); - ///when using m_usePredictiveContacts, disable regular CCD - if (!m_usePredictiveContacts) + ///when using m_ccdMode, disable regular CCD + if (m_ccdMode==USE_CONSERVATIVE_ADVANCEMENT) { body->setCcdMotionThreshold(1.); - body->setCcdSweptSphereRadius(0.2f); + body->setCcdSweptSphereRadius(0.5f*SCALING); } } diff --git a/Demos/BasicDemo/BasicDemo.h b/Demos/BasicDemo/BasicDemo.h index 769b1954f..4876a2e48 100644 --- a/Demos/BasicDemo/BasicDemo.h +++ b/Demos/BasicDemo/BasicDemo.h @@ -47,7 +47,13 @@ class BasicDemo : public PlatformDemoApplication btConstraintSolver* m_solver; - bool m_usePredictiveContacts; + enum + { + USE_SPECULULATIVE_CONTACTS=0, + USE_CONSERVATIVE_ADVANCEMENT, + USE_NO_CCD + }; + int m_ccdMode; btDefaultCollisionConfiguration* m_collisionConfiguration; diff --git a/Demos/BasicDemo/main.cpp b/Demos/BasicDemo/main.cpp index 957c4ba7b..eadcb6d70 100644 --- a/Demos/BasicDemo/main.cpp +++ b/Demos/BasicDemo/main.cpp @@ -15,7 +15,6 @@ subject to the following restrictions: #include "BasicDemo.h" #include "GlutStuff.h" -#include "GLDebugDrawer.h" #include "btBulletDynamicsCommon.h" #include "LinearMath/btHashMap.h" @@ -42,7 +41,6 @@ class OurValue int main(int argc,char** argv) { - GLDebugDrawer gDebugDrawer; ///testing the btHashMap btHashMap,OurValue> map; @@ -75,13 +73,12 @@ int main(int argc,char** argv) BasicDemo ccdDemo; ccdDemo.initPhysics(); - ccdDemo.getDynamicsWorld()->setDebugDrawer(&gDebugDrawer); #ifdef CHECK_MEMORY_LEAKS ccdDemo.exitPhysics(); #else - return glutmain(argc, argv,640,480,"Bullet Physics Demo. http://bulletphysics.com",&ccdDemo); + return glutmain(argc, argv,1024,600,"Bullet Physics Demo. http://bulletphysics.org",&ccdDemo); #endif //default glut doesn't return from mainloop diff --git a/Demos/OpenGL/DemoApplication.cpp b/Demos/OpenGL/DemoApplication.cpp index 050870ea4..b6699d4b3 100644 --- a/Demos/OpenGL/DemoApplication.cpp +++ b/Demos/OpenGL/DemoApplication.cpp @@ -1105,7 +1105,7 @@ void DemoApplication::showProfileInfo(int& xOffset,int& yStart, int yIncr) sprintf(blockTime,"--- Profiling: %s (total running time: %.3f ms) ---", m_profileIterator->Get_Current_Parent_Name(), parent_time ); displayProfileString(xOffset,yStart,blockTime); yStart += yIncr; - sprintf(blockTime,"press number (1,2...) to display child timings, or 0 to go up to parent" ); + sprintf(blockTime,"press (1,2...) to display child timings, or 0 for parent" ); displayProfileString(xOffset,yStart,blockTime); yStart += yIncr;