demo for testing GIMPACT 0.3, thanks to Francisco Leon for the update. GIMPACT demo/build system will be fixed today.

This commit is contained in:
ejcoumans
2007-09-30 00:09:32 +00:00
parent 65b9fbe16e
commit fcfdb96e54
4 changed files with 821 additions and 656 deletions

View File

@@ -1376,4 +1376,4 @@ int gIndicesBunny[BUNNY_NUM_TRIANGLES][3] = {
//***************************THE END OF FAMOUS BUNNY TRIMESH********************************************// //***************************THE END OF FAMOUS BUNNY TRIMESH********************************************//
#endif //BUNNY_MESH_H_ #endif //BUNNY_MESH_H_

View File

@@ -16,14 +16,16 @@ subject to the following restrictions:
#include "btBulletDynamicsCommon.h" #include "btBulletDynamicsCommon.h"
#include "GimpactTestDemo.h" #include "GimpactTestDemo.h"
#define SHOW_NUM_DEEP_PENETRATIONS
#include "LinearMath/btDefaultMotionState.h" #include "LinearMath/btDefaultMotionState.h"
#include "LinearMath/btIDebugDraw.h" #include "LinearMath/btIDebugDraw.h"
#include "LinearMath/btQuickprof.h" #include "LinearMath/btQuickprof.h"
#include "LinearMath/btDefaultMotionState.h" #include "LinearMath/btDefaultMotionState.h"
/// Including GIMPACT here /// Including GIMPACT here
#include "GIMPACT/Bullet/btGImpactShape.h"
#include "GIMPACT/Bullet/btGImpactCollisionAlgorithm.h"
#include "BMF_Api.h" #include "BMF_Api.h"
@@ -32,10 +34,17 @@ subject to the following restrictions:
#include "GL_ShapeDrawer.h" #include "GL_ShapeDrawer.h"
#include "GlutStuff.h" #include "GlutStuff.h"
/// Include Torus Mesh here /// Include Torus Mesh here
#include "TorusMesh.h" #include "TorusMesh.h"
#include "BunnyMesh.h" #include "BunnyMesh.h"
#ifdef SHOW_NUM_DEEP_PENETRATIONS
extern int gNumDeepPenetrationChecks;
extern int gNumGjkChecks;
#endif //
GLDebugDrawer debugDrawer; GLDebugDrawer debugDrawer;
//Real dts = 0.000001f; //Real dts = 0.000001f;
Real dts = 1.0 / 60.0; Real dts = 1.0 / 60.0;
@@ -43,10 +52,10 @@ Real dts = 1.0 / 60.0;
///************************************************************************************** ///**************************************************************************************
/// GIMPACT Test Demo made by DevO /// GIMPACT Test Demo made by DevO
/// ///
///************************************************************************************** ///**************************************************************************************
#define TEST_GIMPACT_TORUS
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
///User can override this material combiner by implementing gContactAddedCallback and setting body0->m_collisionFlags |= btCollisionObject::customMaterialCallback; ///User can override this material combiner by implementing gContactAddedCallback and setting body0->m_collisionFlags |= btCollisionObject::customMaterialCallback;
@@ -130,7 +139,7 @@ void GimpactConcaveDemo::renderme()
{ {
updateCamera(); updateCamera();
btScalar m[16]; btScalar m[16];
if (m_dynamicsWorld) if (m_dynamicsWorld)
@@ -255,6 +264,21 @@ void GimpactConcaveDemo::renderme()
BMF_DrawString(BMF_GetFont(BMF_kHelvetica10),buf); BMF_DrawString(BMF_GetFont(BMF_kHelvetica10),buf);
yStart += yIncr; yStart += yIncr;
#ifdef SHOW_NUM_DEEP_PENETRATIONS
glRasterPos3f(xOffset,yStart,0);
sprintf(buf,"gNumDeepPenetrationChecks = %d",gNumDeepPenetrationChecks);
BMF_DrawString(BMF_GetFont(BMF_kHelvetica10),buf);
yStart += yIncr;
glRasterPos3f(xOffset,yStart,0);
sprintf(buf,"gNumGjkChecks= %d",gNumGjkChecks);
BMF_DrawString(BMF_GetFont(BMF_kHelvetica10),buf);
yStart += yIncr;
#endif //SHOW_NUM_DEEP_PENETRATIONS
resetPerspectiveProjection(); resetPerspectiveProjection();
@@ -274,11 +298,29 @@ void GimpactConcaveDemo::initGImpactCollision()
NUM_VERTICES, NUM_VERTICES,
(Real*) &gVertices[0],sizeof(Real)*3); (Real*) &gVertices[0],sizeof(Real)*3);
btGImpactMeshShape * trimesh = new btGImpactMeshShape(m_indexVertexArrays); #ifdef BULLET_GIMPACT
trimesh->setLocalScaling(btVector3(1.f,1.f,1.f)); #ifdef BULLET_GIMPACT_CONVEX_DECOMPOSITION
trimesh->updateBound(); btGImpactConvexDecompositionShape * trimesh = new
trimesh->setMargin(0.01); ///????? btGImpactConvexDecompositionShape(
m_indexVertexArrays, btVector3(1.f,1.f,1.f),btScalar(0.01));
trimesh->updateBound();
#else
btGImpactMeshShape * trimesh = new btGImpactMeshShape(m_indexVertexArrays);
trimesh->setLocalScaling(btVector3(1.f,1.f,1.f));
#ifdef BULLET_TRIANGLE_COLLISION
trimesh->setMargin(0.07f); ///?????
#else
trimesh->setMargin(0.0f);
#endif
trimesh->updateBound();
#endif
m_trimeshShape = trimesh; m_trimeshShape = trimesh;
#else
m_trimeshShape = new btGIMPACTMeshData(m_indexVertexArrays);
#endif
} }
/// Create Bunny Shape /// Create Bunny Shape
@@ -289,32 +331,73 @@ void GimpactConcaveDemo::initGImpactCollision()
3*sizeof(int), 3*sizeof(int),
BUNNY_NUM_VERTICES, BUNNY_NUM_VERTICES,
(Real*) &gVerticesBunny[0],sizeof(Real)*3); (Real*) &gVerticesBunny[0],sizeof(Real)*3);
#ifdef BULLET_GIMPACT
#ifdef BULLET_GIMPACT_CONVEX_DECOMPOSITION
btGImpactConvexDecompositionShape * trimesh2 = new
btGImpactConvexDecompositionShape(
m_indexVertexArrays2, btVector3(4.f,4.f,4.f),btScalar(0.01));
trimesh2->updateBound();
#else
btGImpactMeshShape * trimesh2 = new btGImpactMeshShape(m_indexVertexArrays2);
trimesh2->setLocalScaling(btVector3(4.f,4.f,4.f));
#ifdef BULLET_TRIANGLE_COLLISION
trimesh2->setMargin(0.07f); ///?????
#else
trimesh2->setMargin(0.0f);
#endif
trimesh2->updateBound();
#endif
btGImpactMeshShape * trimesh2 = new btGImpactMeshShape(m_indexVertexArrays2);
trimesh2->setLocalScaling(btVector3(4.f,4.f,4.f));
trimesh2->updateBound();
trimesh2->setMargin(0.01); ///?????
m_trimeshShape2 = trimesh2; m_trimeshShape2 = trimesh2;
#else
m_trimeshShape2 = new btGIMPACTMeshData(m_indexVertexArrays2);
#endif
} }
///register GIMPACT algorithm ///register GIMPACT algorithm
btCollisionDispatcher * dispatcher = static_cast<btCollisionDispatcher *>(m_dynamicsWorld ->getDispatcher()); btCollisionDispatcher * dispatcher = static_cast<btCollisionDispatcher *>(m_dynamicsWorld ->getDispatcher());
{
//btGImpactCollisionAlgorithm::registerAlgorithm(dispatcher); /// Register GIMPACT !!! #ifdef BULLET_GIMPACT
if(!m_gimpactCollisionCreateFunc) m_gimpactCollisionCreateFunc = new btGImpactCollisionAlgorithm::CreateFunc; /// NEW btGImpactCollisionAlgorithm::registerAlgorithm(dispatcher);
#else
for (GUINT i = 0;i < MAX_BROADPHASE_COLLISION_TYPES ;i++ ) btConcaveConcaveCollisionAlgorithm::registerAlgorithm(dispatcher);
{ #endif
m_dispatcher->registerCollisionCreateFunc(GIMPACT_SHAPE_PROXYTYPE,i ,m_gimpactCollisionCreateFunc);
} // {
for (GUINT i = 0;i < MAX_BROADPHASE_COLLISION_TYPES ;i++ ) // //btGImpactCollisionAlgorithm::registerAlgorithm(dispatcher); /// Register GIMPACT !!!
{ // if(!m_gimpactCollisionCreateFunc) m_gimpactCollisionCreateFunc = new btGImpactCollisionAlgorithm::CreateFunc; /// NEW
m_dispatcher->registerCollisionCreateFunc(i,GIMPACT_SHAPE_PROXYTYPE ,m_gimpactCollisionCreateFunc); //
} // for (int i = 0;i < MAX_BROADPHASE_COLLISION_TYPES ;i++ )
} // {
// m_dispatcher->registerCollisionCreateFunc(GIMPACT_SHAPE_PROXYTYPE,i ,m_gimpactCollisionCreateFunc);
// }
// for (int i = 0;i < MAX_BROADPHASE_COLLISION_TYPES ;i++ )
// {
// m_dispatcher->registerCollisionCreateFunc(i,GIMPACT_SHAPE_PROXYTYPE ,m_gimpactCollisionCreateFunc);
// }
// }
} }
#ifndef BULLET_GIMPACT
btCollisionShape * GimpactConcaveDemo::createTorusShape()
{
btGIMPACTMeshShape * newtrimeshShape = new btGIMPACTMeshShape(m_trimeshShape);
newtrimeshShape->setLocalScaling(btVector3(1.f,1.f,1.f));
return newtrimeshShape;
}
btCollisionShape * GimpactConcaveDemo::createBunnyShape()
{
btGIMPACTMeshShape * newtrimeshShape = new btGIMPACTMeshShape(m_trimeshShape2);
newtrimeshShape->setLocalScaling(btVector3(4.f,4.f,4.f));
return newtrimeshShape;
}
#endif
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
void GimpactConcaveDemo::initPhysics() void GimpactConcaveDemo::initPhysics()
{ {
@@ -325,7 +408,7 @@ void GimpactConcaveDemo::initPhysics()
//btOverlappingPairCache* broadphase = new btSimpleBroadphase(); //btOverlappingPairCache* broadphase = new btSimpleBroadphase();
//m_broadphase = new btSimpleBroadphase(); //m_broadphase = new btSimpleBroadphase();
int maxProxies = 1024; LONG maxProxies = 1024;
btVector3 worldAabbMin(-10000,-10000,-10000); btVector3 worldAabbMin(-10000,-10000,-10000);
btVector3 worldAabbMax( 10000, 10000, 10000); btVector3 worldAabbMax( 10000, 10000, 10000);
m_broadphase = new bt32BitAxisSweep3(worldAabbMin,worldAabbMax,maxProxies); m_broadphase = new bt32BitAxisSweep3(worldAabbMin,worldAabbMax,maxProxies);
@@ -365,7 +448,7 @@ void GimpactConcaveDemo::initPhysics()
startTransform.setOrigin(btVector3(0,15,-200)); startTransform.setOrigin(btVector3(0,15,-200));
staticScenario->addChildShape(startTransform,staticboxShape5); staticScenario->addChildShape(startTransform,staticboxShape5);
startTransform.setOrigin(btVector3(0,-10,0)); startTransform.setOrigin(btVector3(0,0,0));
btRigidBody* staticBody = localCreateRigidBody(mass, startTransform,staticScenario); btRigidBody* staticBody = localCreateRigidBody(mass, startTransform,staticScenario);
@@ -377,29 +460,47 @@ void GimpactConcaveDemo::initPhysics()
//static plane //static plane
/*
btVector3 normal(0.4,1.5,-0.4); btVector3 normal(-0.5,0.5,0.0);
normal.normalize(); normal.normalize();
btCollisionShape* staticplaneShape6 = new btStaticPlaneShape(normal,0.0);// A plane btCollisionShape* staticplaneShape6 = new btStaticPlaneShape(normal,0.0);// A plane
startTransform.setOrigin(btVector3(0,-20,0)); startTransform.setOrigin(btVector3(0,-9,0));
btRigidBody* staticBody2 = localCreateRigidBody(mass, startTransform,staticplaneShape6 ); btRigidBody* staticBody2 = localCreateRigidBody(mass, startTransform,staticplaneShape6 );
staticBody2->setCollisionFlags(staticBody2->getCollisionFlags()|btCollisionObject::CF_STATIC_OBJECT); staticBody2->setCollisionFlags(staticBody2->getCollisionFlags()|btCollisionObject::CF_STATIC_OBJECT);
staticBody2->setActivationState(ISLAND_SLEEPING); staticBody2->setActivationState(ISLAND_SLEEPING);
*/
//another static plane
normal.setValue(0.5,0.7,0.0);
//normal.normalize();
btCollisionShape* staticplaneShape7 = new btStaticPlaneShape(normal,0.0);// A plane
startTransform.setOrigin(btVector3(0,-10,0));
staticBody2 = localCreateRigidBody(mass, startTransform,staticplaneShape7 );
staticBody2->setCollisionFlags(staticBody2->getCollisionFlags()|btCollisionObject::CF_STATIC_OBJECT);
staticBody2->setActivationState(ISLAND_SLEEPING);
/// Create Static Torus /// Create Static Torus
float height = 32; float height = 28;
float step = 2.5; float step = 2.5;
float massT = 1.0; float massT = 1.0;
startTransform.setOrigin(btVector3(0,height,-5)); startTransform.setOrigin(btVector3(0,height,-5));
startTransform.setRotation(btQuaternion(3.14159265*0.5,0,3.14159265*0.5)); startTransform.setRotation(btQuaternion(3.14159265*0.5,0,3.14159265*0.5));
#ifdef BULLET_GIMPACT
kinematicTorus = localCreateRigidBody(0.0, startTransform,m_trimeshShape); kinematicTorus = localCreateRigidBody(0.0, startTransform,m_trimeshShape);
//kinematicTorus->setCollisionFlags(kinematicTorus->getCollisionFlags()|btCollisionObject::CF_STATIC_OBJECT);
#else
kinematicTorus = localCreateRigidBody(0.0, startTransform,createTorusShape());
#endif //kinematicTorus->setCollisionFlags(kinematicTorus->getCollisionFlags()|btCollisionObject::CF_STATIC_OBJECT);
//kinematicTorus->setActivationState(ISLAND_SLEEPING); //kinematicTorus->setActivationState(ISLAND_SLEEPING);
kinematicTorus->setCollisionFlags( kinematicTorus->getCollisionFlags() | btCollisionObject::CF_KINEMATIC_OBJECT); kinematicTorus->setCollisionFlags( kinematicTorus->getCollisionFlags() | btCollisionObject::CF_KINEMATIC_OBJECT);
@@ -411,12 +512,14 @@ void GimpactConcaveDemo::initPhysics()
#ifdef TEST_GIMPACT_TORUS #ifdef TEST_GIMPACT_TORUS
#ifdef BULLET_GIMPACT
/// Create dynamic Torus /// Create dynamic Torus
for (int i=0;i<8;i++) for (int i=0;i<6;i++)
{ {
height -= step; height -= step;
startTransform.setOrigin(btVector3(0,height,-5)); startTransform.setOrigin(btVector3(0,height,-5));
startTransform.setRotation(btQuaternion(0,0,3.14159265*0.5)); startTransform.setRotation(btQuaternion(0,0,3.14159265*0.5));
btRigidBody* bodyA = localCreateRigidBody(massT, startTransform,m_trimeshShape); btRigidBody* bodyA = localCreateRigidBody(massT, startTransform,m_trimeshShape);
height -= step; height -= step;
@@ -425,6 +528,24 @@ void GimpactConcaveDemo::initPhysics()
btRigidBody* bodyB = localCreateRigidBody(massT, startTransform,m_trimeshShape); btRigidBody* bodyB = localCreateRigidBody(massT, startTransform,m_trimeshShape);
} }
#else
/// Create dynamic Torus
for (int i=0;i<6;i++)
{
height -= step;
startTransform.setOrigin(btVector3(0,height,-5));
startTransform.setRotation(btQuaternion(0,0,3.14159265*0.5));
btRigidBody* bodyA = localCreateRigidBody(massT, startTransform,createTorusShape());
height -= step;
startTransform.setOrigin(btVector3(0,height,-5));
startTransform.setRotation(btQuaternion(3.14159265*0.5,0,3.14159265*0.5));
btRigidBody* bodyB = localCreateRigidBody(massT, startTransform,createTorusShape());
}
#endif //no BULLET_GIMPACT
#endif #endif
startTransform.setIdentity(); startTransform.setIdentity();
@@ -432,7 +553,7 @@ void GimpactConcaveDemo::initPhysics()
/// Create Dynamic Boxes /// Create Dynamic Boxes
{ {
for (int i=0;i<9;i++) for (int i=0;i<8;i++)
{ {
btCollisionShape* boxShape = new btBoxShape(btVector3(1,1,1)); btCollisionShape* boxShape = new btBoxShape(btVector3(1,1,1));
startTransform.setOrigin(btVector3(2*i-5,2,-3)); startTransform.setOrigin(btVector3(2*i-5,2,-3));
@@ -455,9 +576,11 @@ void GimpactConcaveDemo::shootTrimesh(const btVector3& destination)
startTransform.setIdentity(); startTransform.setIdentity();
btVector3 camPos = getCameraPosition(); btVector3 camPos = getCameraPosition();
startTransform.setOrigin(camPos); startTransform.setOrigin(camPos);
#ifdef BULLET_GIMPACT
btRigidBody* body = this->localCreateRigidBody(mass, startTransform,m_trimeshShape2); btRigidBody* body = this->localCreateRigidBody(mass, startTransform,m_trimeshShape2);
#else
btRigidBody* body = this->localCreateRigidBody(mass, startTransform,createBunnyShape());
#endif
btVector3 linVel(destination[0]-camPos[0],destination[1]-camPos[1],destination[2]-camPos[2]); btVector3 linVel(destination[0]-camPos[0],destination[1]-camPos[1],destination[2]-camPos[2]);
linVel.normalize(); linVel.normalize();
linVel*=m_ShootBoxInitialSpeed*0.25; linVel*=m_ShootBoxInitialSpeed*0.25;
@@ -487,7 +610,7 @@ void GimpactConcaveDemo::clientMoveAndDisplay()
btTransform newTrans; btTransform newTrans;
btRigidBody::upcast(colObj)->getMotionState()->getWorldTransform(newTrans); btRigidBody::upcast(colObj)->getMotionState()->getWorldTransform(newTrans);
newTrans.getOrigin() += kinTorusTran; newTrans.getOrigin() += kinTorusTran;
newTrans.getBasis() = newTrans.getBasis() * btMatrix3x3(kinTorusRot); newTrans.getBasis() = newTrans.getBasis() * btMatrix3x3(kinTorusRot);
if(newTrans.getOrigin().getX() > 6.0){ if(newTrans.getOrigin().getX() > 6.0){
newTrans.getOrigin().setX(6.0); newTrans.getOrigin().setX(6.0);
@@ -511,11 +634,20 @@ void GimpactConcaveDemo::clientMoveAndDisplay()
#endif //USE_KINEMATIC_GROUND #endif //USE_KINEMATIC_GROUND
unsigned long int time = m_clock.getTimeMilliseconds(); unsigned long int time = m_clock.getTimeMilliseconds();
printf("%i time %i ms \n",m_steps_done,time);
//#ifdef BULLET_GIMPACT
// printf("%i time %.1f ms \n",m_steps_done,btGImpactCollisionAlgorithm::getAverageTreeCollisionTime());
//#else
// printf("%i time %.1f ms \n",m_steps_done,btConcaveConcaveCollisionAlgorithm::getAverageTreeCollisionTime());
//#endif
//float dt = float(m_clock.getTimeMicroseconds()) * dts; //0.000001f; //float dt = float(m_clock.getTimeMicroseconds()) * dts; //0.000001f;
float dt = float(m_clock.getTimeMicroseconds()) * 0.000001f; float dt = float(m_clock.getTimeMicroseconds()) * 0.000001f;
printf("%i time %i ms \n",m_steps_done,time);
m_clock.reset(); m_clock.reset();
m_dynamicsWorld->stepSimulation(dt); m_dynamicsWorld->stepSimulation(dt);
@@ -564,10 +696,10 @@ void GimpactConcaveDemo::keyboardCallback(unsigned char key, int x, int y)
case '2': case '2':
{ {
dts += 0.000001f; dts += 0.000001f;
break; break;
} }
case '3': case '3':
{ {
dts -= 0.000001f; if(dts<0.000001f) dts = 0.000001f; dts -= 0.000001f; if(dts<0.000001f) dts = 0.000001f;
break; break;
@@ -586,7 +718,7 @@ void GimpactConcaveDemo::keyboardCallback(unsigned char key, int x, int y)
switch (key) switch (key)
{ {
case 'q' : case 'q' :
case KEY_ESCAPE : case KEY_ESCAPE :
exit(0); break; exit(0); break;

View File

@@ -17,6 +17,30 @@ subject to the following restrictions:
#include "DemoApplication.h" #include "DemoApplication.h"
//#define BULLET_TRIANGLE_COLLISION 1
#define BULLET_GIMPACT 1
#define BULLET_GIMPACT_CONVEX_DECOMPOSITION 1
#define TEST_GIMPACT_TORUS
#ifdef BULLET_GIMPACT
#include "GIMPACT/Bullet/btGImpactCollisionAlgorithm.h"
#ifdef BULLET_GIMPACT_CONVEX_DECOMPOSITION
#include "btGImpactConvexDecompositionShape.h"
#endif
#else
#include "btConcaveConcaveCollisionAlgorithm.h"
#include "btGIMPACTMeshShape.h"
#endif
struct btCollisionAlgorithmCreateFunc; struct btCollisionAlgorithmCreateFunc;
///GimpactConcaveDemo shows usage of static concave triangle meshes ///GimpactConcaveDemo shows usage of static concave triangle meshes
@@ -25,18 +49,18 @@ class GimpactConcaveDemo : public DemoApplication
{ {
public: public:
GimpactConcaveDemo() GimpactConcaveDemo()
: m_trimeshShape(NULL), : m_trimeshShape(NULL),
m_trimeshShape2(NULL), m_trimeshShape2(NULL),
m_indexVertexArrays(NULL), m_indexVertexArrays(NULL),
m_indexVertexArrays2(NULL), m_indexVertexArrays2(NULL),
m_collisionConfiguration(NULL), m_collisionConfiguration(NULL),
m_dispatcher(NULL), m_dispatcher(NULL),
m_broadphase(NULL), m_broadphase(NULL),
m_constraintSolver(NULL), m_constraintSolver(NULL),
m_gimpactCollisionCreateFunc(NULL), m_gimpactCollisionCreateFunc(NULL),
m_steps_done(0) m_steps_done(0)
{ {
} }
virtual ~GimpactConcaveDemo() virtual ~GimpactConcaveDemo()
@@ -51,7 +75,7 @@ public:
delete m_collisionConfiguration; delete m_collisionConfiguration;
delete m_dispatcher; delete m_dispatcher;
delete m_broadphase; delete m_broadphase;
delete m_constraintSolver; delete m_constraintSolver;
delete m_dynamicsWorld; delete m_dynamicsWorld;
@@ -75,9 +99,18 @@ public:
public: ///data public: ///data
unsigned int m_steps_done; unsigned int m_steps_done;
#ifdef BULLET_GIMPACT
btCollisionShape *m_trimeshShape; btCollisionShape *m_trimeshShape;
btCollisionShape *m_trimeshShape2; btCollisionShape *m_trimeshShape2;
#else
btGIMPACTMeshData * m_trimeshShape;
btGIMPACTMeshData * m_trimeshShape2;
btCollisionShape * createTorusShape();
btCollisionShape * createBunnyShape();
#endif
btTriangleIndexVertexArray *m_indexVertexArrays; btTriangleIndexVertexArray *m_indexVertexArrays;
btTriangleIndexVertexArray *m_indexVertexArrays2; btTriangleIndexVertexArray *m_indexVertexArrays2;

File diff suppressed because it is too large Load Diff