made BasicDemo/Speculative Contacts demo a bit prettier
This commit is contained in:
@@ -36,10 +36,16 @@ subject to the following restrictions:
|
||||
#include "btBulletDynamicsCommon.h"
|
||||
|
||||
#include <stdio.h> //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)
|
||||
{
|
||||
case USE_SPECULULATIVE_CONTACTS:
|
||||
{
|
||||
sprintf(buf,"Predictive contacts enabled");
|
||||
} else
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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<btHashKey<OurValue>,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
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user