From 125a9c673d2222169246326e51160f9c42e7ac38 Mon Sep 17 00:00:00 2001 From: ejcoumans Date: Sun, 12 Nov 2006 07:46:30 +0000 Subject: [PATCH] =?UTF-8?q?Added=20GIMPACT=20integration=20for=20moving=20?= =?UTF-8?q?concave=20meshes=20(interaction=20with=20all=20other=20Bullet?= =?UTF-8?q?=20collision=20shapes)=20Thanks=20a=20lot=20to=20Francisco=20Le?= =?UTF-8?q?=C3=B3n=20N=C3=A1jera=20for=20the=20contribution!?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Demos/ConcaveDemo/ConcavePhysicsDemo.cpp | 1 + .../MovingConcaveDemo/ConcavePhysicsDemo.cpp | 8 +- Demos/OpenGL/GL_ShapeDrawer.cpp | 74 ++++++++++++++++--- 3 files changed, 71 insertions(+), 12 deletions(-) diff --git a/Demos/ConcaveDemo/ConcavePhysicsDemo.cpp b/Demos/ConcaveDemo/ConcavePhysicsDemo.cpp index 8efcec3d6..f8bc1c472 100644 --- a/Demos/ConcaveDemo/ConcavePhysicsDemo.cpp +++ b/Demos/ConcaveDemo/ConcavePhysicsDemo.cpp @@ -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) { diff --git a/Demos/MovingConcaveDemo/ConcavePhysicsDemo.cpp b/Demos/MovingConcaveDemo/ConcavePhysicsDemo.cpp index 14b70500d..230f4e040 100644 --- a/Demos/MovingConcaveDemo/ConcavePhysicsDemo.cpp +++ b/Demos/MovingConcaveDemo/ConcavePhysicsDemo.cpp @@ -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"); @@ -1608,6 +1609,9 @@ void ConcaveDemo::renderme() sprintf(buf,"+- shooting speed = %10.2f",m_ShootBoxInitialSpeed); 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; } diff --git a/Demos/OpenGL/GL_ShapeDrawer.cpp b/Demos/OpenGL/GL_ShapeDrawer.cpp index 89c3c155e..d55662c54 100644 --- a/Demos/OpenGL/GL_ShapeDrawer.cpp +++ b/Demos/OpenGL/GL_ShapeDrawer.cpp @@ -44,6 +44,7 @@ subject to the following restrictions: #include "BMF_Api.h" #include //printf debugging +#define USE_DISPLAY_LISTS 1 #ifdef USE_DISPLAY_LISTS #include @@ -63,6 +64,55 @@ typedef pair 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); - glCallList(dlist); - } + 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;