Added GIMPACT integration for moving concave meshes (interaction with all other Bullet collision shapes)

Thanks a lot to Francisco León Nájera for the contribution!
This commit is contained in:
ejcoumans
2006-11-12 06:15:19 +00:00
parent 86c27a7c9d
commit a9172d8684
47 changed files with 14930 additions and 5 deletions

View File

@@ -77,6 +77,7 @@ SubInclude TOP Demos BspDemo ;
SubInclude TOP Demos VehicleDemo ;
SubInclude TOP Demos CollisionDemo ;
SubInclude TOP Demos CollisionInterfaceDemo ;
#SubInclude TOP Demos MovingConcaveDemo ;
SubInclude TOP Demos ConcaveDemo ;
SubInclude TOP Demos ConstraintDemo ;
SubInclude TOP Demos ContinuousConvexCollision ;

View File

@@ -0,0 +1,42 @@
/*
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.
*/
#ifndef CONCAVE_DEMO_H
#define CONCAVE_DEMO_H
#include "DemoApplication.h"
///ConcaveDemo shows usage of static concave triangle meshes
///It also shows per-triangle material (friction/restitution) through CustomMaterialCombinerCallback
class ConcaveDemo : public DemoApplication
{
public:
void initPhysics();
virtual void clientMoveAndDisplay();
virtual void displayCallback();
virtual void renderme();
virtual void keyboardCallback(unsigned char key, int x, int y);
///Demo functions
void shootTrimesh(const btVector3& destination);
};
#endif //CONCAVE_DEMO_H

File diff suppressed because it is too large Load Diff

View File

@@ -44,6 +44,93 @@ subject to the following restrictions:
#include "BMF_Api.h"
#include <stdio.h> //printf debugging
#ifdef USE_DISPLAY_LISTS
#include <map>
using namespace std;
//Set for storing Display list per trimesh
struct TRIMESH_KEY
{
btCollisionShape* m_shape;
GLuint m_dlist;//OpenGL display list
};
typedef map<unsigned long,TRIMESH_KEY> TRIMESH_KEY_MAP;
typedef pair<unsigned long,TRIMESH_KEY> TRIMESH_KEY_PAIR;
TRIMESH_KEY_MAP g_display_lists;
GLuint OGL_get_displaylist_for_shape(btCollisionShape * shape)
{
TRIMESH_KEY_MAP::iterator map_iter;
unsigned long key = (unsigned long)shape;
map_iter = g_display_lists.find(key);
if(map_iter!=g_display_lists.end())
{
return map_iter->second.m_dlist;
}
return 0;
}
void OGL_displaylist_clean()
{
TRIMESH_KEY_MAP::iterator map_iter,map_itend;
map_iter = g_display_lists.begin();
while(map_iter!=map_itend)
{
glDeleteLists(map_iter->second.m_dlist,1);
map_iter++;
}
g_display_lists.clear();
}
void OGL_displaylist_register_shape(btCollisionShape * shape)
{
btVector3 aabbMax(1e30f,1e30f,1e30f);
btVector3 aabbMin(-1e30f,-1e30f,-1e30f);
GlDrawcallback drawCallback;
TRIMESH_KEY dlist;
dlist.m_dlist = glGenLists(1);
dlist.m_shape = shape;
unsigned long key = (unsigned long)shape;
g_display_lists.insert(TRIMESH_KEY_PAIR(key,dlist));
glNewList(dlist.m_dlist,GL_COMPILE);
glEnable(GL_CULL_FACE);
glCullFace(GL_BACK);
if (shape->getShapeType() == TRIANGLE_MESH_SHAPE_PROXYTYPE)
{
btTriangleMeshShape* concaveMesh = (btTriangleMeshShape*) shape;
//todo pass camera, for some culling
concaveMesh->processAllTriangles(&drawCallback,aabbMin,aabbMax);
}
else if (shape->getShapeType() == GIMPACT_SHAPE_PROXYTYPE)
{
btGIMPACTMeshShape* gimpactMesh = (btGIMPACTMeshShape*) shape;
gimpactMesh->processAllTriangles(&drawCallback,aabbMin,aabbMax);
}
glDisable(GL_CULL_FACE);
glEndList();
}
#endif //USE_DISPLAY_LISTS
void GL_ShapeDrawer::drawCoordSystem() {
glBegin(GL_LINES);
glColor3f(1, 0, 0);
@@ -322,9 +409,19 @@ void GL_ShapeDrawer::drawOpenGL(float* m, const btCollisionShape* shape, const b
}
}
if (shape->getShapeType() == TRIANGLE_MESH_SHAPE_PROXYTYPE)
#ifdef USE_DISPLAY_LISTS
if (shape->getShapeType() == TRIANGLE_MESH_SHAPE_PROXYTYPE||shape->getShapeType() == GIMPACT_SHAPE_PROXYTYPE)
{
btTriangleMeshShape* concaveMesh = (btTriangleMeshShape*) shape;
GLuint dlist = OGL_get_displaylist_for_shape((btCollisionShape * )shape);
glCallList(dlist);
}
#else
if (shape->getShapeType() == TRIANGLE_MESH_SHAPE_PROXYTYPE||shape->getShapeType() == GIMPACT_SHAPE_PROXYTYPE)
// if (shape->getShapeType() == TRIANGLE_MESH_SHAPE_PROXYTYPE)
{
ConcaveShape* concaveMesh = (btTriangleMeshShape*) shape;
//btVector3 aabbMax(1e30f,1e30f,1e30f);
//btVector3 aabbMax(100,100,100);//1e30f,1e30f,1e30f);
@@ -337,8 +434,8 @@ void GL_ShapeDrawer::drawOpenGL(float* m, const btCollisionShape* shape, const b
concaveMesh->processAllTriangles(&drawCallback,aabbMin,aabbMax);
}
#endif
if (shape->getShapeType() == CONVEX_TRIANGLEMESH_SHAPE_PROXYTYPE)
{

View File

@@ -28,4 +28,7 @@ class GL_ShapeDrawer
};
void OGL_displaylist_register_shape(btCollisionShape * shape);
void OGL_displaylist_clean();
#endif //GL_SHAPE_DRAWER_H

View File

@@ -108,7 +108,7 @@ void UserCollisionAlgorithm::initPhysics()
btVector3 maxAabb(10000,10000,10000);
btOverlappingPairCache* broadphase = new btAxisSweep3(-maxAabb,maxAabb);//SimpleBroadphase();
dispatcher->registerCollisionCreateFunc(SPHERE_SHAPE_PROXYTYPE,SPHERE_SHAPE_PROXYTYPE,new btSphereSphereCollisionAlgorithm::CreateFunc);
dispatcher->registerCollisionCreateFunc(GIMPACT_SHAPE_PROXYTYPE,GIMPACT_SHAPE_PROXYTYPE,new btSphereSphereCollisionAlgorithm::CreateFunc);
m_dynamicsWorld = new btDiscreteDynamicsWorld(dispatcher,broadphase);