improve usability of ExampleBrowser

store command-line arguments in bulletDemo.txt
save/load of configuration, save demo name instead of index
add setBackgroundColor as example (background_color_red) and
mouse move/wheel speed config (mouse_wheel_multiplier and mouse_move_multiplier)
(saved after changing the demo)
default btIDebugDraw colors can be changed
b3CommandLineArgs::GetCmdLineArgument returns bool, and b3CommandLineArgs::addArgs added
fix copy/paste
This commit is contained in:
erwincoumans
2015-08-04 18:24:30 -07:00
parent 9d7d5caa8b
commit b316f30040
14 changed files with 400 additions and 115 deletions

View File

@@ -19,6 +19,11 @@ public:
// Constructor
b3CommandLineArgs(int argc, char **argv)
{
addArgs(argc,argv);
}
void addArgs(int argc, char**argv)
{
using namespace std;
@@ -39,7 +44,12 @@ public:
key = string(arg, 2, pos - 2);
val = string(arg, pos + 1, arg.length() - 1);
}
pairs[key] = val;
//only add new keys, don't replace existing
if(pairs.find(key) == pairs.end())
{
pairs[key] = val;
}
}
}
@@ -54,7 +64,7 @@ public:
}
template <typename T>
void GetCmdLineArgument(const char *arg_name, T &val);
bool GetCmdLineArgument(const char *arg_name, T &val);
int ParsedArgc()
{
@@ -63,18 +73,20 @@ public:
};
template <typename T>
inline void b3CommandLineArgs::GetCmdLineArgument(const char *arg_name, T &val)
inline bool b3CommandLineArgs::GetCmdLineArgument(const char *arg_name, T &val)
{
using namespace std;
map<string, string>::iterator itr;
if ((itr = pairs.find(arg_name)) != pairs.end()) {
istringstream strstream(itr->second);
strstream >> val;
return true;
}
return false;
}
template <>
inline void b3CommandLineArgs::GetCmdLineArgument<char*>(const char* arg_name, char* &val)
inline bool b3CommandLineArgs::GetCmdLineArgument<char*>(const char* arg_name, char* &val)
{
using namespace std;
map<string, string>::iterator itr;
@@ -83,10 +95,11 @@ inline void b3CommandLineArgs::GetCmdLineArgument<char*>(const char* arg_name, c
string s = itr->second;
val = (char*) malloc(sizeof(char) * (s.length() + 1));
std::strcpy(val, s.c_str());
return true;
} else {
val = NULL;
}
return false;
}

View File

