made BasicDemo/Speculative Contacts demo a bit prettier

This commit is contained in:
erwin.coumans
2011-03-05 21:13:49 +00:00
parent 7a9c349a8c
commit b67da9e50a
4 changed files with 71 additions and 24 deletions

View File

@@ -36,10 +36,16 @@ subject to the following restrictions:
#include "btBulletDynamicsCommon.h" #include "btBulletDynamicsCommon.h"
#include <stdio.h> //printf debugging #include <stdio.h> //printf debugging
#include "GLDebugDrawer.h"
static GLDebugDrawer sDebugDrawer;
BasicDemo::BasicDemo() 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() void BasicDemo::displayText()
{ {
int lineWidth=450; int lineWidth=400;
int xStart = m_glutScreenWidth - lineWidth; int xStart = m_glutScreenWidth - lineWidth;
int yStart = 20; int yStart = 20;
@@ -83,20 +89,42 @@ void BasicDemo::displayText()
char buf[124]; char buf[124];
glRasterPos3f(xStart, yStart, 0); glRasterPos3f(xStart, yStart, 0);
if (this->m_usePredictiveContacts) switch (m_ccdMode)
{
case USE_SPECULULATIVE_CONTACTS:
{ {
sprintf(buf,"Predictive contacts enabled"); sprintf(buf,"Predictive contacts enabled");
} else break;
}
case USE_CONSERVATIVE_ADVANCEMENT:
{ {
sprintf(buf,"Conservative advancement enabled"); 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); GLDebugDrawString(xStart,20,buf);
yStart+=20;
glRasterPos3f(xStart, yStart, 0); glRasterPos3f(xStart, yStart, 0);
sprintf(buf,"Press 'p' to toggle CCD mode"); sprintf(buf,"Press 'p' to change CCD mode");
yStart+=20; yStart+=20;
GLDebugDrawString(xStart,yStart,buf); GLDebugDrawString(xStart,yStart,buf);
glRasterPos3f(xStart, yStart, 0); 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(); resetPerspectiveProjection();
glEnable(GL_LIGHTING); glEnable(GL_LIGHTING);
@@ -133,7 +161,6 @@ void BasicDemo::initPhysics()
m_ShootBoxInitialSpeed = 1000.f; m_ShootBoxInitialSpeed = 1000.f;
setCameraDistance(btScalar(SCALING*50.));
///collision configuration contains default setup for memory, collision setup ///collision configuration contains default setup for memory, collision setup
m_collisionConfiguration = new btDefaultCollisionConfiguration(); m_collisionConfiguration = new btDefaultCollisionConfiguration();
@@ -150,9 +177,9 @@ void BasicDemo::initPhysics()
m_solver = sol; m_solver = sol;
m_dynamicsWorld = new btDiscreteDynamicsWorld(m_dispatcher,m_broadphase,m_solver,m_collisionConfiguration); 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; m_dynamicsWorld->getDispatchInfo().m_convexMaxDistanceUseCPT = true;
} }
@@ -231,7 +258,7 @@ void BasicDemo::initPhysics()
btDefaultMotionState* myMotionState = new btDefaultMotionState(startTransform); btDefaultMotionState* myMotionState = new btDefaultMotionState(startTransform);
btRigidBody::btRigidBodyConstructionInfo rbInfo(mass,myMotionState,colShape,localInertia); btRigidBody::btRigidBodyConstructionInfo rbInfo(mass,myMotionState,colShape,localInertia);
btRigidBody* body = new btRigidBody(rbInfo); btRigidBody* body = new btRigidBody(rbInfo);
if (m_usePredictiveContacts) if (m_ccdMode==USE_SPECULULATIVE_CONTACTS)
body->setContactProcessingThreshold(1e30); body->setContactProcessingThreshold(1e30);
m_dynamicsWorld->addRigidBody(body); m_dynamicsWorld->addRigidBody(body);
@@ -253,7 +280,24 @@ void BasicDemo::keyboardCallback(unsigned char key, int x, int y)
{ {
if (key=='p') 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(); clientResetScene();
} else } else
{ {
@@ -289,11 +333,11 @@ void BasicDemo::shootBox(const btVector3& destination)
body->setAngularVelocity(btVector3(0,0,0)); body->setAngularVelocity(btVector3(0,0,0));
body->setContactProcessingThreshold(1e30); body->setContactProcessingThreshold(1e30);
///when using m_usePredictiveContacts, disable regular CCD ///when using m_ccdMode, disable regular CCD
if (!m_usePredictiveContacts) if (m_ccdMode==USE_CONSERVATIVE_ADVANCEMENT)
{ {
body->setCcdMotionThreshold(1.); body->setCcdMotionThreshold(1.);
body->setCcdSweptSphereRadius(0.2f); body->setCcdSweptSphereRadius(0.5f*SCALING);
} }
} }

View File

@@ -47,7 +47,13 @@ class BasicDemo : public PlatformDemoApplication
btConstraintSolver* m_solver; btConstraintSolver* m_solver;
bool m_usePredictiveContacts; enum
{
USE_SPECULULATIVE_CONTACTS=0,
USE_CONSERVATIVE_ADVANCEMENT,
USE_NO_CCD
};
int m_ccdMode;
btDefaultCollisionConfiguration* m_collisionConfiguration; btDefaultCollisionConfiguration* m_collisionConfiguration;

View File

@@ -15,7 +15,6 @@ subject to the following restrictions:
#include "BasicDemo.h" #include "BasicDemo.h"
#include "GlutStuff.h" #include "GlutStuff.h"
#include "GLDebugDrawer.h"
#include "btBulletDynamicsCommon.h" #include "btBulletDynamicsCommon.h"
#include "LinearMath/btHashMap.h" #include "LinearMath/btHashMap.h"
@@ -42,7 +41,6 @@ class OurValue
int main(int argc,char** argv) int main(int argc,char** argv)
{ {
GLDebugDrawer gDebugDrawer;
///testing the btHashMap ///testing the btHashMap
btHashMap<btHashKey<OurValue>,OurValue> map; btHashMap<btHashKey<OurValue>,OurValue> map;
@@ -75,13 +73,12 @@ int main(int argc,char** argv)
BasicDemo ccdDemo; BasicDemo ccdDemo;
ccdDemo.initPhysics(); ccdDemo.initPhysics();
ccdDemo.getDynamicsWorld()->setDebugDrawer(&gDebugDrawer);
#ifdef CHECK_MEMORY_LEAKS #ifdef CHECK_MEMORY_LEAKS
ccdDemo.exitPhysics(); ccdDemo.exitPhysics();
#else #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 #endif
//default glut doesn't return from mainloop //default glut doesn't return from mainloop

View File

@@ -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 ); sprintf(blockTime,"--- Profiling: %s (total running time: %.3f ms) ---", m_profileIterator->Get_Current_Parent_Name(), parent_time );
displayProfileString(xOffset,yStart,blockTime); displayProfileString(xOffset,yStart,blockTime);
yStart += yIncr; 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); displayProfileString(xOffset,yStart,blockTime);
yStart += yIncr; yStart += yIncr;