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 07:46:30 +00:00
parent 5f91cc237d
commit 125a9c673d
3 changed files with 71 additions and 12 deletions

View File

@@ -31,6 +31,7 @@ int gIndices[NUM_TRIANGLES*3];
const float TRIANGLE_SIZE=80.f;
///User can override this material combiner by implementing gContactAddedCallback and setting body0->m_collisionFlags |= btCollisionObject::customMaterialCallback;
inline btScalar calculateCombinedFriction(float friction0,float friction1)
{

View File

@@ -1539,11 +1539,12 @@ void ConcaveDemo::renderme()
float xOffset = 10.f;
float yStart = 20.f;
float yIncr = -2.f;
float yIncr = 20.f;
char buf[124];
glColor3f(0, 0, 0);
setOrthographicProjection();
glRasterPos3f(xOffset,yStart,0);
sprintf(buf,"mouse to interact");
@@ -1609,6 +1610,9 @@ void ConcaveDemo::renderme()
BMF_DrawString(BMF_GetFont(BMF_kHelvetica10),buf);
yStart += yIncr;
resetPerspectiveProjection();
}
}
@@ -1826,7 +1830,7 @@ btGIMPACTMeshShape * createMesh()
{
btGIMPACTMeshShape * newtrimeshShape = new btGIMPACTMeshShape(g_trimeshData );
newtrimeshShape->setLocalScaling(btVector3(4.f,4.f,4.f));
//OGL_displaylist_register_shape(newtrimeshShape);
OGL_displaylist_register_shape(newtrimeshShape);
return newtrimeshShape;
}

View File

@@ -44,6 +44,7 @@ subject to the following restrictions:
#include "BMF_Api.h"
#include <stdio.h> //printf debugging
#define USE_DISPLAY_LISTS 1
#ifdef USE_DISPLAY_LISTS
#include <map>
@@ -63,6 +64,55 @@ typedef pair<unsigned long,TRIMESH_KEY> TRIMESH_KEY_PAIR;
TRIMESH_KEY_MAP g_display_lists;
class GlDisplaylistDrawcallback : public btTriangleCallback
{
public:
virtual void processTriangle(btVector3* triangle,int partId, int triangleIndex)
{
btVector3 diff1 = triangle[1] - triangle[0];
btVector3 diff2 = triangle[2] - triangle[0];
btVector3 normal = diff1.cross(diff2);
normal.normalize();
glBegin(GL_TRIANGLES);
glColor3f(0, 1, 0);
glNormal3d(normal.getX(),normal.getY(),normal.getZ());
glVertex3d(triangle[0].getX(), triangle[0].getY(), triangle[0].getZ());
glColor3f(0, 1, 0);
glNormal3d(normal.getX(),normal.getY(),normal.getZ());
glVertex3d(triangle[1].getX(), triangle[1].getY(), triangle[1].getZ());
glColor3f(0, 1, 0);
glNormal3d(normal.getX(),normal.getY(),normal.getZ());
glVertex3d(triangle[2].getX(), triangle[2].getY(), triangle[2].getZ());
glEnd();
/*glBegin(GL_LINES);
glColor3f(1, 1, 0);
glNormal3d(normal.getX(),normal.getY(),normal.getZ());
glVertex3d(triangle[0].getX(), triangle[0].getY(), triangle[0].getZ());
glNormal3d(normal.getX(),normal.getY(),normal.getZ());
glVertex3d(triangle[1].getX(), triangle[1].getY(), triangle[1].getZ());
glColor3f(1, 1, 0);
glNormal3d(normal.getX(),normal.getY(),normal.getZ());
glVertex3d(triangle[2].getX(), triangle[2].getY(), triangle[2].getZ());
glNormal3d(normal.getX(),normal.getY(),normal.getZ());
glVertex3d(triangle[1].getX(), triangle[1].getY(), triangle[1].getZ());
glColor3f(1, 1, 0);
glNormal3d(normal.getX(),normal.getY(),normal.getZ());
glVertex3d(triangle[2].getX(), triangle[2].getY(), triangle[2].getZ());
glNormal3d(normal.getX(),normal.getY(),normal.getZ());
glVertex3d(triangle[0].getX(), triangle[0].getY(), triangle[0].getZ());
glEnd();*/
}
};
GLuint OGL_get_displaylist_for_shape(btCollisionShape * shape)
{
TRIMESH_KEY_MAP::iterator map_iter;
@@ -97,7 +147,7 @@ void OGL_displaylist_register_shape(btCollisionShape * shape)
{
btVector3 aabbMax(1e30f,1e30f,1e30f);
btVector3 aabbMin(-1e30f,-1e30f,-1e30f);
GlDrawcallback drawCallback;
GlDisplaylistDrawcallback drawCallback;
TRIMESH_KEY dlist;
dlist.m_dlist = glGenLists(1);
@@ -113,17 +163,12 @@ void OGL_displaylist_register_shape(btCollisionShape * shape)
glCullFace(GL_BACK);
if (shape->getShapeType() == TRIANGLE_MESH_SHAPE_PROXYTYPE)
if (shape->isConcave())
{
btTriangleMeshShape* concaveMesh = (btTriangleMeshShape*) shape;
ConcaveShape* concaveMesh = (ConcaveShape*) 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);
@@ -415,8 +460,12 @@ void GL_ShapeDrawer::drawOpenGL(float* m, const btCollisionShape* shape, const b
if (shape->getShapeType() == TRIANGLE_MESH_SHAPE_PROXYTYPE||shape->getShapeType() == GIMPACT_SHAPE_PROXYTYPE)
{
GLuint dlist = OGL_get_displaylist_for_shape((btCollisionShape * )shape);
if (dlist)
{
glCallList(dlist);
}
else
{
#else
if (shape->getShapeType() == TRIANGLE_MESH_SHAPE_PROXYTYPE||shape->getShapeType() == GIMPACT_SHAPE_PROXYTYPE)
// if (shape->getShapeType() == TRIANGLE_MESH_SHAPE_PROXYTYPE)
@@ -437,6 +486,11 @@ void GL_ShapeDrawer::drawOpenGL(float* m, const btCollisionShape* shape, const b
}
#endif
#ifdef USE_DISPLAY_LISTS
}
}
#endif
if (shape->getShapeType() == CONVEX_TRIANGLEMESH_SHAPE_PROXYTYPE)
{
btConvexTriangleMeshShape* convexMesh = (btConvexTriangleMeshShape*) shape;