From 095f5f42a9a1f12376fde31b253b6bcf43a40b56 Mon Sep 17 00:00:00 2001 From: ejcoumans Date: Sun, 21 Oct 2007 04:22:43 +0000 Subject: [PATCH] allow some existing demos to run in the TestFrameWork --- Demos/BasicDemo/BasicDemo.cpp | 16 ------ Demos/BasicDemo/BasicDemo.h | 3 +- Demos/BasicDemo/main.cpp | 36 ++++++++++++ Demos/BspDemo/BspDemo.cpp | 37 +----------- Demos/BspDemo/main.cpp | 54 ++++++++++++++++++ Demos/CcdPhysicsDemo/CcdPhysicsDemo.cpp | 27 ++++----- Demos/CcdPhysicsDemo/main.cpp | 29 ++++++++++ Examples/TestBed/FrameWork/Jamfile | 2 +- Examples/TestBed/Jamfile | 2 +- Examples/TestBed/Tests/CollisionProcessing.h | 2 +- Examples/TestBed/Tests/TestEntries.cpp | 59 +++++++++++++++++++- 11 files changed, 192 insertions(+), 75 deletions(-) create mode 100644 Demos/BasicDemo/main.cpp create mode 100644 Demos/BspDemo/main.cpp create mode 100644 Demos/CcdPhysicsDemo/main.cpp diff --git a/Demos/BasicDemo/BasicDemo.cpp b/Demos/BasicDemo/BasicDemo.cpp index e06a4964b..465b0ee19 100644 --- a/Demos/BasicDemo/BasicDemo.cpp +++ b/Demos/BasicDemo/BasicDemo.cpp @@ -16,7 +16,6 @@ subject to the following restrictions: #define USE_GROUND_BOX 1 //#define PRINT_CONTACT_STATISTICS 1 -//#define CHECK_MEMORY_LEAKS 1 //#define USE_PARALLEL_DISPATCHER 1 #define START_POS_X -5 @@ -65,22 +64,7 @@ class myTest -int main(int argc,char** argv) -{ - BasicDemo ccdDemo; - ccdDemo.initPhysics(); - ccdDemo.setCameraDistance(btScalar(50.)); - -#ifdef CHECK_MEMORY_LEAKS - ccdDemo.exitPhysics(); -#else - return glutmain(argc, argv,640,480,"Bullet Physics Demo. http://bullet.sf.net",&ccdDemo); -#endif - - //default glut doesn't return from mainloop - return 0; -} diff --git a/Demos/BasicDemo/BasicDemo.h b/Demos/BasicDemo/BasicDemo.h index 4b06629d6..b7b622b01 100644 --- a/Demos/BasicDemo/BasicDemo.h +++ b/Demos/BasicDemo/BasicDemo.h @@ -16,8 +16,9 @@ subject to the following restrictions: #define BASIC_DEMO_H #include "DemoApplication.h" +#include "LinearMath/btAlignedObjectArray.h" - +class btBroadphaseInterface; class btCollisionShape; class btOverlappingPairCache; class btCollisionDispatcher; diff --git a/Demos/BasicDemo/main.cpp b/Demos/BasicDemo/main.cpp new file mode 100644 index 000000000..4118c90df --- /dev/null +++ b/Demos/BasicDemo/main.cpp @@ -0,0 +1,36 @@ +/* +Bullet Continuous Collision Detection and Physics Library +Copyright (c) 2003-2007 Erwin Coumans http://continuousphysics.com/Bullet/ + +This software is provided 'as-is', without any express or implied warranty. +In no event will the authors be held liable for any damages arising from the use of this software. +Permission is granted to anyone to use this software for any purpose, +including commercial applications, and to alter it and redistribute it freely, +subject to the following restrictions: + +1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. +2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. +3. This notice may not be removed or altered from any source distribution. +*/ + +#include "BasicDemo.h" +#include "GlutStuff.h" + +//#define CHECK_MEMORY_LEAKS 1 + +int main(int argc,char** argv) +{ + + BasicDemo ccdDemo; + ccdDemo.initPhysics(); + ccdDemo.setCameraDistance(btScalar(50.)); + +#ifdef CHECK_MEMORY_LEAKS + ccdDemo.exitPhysics(); +#else + return glutmain(argc, argv,640,480,"Bullet Physics Demo. http://bullet.sf.net",&ccdDemo); +#endif + + //default glut doesn't return from mainloop + return 0; +} \ No newline at end of file diff --git a/Demos/BspDemo/BspDemo.cpp b/Demos/BspDemo/BspDemo.cpp index dcf4d2441..8ba38b3e2 100644 --- a/Demos/BspDemo/BspDemo.cpp +++ b/Demos/BspDemo/BspDemo.cpp @@ -31,7 +31,7 @@ subject to the following restrictions: #include "BMF_Api.h" #include //printf debugging -float deltaTime = 1.f/60.f; + #include "BspDemo.h" #include "GL_ShapeDrawer.h" #include "GlutStuff.h" @@ -85,41 +85,9 @@ public: -GLDebugDrawer debugDrawer; - -char* makeExeToBspFilename(const char* lpCmdLine); -char* getLastFileName(); -int main(int argc,char** argv) -{ - BspDemo* bspDemo = new BspDemo(); - - const char* bspfilename = "BspDemo.bsp"; - - printf("argc=%i\n",argc); - { - for (int i=0;i1) - { - bspfilename = argv[1]; - } - - // Enrico: TODO: Should change parameter type of initPhysics() to std::string or at least const char * - bspDemo->initPhysics((char*)bspfilename); - - bspDemo->setCameraDistance(22.f); - - return glutmain(argc, argv,640,480,"Bullet Quake BSP Physics Viewer http://bullet.sourceforge.net",bspDemo); -} BspDemo::~BspDemo() { @@ -147,7 +115,6 @@ void BspDemo::initPhysics(char* bspfilename) m_dynamicsWorld = new btDiscreteDynamicsWorld(dispatcher,pairCache,constraintSolver,collisionConfiguration); m_dynamicsWorld->setGravity(-m_cameraUp * 10); - m_dynamicsWorld->setDebugDrawer(&debugDrawer); #ifdef QUAKE_BSP_IMPORTING @@ -225,8 +192,6 @@ void BspDemo::displayCallback(void) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - //m_dynamicsWorld->UpdateAabbs(deltaTime); - renderme(); diff --git a/Demos/BspDemo/main.cpp b/Demos/BspDemo/main.cpp new file mode 100644 index 000000000..46e9f32e3 --- /dev/null +++ b/Demos/BspDemo/main.cpp @@ -0,0 +1,54 @@ +/* +Bullet Continuous Collision Detection and Physics Library +Copyright (c) 2003-2007 Erwin Coumans http://continuousphysics.com/Bullet/ + +This software is provided 'as-is', without any express or implied warranty. +In no event will the authors be held liable for any damages arising from the use of this software. +Permission is granted to anyone to use this software for any purpose, +including commercial applications, and to alter it and redistribute it freely, +subject to the following restrictions: + +1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. +2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. +3. This notice may not be removed or altered from any source distribution. +*/ + + +#include "BspDemo.h" +#include "GlutStuff.h" +#include "GLDebugDrawer.h" + +char* makeExeToBspFilename(const char* lpCmdLine); +char* getLastFileName(); + + +int main(int argc,char** argv) +{ + + BspDemo* bspDemo = new BspDemo(); + + const char* bspfilename = "BspDemo.bsp"; + + printf("argc=%i\n",argc); + { + for (int i=0;i1) + { + bspfilename = argv[1]; + } + + // Enrico: TODO: Should change parameter type of initPhysics() to std::string or at least const char * + bspDemo->initPhysics((char*)bspfilename); + + bspDemo->setCameraDistance(22.f); + + return glutmain(argc, argv,640,480,"Bullet Quake BSP Physics Viewer http://bullet.sourceforge.net",bspDemo); +} + diff --git a/Demos/CcdPhysicsDemo/CcdPhysicsDemo.cpp b/Demos/CcdPhysicsDemo/CcdPhysicsDemo.cpp index 9720bc8cf..d8dee3887 100644 --- a/Demos/CcdPhysicsDemo/CcdPhysicsDemo.cpp +++ b/Demos/CcdPhysicsDemo/CcdPhysicsDemo.cpp @@ -71,7 +71,6 @@ subject to the following restrictions: #include "BMF_Api.h" #include //printf debugging -float deltaTime = 1.f/60.f; float gCollisionMargin = 0.05f; #include "CcdPhysicsDemo.h" #include "GL_ShapeDrawer.h" @@ -172,6 +171,11 @@ void CcdPhysicsDemo::createStack( btCollisionShape* boxShape, float halfCubeSize btRigidBody* body = 0; body = localCreateRigidBody(mass,trans,boxShape); +#ifdef USER_DEFINED_FRICTION_MODEL + ///Advanced use: override the friction solver + body->m_frictionSolverType = USER_CONTACT_SOLVER_TYPE1; +#endif //USER_DEFINED_FRICTION_MODEL + } } } @@ -220,25 +224,10 @@ void customNearCallback(btBroadphasePair& collisionPair, btCollisionDispatcher& -GLDebugDrawer debugDrawer; //experimental jitter damping (1 = no damping, 0 = total damping once motion below threshold) extern btScalar gJitterVelocityDampingFactor; -int main(int argc,char** argv) -{ - gJitterVelocityDampingFactor = 0.7; - - CcdPhysicsDemo* ccdDemo = new CcdPhysicsDemo(); - - ccdDemo->initPhysics(); - -#ifdef DO_BENCHMARK_PYRAMIDS - ccdDemo->setCameraDistance(26.f); -#endif - - return glutmain(argc, argv,640,480,"Bullet Physics Demo. http://bullet.sf.net",ccdDemo); -} @@ -371,6 +360,11 @@ float myFrictionModel( btRigidBody& body1, btRigidBody& body2, btManifoldPoint& void CcdPhysicsDemo::initPhysics() { + +#ifdef DO_BENCHMARK_PYRAMIDS + setCameraDistance(2.5f); +#endif + #ifdef DO_BENCHMARK_PYRAMIDS m_azi = 90.f; #endif //DO_BENCHMARK_PYRAMIDS @@ -487,7 +481,6 @@ int maxNumOutstandingTasks = 4; m_dynamicsWorld->getDispatchInfo().m_enableSPU = true; m_dynamicsWorld->setGravity(btVector3(0,-10,0)); - m_dynamicsWorld->setDebugDrawer(&debugDrawer); #ifdef USER_DEFINED_FRICTION_MODEL diff --git a/Demos/CcdPhysicsDemo/main.cpp b/Demos/CcdPhysicsDemo/main.cpp new file mode 100644 index 000000000..4bbcfab19 --- /dev/null +++ b/Demos/CcdPhysicsDemo/main.cpp @@ -0,0 +1,29 @@ +/* +Bullet Continuous Collision Detection and Physics Library +Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/ + +This software is provided 'as-is', without any express or implied warranty. +In no event will the authors be held liable for any damages arising from the use of this software. +Permission is granted to anyone to use this software for any purpose, +including commercial applications, and to alter it and redistribute it freely, +subject to the following restrictions: + +1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. +2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. +3. This notice may not be removed or altered from any source distribution. +*/ + +#include "CcdPhysicsDemo.h" +#include "GlutStuff.h" + + +int main(int argc,char** argv) +{ + + CcdPhysicsDemo* ccdDemo = new CcdPhysicsDemo(); + + ccdDemo->initPhysics(); + + + return glutmain(argc, argv,640,480,"Bullet Physics Demo. http://bullet.sf.net",ccdDemo); +} diff --git a/Examples/TestBed/FrameWork/Jamfile b/Examples/TestBed/FrameWork/Jamfile index 5409e131f..86bc1f7a7 100644 --- a/Examples/TestBed/FrameWork/Jamfile +++ b/Examples/TestBed/FrameWork/Jamfile @@ -1,3 +1,3 @@ SubDir TOP Examples TestBed Framework ; -BulletDemo FrameWork : [ Wildcard *.h *.cpp ] ; +FrameWorkDemo FrameWork : [ Wildcard *.h *.cpp ] ; diff --git a/Examples/TestBed/Jamfile b/Examples/TestBed/Jamfile index 10caa1b50..82034b83d 100644 --- a/Examples/TestBed/Jamfile +++ b/Examples/TestBed/Jamfile @@ -3,7 +3,7 @@ SubDir TOP Examples TestBed ; if $(GLUT.AVAILABLE) = "yes" { # All demo apps have a lot in common, so use this rule to simply things - rule BulletDemo + rule FrameWorkDemo { Application $(<) : $(>) : noinstall console nomanifest ; LinkWith $(<) : Tests bulletdynamics bulletcollision bulletmath glui ; diff --git a/Examples/TestBed/Tests/CollisionProcessing.h b/Examples/TestBed/Tests/CollisionProcessing.h index 10aaeefb9..15b41f957 100644 --- a/Examples/TestBed/Tests/CollisionProcessing.h +++ b/Examples/TestBed/Tests/CollisionProcessing.h @@ -6,7 +6,7 @@ class CollisionProcessing : public Test { public: -void Step(Settings* settings) +void Step(const Settings* settings) { } diff --git a/Examples/TestBed/Tests/TestEntries.cpp b/Examples/TestBed/Tests/TestEntries.cpp index 923028221..4b2c9f0f0 100644 --- a/Examples/TestBed/Tests/TestEntries.cpp +++ b/Examples/TestBed/Tests/TestEntries.cpp @@ -3,8 +3,63 @@ #include "../FrameWork/Test.h" #include "CollisionProcessing.h" -TestEntry g_testEntries[] = +#include "../../Demos/CcdPhysicsDemo/CcdPhysicsDemo.h" + +class CcdPhysicsTest : public Test { - {"Collision Processing", CollisionProcessing::Create} + CcdPhysicsDemo* m_demo; + CcdPhysicsTest() + { + m_demo = new CcdPhysicsDemo(); + m_demo->initPhysics(); + } + virtual ~CcdPhysicsTest() + { + delete m_demo; + } +public: + void Step(const Settings* settings) + { + m_demo->clientMoveAndDisplay(); + } + static Test* Create() + { + return new CcdPhysicsTest; + } +}; + +#include "../../Demos/BspDemo/BspDemo.h" + +class BspDemoTest : public Test +{ + BspDemo* m_demo; + + BspDemoTest() + { + m_demo = new BspDemo(); + m_demo->initPhysics("BspDemo.bsp"); + } + virtual ~BspDemoTest() + { + delete m_demo; + } +public: + void Step(const Settings* settings) + { + m_demo->clientMoveAndDisplay(); + } + static Test* Create() + { + return new BspDemoTest; + } +}; + + +TestEntry g_testEntries[] = +{ + {"CcdPhysics Test", CcdPhysicsTest::Create}, + {"BspDemo Test", BspDemoTest::Create}, + {"Collision Processing", CollisionProcessing::Create}, + {0, 0} };