Make BenchmarkDemo a console application, without OpenGL/Glut dependency.

Fix potential division by zero when enabling convex distance utility.
Thanks to linzner http://code.google.com/p/bullet/issues/detail?id=264
This commit is contained in:
erwin.coumans
2009-08-12 08:18:57 +00:00
parent ae3255f5e9
commit e89fe1cbfa
17 changed files with 152 additions and 90 deletions

View File

@@ -16,10 +16,11 @@ subject to the following restrictions:
// Collision Radius
#define COLLISION_RADIUS 0.0f
#include "BenchmarkDemo.h"
#ifdef USE_GLUT_DEMO_APPLICATION
#include "GlutStuff.h"
#endif //USE_GLUT_DEMO_APPLICATION
///btBulletDynamicsCommon.h is the main Bullet include file, contains most common include files.
#include "btBulletDynamicsCommon.h"
#include <stdio.h> //printf debugging
@@ -177,6 +178,7 @@ public:
void draw ()
{
#ifdef USE_GLUT_DEMO_APPLICATION
glDisable (GL_LIGHTING);
glColor3f (0.0, 1.0, 0.0);
glBegin (GL_LINES);
@@ -204,6 +206,8 @@ public:
}
glEnd ();
glEnable (GL_LIGHTING);
#endif //USE_GLUT_DEMO_APPLICATION
}
};
@@ -213,7 +217,9 @@ static btRaycastBar2 raycastBar;
void BenchmarkDemo::clientMoveAndDisplay()
{
#ifdef USE_GLUT_DEMO_APPLICATION
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
#endif //USE_GLUT_DEMO_APPLICATION
//simple dynamics world doesn't handle fixed-time-stepping
float ms = getDeltaTimeMicroseconds();
@@ -236,16 +242,20 @@ void BenchmarkDemo::clientMoveAndDisplay()
renderme();
#ifdef USE_GLUT_DEMO_APPLICATION
glFlush();
glutSwapBuffers();
#endif //USE_GLUT_DEMO_APPLICATION
}
void BenchmarkDemo::displayCallback(void) {
void BenchmarkDemo::displayCallback(void)
{
#ifdef USE_GLUT_DEMO_APPLICATION
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
renderme();
@@ -256,6 +266,7 @@ void BenchmarkDemo::displayCallback(void) {
glFlush();
glutSwapBuffers();
#endif //USE_GLUT_DEMO_APPLICATION
}
@@ -1213,5 +1224,26 @@ void BenchmarkDemo::exitPhysics()
#ifndef USE_GLUT_DEMO_APPLICATION
btRigidBody* DemoApplication::localCreateRigidBody(float mass, const btTransform& startTransform,btCollisionShape* shape)
{
btAssert((!shape || shape->getShapeType() != INVALID_SHAPE_PROXYTYPE));
//rigidbody is dynamic if and only if mass is non zero, otherwise static
bool isDynamic = (mass != 0.f);
btVector3 localInertia(0,0,0);
if (isDynamic)
shape->calculateLocalInertia(mass,localInertia);
//using motionstate is recommended, it provides interpolation capabilities, and only synchronizes 'active' objects
btRigidBody* body = new btRigidBody(mass,0,shape,localInertia);
body->setWorldTransform(startTransform);
m_dynamicsWorld->addRigidBody(body);
return body;
}
#endif //USE_GLUT_DEMO_APPLICATION

View File

@@ -15,10 +15,15 @@ subject to the following restrictions:
#ifndef BENCHMARK_DEMO_H
#define BENCHMARK_DEMO_H
#include "GlutDemoApplication.h"
#include "LinearMath/btAlignedObjectArray.h"
#include "LinearMath/btTransform.h"
class btDynamicsWorld;
#define NUMRAYS 500
class btRigidBody;
class btBroadphaseInterface;
class btCollisionShape;
class btOverlappingPairCache;
@@ -27,8 +32,39 @@ class btConstraintSolver;
struct btCollisionAlgorithmCreateFunc;
class btDefaultCollisionConfiguration;
#ifndef USE_GLUT_DEMO_APPLICATION
///empty placeholder
class DemoApplication
{
protected:
btDynamicsWorld* m_dynamicsWorld;
public:
virtual void myinit() {}
virtual btDynamicsWorld* getDynamicsWorld()
{
return m_dynamicsWorld;
}
btScalar getDeltaTimeMicroseconds()
{
return 1.f;
}
void renderme() {}
void setCameraDistance(btScalar dist){}
void clientResetScene(){}
btRigidBody* localCreateRigidBody(float mass, const btTransform& startTransform,btCollisionShape* shape);
};
///BenchmarkDemo is provides several performance tests
class BenchmarkDemo : public DemoApplication
#else
#include "GlutDemoApplication.h"
class BenchmarkDemo : public GlutDemoApplication
#endif
{
//keep the collision shapes, for deletion/cleanup

View File

@@ -15,7 +15,7 @@ ${BULLET_PHYSICS_SOURCE_DIR}/src ${BULLET_PHYSICS_SOURCE_DIR}/Demos/OpenGL }
)
LINK_LIBRARIES(
OpenGLSupport BulletDynamics BulletCollision LinearMath ${GLUT_glut_LIBRARY} ${OPENGL_gl_LIBRARY} ${OPENGL_glu_LIBRARY}
BulletDynamics BulletCollision LinearMath
)
ADD_EXECUTABLE(AppBenchmarks

View File

@@ -1,3 +1,3 @@
SubDir TOP Demos Benchmarks ;
BulletDemo Benchmarks : [ Wildcard *.h *.cpp ] ;
BulletBasicDemo Benchmarks : [ Wildcard *.h *.cpp ] ;

View File

@@ -14,32 +14,70 @@ subject to the following restrictions:
*/
#include "BenchmarkDemo.h"
#include "GlutStuff.h"
#include "GLDebugDrawer.h"
#include "btBulletDynamicsCommon.h"
#include "LinearMath/btHashMap.h"
#include <stdio.h>
#ifdef USE_GLUT_DEMO_APPLICATION
#include "GlutStuff.h"
#include "GLDebugDrawer.h"
GLDebugDrawer gDebugDrawer;
#endif //USE_GLUT_DEMO_APPLICATION
#define NUM_DEMOS 7
#define NUM_TESTS 650
extern bool gDisableDeactivation;
int main(int argc,char** argv)
{
GLDebugDrawer gDebugDrawer;
gDisableDeactivation = true;
// BenchmarkDemo1 benchmarkDemo;
// BenchmarkDemo2 benchmarkDemo;
// BenchmarkDemo3 benchmarkDemo;
BenchmarkDemo4 benchmarkDemo;
// BenchmarkDemo5 benchmarkDemo;
// BenchmarkDemo6 benchmarkDemo;
// BenchmarkDemo7 benchmarkDemo;
BenchmarkDemo1 benchmarkDemo1;
BenchmarkDemo2 benchmarkDemo2;
BenchmarkDemo3 benchmarkDemo3;
BenchmarkDemo4 benchmarkDemo4;
BenchmarkDemo5 benchmarkDemo5;
BenchmarkDemo6 benchmarkDemo6;
BenchmarkDemo7 benchmarkDemo7;
BenchmarkDemo* demoArray[NUM_DEMOS] = {&benchmarkDemo1,&benchmarkDemo2,&benchmarkDemo3,&benchmarkDemo4,&benchmarkDemo5,&benchmarkDemo6,&benchmarkDemo7};
char* demoNames[NUM_DEMOS] = {"3000 fall", "1000 stack", "136 ragdolls","1000 convex", "prim-trimesh", "convex-trimesh","raytests"};
float totalTime[NUM_DEMOS] = {0.f,0.f,0.f,0.f,0.f,0.f,0.f};
benchmarkDemo.initPhysics();
#ifdef USE_GLUT_DEMO_APPLICATION
benchmarkDemo.getDynamicsWorld()->setDebugDrawer(&gDebugDrawer);
return glutmain(argc, argv,640,480,"Bullet Physics Demo. http://bulletphysics.com",&benchmarkDemo);
//default glut doesn't return from mainloop
#else
int d;
for (d=0;d<NUM_DEMOS;d++)
{
demoArray[d]->initPhysics();
for (int i=0;i<NUM_TESTS;i++)
{
demoArray[d]->clientMoveAndDisplay();
float frameTime = CProfileManager::Get_Time_Since_Reset();
if ((i % 25)==0)
{
printf("BenchmarkDemo: %s, Frame %d, Duration (ms): %f\n",demoNames[d],i,frameTime);
}
totalTime[d] += frameTime;
if (i==NUM_TESTS-1)
CProfileManager::dumpAll();
}
}
for (d=0;d<NUM_DEMOS;d++)
{
printf("\nResults for %s: %f",demoNames[d],totalTime[d]*(1.f/NUM_TESTS));
}
#endif
return 0;
}