@@ -1427,84 +1427,91 @@ void btCollisionWorld::debugDrawObject(const btTransform& worldTransform, const
void btCollisionWorld::debugDrawWorld()
{
if (getDebugDrawer() && getDebugDrawer()->getDebugMode() & btIDebugDraw::DBG_DrawContactPoints)
if (getDebugDrawer())
{
if (getDispatcher())
{
int numManifolds = getDispatcher()->getNumManifolds();
btVector3 color(1,1,0);
for (int i=0;i<numManifolds;i++)
{
btPersistentManifold* contactManifold = getDispatcher()->getManifoldByIndexInternal(i);
//btCollisionObject* obA = static_cast<btCollisionObject*>(contactManifold->getBody0());
//btCollisionObject* obB = static_cast<btCollisionObject*>(contactManifold->getBody1());
btIDebugDraw::DefaultColors defaultColors = getDebugDrawer()->getDefaultColors();
int numContacts = contactManifold->getNumContacts();
for (int j=0;j<numContacts;j++)
if ( getDebugDrawer()->getDebugMode() & btIDebugDraw::DBG_DrawContactPoints)
{
if (getDispatcher())
{
int numManifolds = getDispatcher()->getNumManifolds();
for (int i=0;i<numManifolds;i++)
{
btManifoldPoint& cp = contactManifold->getContactPoint(j);
getDebugDrawer()->drawContactPoint(cp.m_positionWorldOnB,cp.m_normalWorldOnB,cp.getDistance(),cp.getLifeTime(),color);
btPersistentManifold* contactManifold = getDispatcher()->getManifoldByIndexInternal(i);
//btCollisionObject* obA = static_cast<btCollisionObject*>(contactManifold->getBody0());
//btCollisionObject* obB = static_cast<btCollisionObject*>(contactManifold->getBody1());
int numContacts = contactManifold->getNumContacts();
for (int j=0;j<numContacts;j++)
{
btManifoldPoint& cp = contactManifold->getContactPoint(j);
getDebugDrawer()->drawContactPoint(cp.m_positionWorldOnB,cp.m_normalWorldOnB,cp.getDistance(),cp.getLifeTime(),defaultColors.m_contactPoint);
}
}
}
}
}
if (getDebugDrawer() && (getDebugDrawer()->getDebugMode() & (btIDebugDraw::DBG_DrawWireframe | btIDebugDraw::DBG_DrawAabb)))
{
int i;
for ( i=0;i<m_collisionObjects.size();i++)
if ((getDebugDrawer()->getDebugMode() & (btIDebugDraw::DBG_DrawWireframe | btIDebugDraw::DBG_DrawAabb)))
{
btCollisionObject* colObj = m_collisionObjects[i];
if ((colObj->getCollisionFlags() & btCollisionObject::CF_DISABLE_VISUALIZE_OBJECT)==0)
int i;
for ( i=0;i<m_collisionObjects.size();i++)
{
if (getDebugDrawer() && (getDebugDrawer()->getDebugMode() & btIDebugDraw::DBG_DrawWireframe))
btCollisionObject* colObj = m_collisionObjects[i];
if ((colObj->getCollisionFlags() & btCollisionObject::CF_DISABLE_VISUALIZE_OBJECT)==0)
{
btVector3 color(btScalar(1.),btScalar(1.),btScalar(1.));
switch(colObj->getActivationState())
if (getDebugDrawer() && (getDebugDrawer()->getDebugMode() & btIDebugDraw::DBG_DrawWireframe))
{
case ACTIVE_TAG:
color = btVector3(btScalar(1.),btScalar(1.),btScalar(1.)); break;
case ISLAND_SLEEPING:
color = btVector3(btScalar(0.),btScalar(1.),btScalar(0.));break;
case WANTS_DEACTIVATION:
color = btVector3(btScalar(0.),btScalar(1.),btScalar(1.));break;
case DISABLE_DEACTIVATION:
color = btVector3(btScalar(1.),btScalar(0.),btScalar(0.));break;
case DISABLE_SIMULATION:
color = btVector3(btScalar(1.),btScalar(1.),btScalar(0.));break;
default:
btVector3 color(btScalar(0.4),btScalar(0.4),btScalar(0.4));
switch(colObj->getActivationState())
{
color = btVector3(btScalar(1),btScalar(0.),btScalar(0.));
}
};
case ACTIVE_TAG:
color = defaultColors.m_activeObject; break;
case ISLAND_SLEEPING:
color = defaultColors.m_deactivatedObject;break;
case WANTS_DEACTIVATION:
color = defaultColors.m_wantsDeactivationObject;break;
case DISABLE_DEACTIVATION:
color = defaultColors.m_disabledDeactivationObject;break;
case DISABLE_SIMULATION:
color = defaultColors.m_disabledSimulationObject;break;
default:
{
color = btVector3(btScalar(.3),btScalar(0.3),btScalar(0.3));
}
};
debugDrawObject(colObj->getWorldTransform(),colObj->getCollisionShape(),color);
}
if (m_debugDrawer && (m_debugDrawer->getDebugMode() & btIDebugDraw::DBG_DrawAabb))
{
btVector3 minAabb,maxAabb;
btVector3 colorvec(1,0,0);
colObj->getCollisionShape()->getAabb(colObj->getWorldTransform(), minAabb,maxAabb);
btVector3 contactThreshold(gContactBreakingThreshold,gContactBreakingThreshold,gContactBreakingThreshold);
minAabb -= contactThreshold;
maxAabb += contactThreshold;
btVector3 minAabb2,maxAabb2;
if(getDispatchInfo().m_useContinuous && colObj->getInternalType()==btCollisionObject::CO_RIGID_BODY && !colObj->isStaticOrKinematicObject())
{
colObj->getCollisionShape()->getAabb(colObj->getInterpolationWorldTransform(),minAabb2,maxAabb2);
minAabb2 -= contactThreshold;
maxAabb2 += contactThreshold;
minAabb.setMin(minAabb2);
maxAabb.setMax(maxAabb2);
debugDrawObject(colObj->getWorldTransform(),colObj->getCollisionShape(),color);
}
if (m_debugDrawer && (m_debugDrawer->getDebugMode() & btIDebugDraw::DBG_DrawAabb))
{
btVector3 minAabb,maxAabb;
btVector3 colorvec = defaultColors.m_aabb;
colObj->getCollisionShape()->getAabb(colObj->getWorldTransform(), minAabb,maxAabb);
btVector3 contactThreshold(gContactBreakingThreshold,gContactBreakingThreshold,gContactBreakingThreshold);
minAabb -= contactThreshold;
maxAabb += contactThreshold;
m_debugDrawer->drawAabb(minAabb,maxAabb,colorvec);
btVector3 minAabb2,maxAabb2;
if(getDispatchInfo().m_useContinuous && colObj->getInternalType()==btCollisionObject::CO_RIGID_BODY && !colObj->isStaticOrKinematicObject())
{
colObj->getCollisionShape()->getAabb(colObj->getInterpolationWorldTransform(),minAabb2,maxAabb2);
minAabb2 -= contactThreshold;
maxAabb2 += contactThreshold;
minAabb.setMin(minAabb2);
maxAabb.setMax(maxAabb2);
}
m_debugDrawer->drawAabb(minAabb,maxAabb,colorvec);
}
}
}
}
}
}

View File

@@ -21,6 +21,7 @@ subject to the following restrictions:
#include "btTransform.h"
///The btIDebugDraw interface class allows hooking up a debug renderer to visually debug simulations.
///Typical use case: create a debug drawer object, and assign it to a btCollisionWorld or btDynamicsWorld using setDebugDrawer and call debugDrawWorld.
///A class that implements the btIDebugDraw interface has to implement the drawLine method at a minimum.
@@ -29,6 +30,29 @@ class btIDebugDraw
{
public:
ATTRIBUTE_ALIGNED16(struct) DefaultColors
{
btVector3 m_activeObject;
btVector3 m_deactivatedObject;
btVector3 m_wantsDeactivationObject;
btVector3 m_disabledDeactivationObject;
btVector3 m_disabledSimulationObject;
btVector3 m_aabb;
btVector3 m_contactPoint;
DefaultColors()
: m_activeObject(1,1,1),
m_deactivatedObject(0,1,0),
m_wantsDeactivationObject(0,1,1),
m_disabledDeactivationObject(1,0,0),
m_disabledSimulationObject(1,1,0),
m_aabb(1,0,0),
m_contactPoint(1,1,0)
{
}
};
enum DebugDrawModes
{
DBG_NoDebug=0,
@@ -53,6 +77,11 @@ class btIDebugDraw
virtual ~btIDebugDraw() {};
virtual DefaultColors getDefaultColors() const { DefaultColors colors; return colors; }
///the default implementation for setDefaultColors has no effect. A derived class can implement it and store the colors.
virtual void setDefaultColors(const DefaultColors& /*colors*/) {}
virtual void drawLine(const btVector3& from,const btVector3& to,const btVector3& color)=0;
virtual void drawLine(const btVector3& from,const btVector3& to, const btVector3& fromColor, const btVector3& toColor)