Back to index

supertuxkart  0.5+dfsg1
GL_ShapeDrawer.cpp
Go to the documentation of this file.
00001 /*
00002 Bullet Continuous Collision Detection and Physics Library
00003 Copyright (c) 2003-2006 Erwin Coumans  http://continuousphysics.com/Bullet/
00004 
00005 This software is provided 'as-is', without any express or implied warranty.
00006 In no event will the authors be held liable for any damages arising from the use of this software.
00007 Permission is granted to anyone to use this software for any purpose, 
00008 including commercial applications, and to alter it and redistribute it freely, 
00009 subject to the following restrictions:
00010 
00011 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.
00012 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
00013 3. This notice may not be removed or altered from any source distribution.
00014 */
00015 
00016 #ifdef WIN32 //needed for glut.h
00017 #include <windows.h>
00018 #endif
00019 
00020 //think different
00021 #if defined(__APPLE__) && !defined (VMDMESA)
00022 #include <OpenGL/gl.h>
00023 #include <OpenGL/glu.h>
00024 #include <GLUT/glut.h>
00025 #else
00026 #include <GL/glut.h>
00027 #endif
00028 
00029 #include "GlutStuff.h"
00030 #include "GL_ShapeDrawer.h"
00031 #include "BulletCollision/CollisionShapes/btPolyhedralConvexShape.h"
00032 #include "BulletCollision/CollisionShapes/btTriangleMeshShape.h"
00033 #include "BulletCollision/CollisionShapes/btBoxShape.h"
00034 #include "BulletCollision/CollisionShapes/btSphereShape.h"
00035 #include "BulletCollision/CollisionShapes/btConeShape.h"
00036 #include "BulletCollision/CollisionShapes/btCylinderShape.h"
00037 #include "BulletCollision/CollisionShapes/btTetrahedronShape.h"
00038 #include "BulletCollision/CollisionShapes/btCompoundShape.h"
00039 #include "BulletCollision/CollisionShapes/btCapsuleShape.h"
00040 #include "BulletCollision/CollisionShapes/btConvexTriangleMeshShape.h"
00041 #include "BulletCollision/CollisionShapes/btUniformScalingShape.h"
00042 #include "BulletCollision/CollisionShapes/btStaticPlaneShape.h"
00044 #include "BulletCollision/CollisionShapes/btShapeHull.h"
00045 
00046 #include "LinearMath/btTransformUtil.h"
00047 
00048 
00049 #include "LinearMath/btIDebugDraw.h"
00050 //for debugmodes
00051 #include "BMF_Api.h"
00052 #include <stdio.h> //printf debugging
00053 
00054 //#define USE_DISPLAY_LISTS 1
00055 #ifdef USE_DISPLAY_LISTS
00056 
00057 #include <map>
00058 
00059 using namespace std;
00060 
00061 //Set for storing Display list per trimesh
00062 struct TRIMESH_KEY
00063 {
00064        btCollisionShape* m_shape;
00065        GLuint m_dlist;//OpenGL display list      
00066 };
00067 
00068 typedef map<unsigned long,TRIMESH_KEY> TRIMESH_KEY_MAP;
00069 
00070 typedef pair<unsigned long,TRIMESH_KEY> TRIMESH_KEY_PAIR;
00071 
00072 TRIMESH_KEY_MAP g_display_lists;
00073 
00074 class GlDisplaylistDrawcallback : public btTriangleCallback
00075 {
00076 public:
00077 
00078        virtual void processTriangle(btVector3* triangle,int partId, int triangleIndex)
00079        {
00080 
00081               btVector3 diff1 = triangle[1] - triangle[0];
00082               btVector3 diff2 = triangle[2] - triangle[0];
00083               btVector3 normal = diff1.cross(diff2);
00084 
00085               normal.normalize();
00086 
00087               glBegin(GL_TRIANGLES);
00088               glColor3f(0, 1, 0);
00089               glNormal3d(normal.getX(),normal.getY(),normal.getZ());
00090               glVertex3d(triangle[0].getX(), triangle[0].getY(), triangle[0].getZ());
00091 
00092               glColor3f(0, 1, 0);
00093               glNormal3d(normal.getX(),normal.getY(),normal.getZ());
00094               glVertex3d(triangle[1].getX(), triangle[1].getY(), triangle[1].getZ());
00095 
00096               glColor3f(0, 1, 0);
00097               glNormal3d(normal.getX(),normal.getY(),normal.getZ());
00098               glVertex3d(triangle[2].getX(), triangle[2].getY(), triangle[2].getZ());
00099               glEnd();
00100 
00101               /*glBegin(GL_LINES);
00102               glColor3f(1, 1, 0);
00103               glNormal3d(normal.getX(),normal.getY(),normal.getZ());
00104               glVertex3d(triangle[0].getX(), triangle[0].getY(), triangle[0].getZ());
00105               glNormal3d(normal.getX(),normal.getY(),normal.getZ());
00106               glVertex3d(triangle[1].getX(), triangle[1].getY(), triangle[1].getZ());
00107               glColor3f(1, 1, 0);
00108               glNormal3d(normal.getX(),normal.getY(),normal.getZ());
00109               glVertex3d(triangle[2].getX(), triangle[2].getY(), triangle[2].getZ());
00110               glNormal3d(normal.getX(),normal.getY(),normal.getZ());
00111               glVertex3d(triangle[1].getX(), triangle[1].getY(), triangle[1].getZ());
00112               glColor3f(1, 1, 0);
00113               glNormal3d(normal.getX(),normal.getY(),normal.getZ());
00114               glVertex3d(triangle[2].getX(), triangle[2].getY(), triangle[2].getZ());
00115               glNormal3d(normal.getX(),normal.getY(),normal.getZ());
00116               glVertex3d(triangle[0].getX(), triangle[0].getY(), triangle[0].getZ());
00117               glEnd();*/
00118 
00119               
00120        }
00121 };
00122 
00123 GLuint  OGL_get_displaylist_for_shape(btCollisionShape * shape)
00124 {
00125        TRIMESH_KEY_MAP::iterator map_iter;
00126        
00127        unsigned long key = (unsigned long)shape;
00128        map_iter = g_display_lists.find(key);
00129        if(map_iter!=g_display_lists.end())
00130        {
00131               return map_iter->second.m_dlist;
00132        }
00133 
00134        return 0;
00135 }
00136 
00137 void OGL_displaylist_clean()
00138 {
00139        TRIMESH_KEY_MAP::iterator map_iter,map_itend;
00140 
00141        map_iter = g_display_lists.begin();
00142 
00143        while(map_iter!=map_itend)
00144        {
00145               glDeleteLists(map_iter->second.m_dlist,1);              
00146               map_iter++;
00147        }
00148 
00149        g_display_lists.clear();
00150 }
00151 
00152 
00153 void OGL_displaylist_register_shape(btCollisionShape * shape)
00154 {
00155        btVector3 aabbMax(btScalar(1e30),btScalar(1e30),btScalar(1e30));
00156        btVector3 aabbMin(-btScalar(1e30),-btScalar(1e30),-btScalar(1e30));
00157        GlDisplaylistDrawcallback drawCallback;
00158        TRIMESH_KEY dlist;
00159 
00160        dlist.m_dlist = glGenLists(1);
00161        dlist.m_shape = shape;
00162 
00163        unsigned long key = (unsigned long)shape;
00164 
00165        g_display_lists.insert(TRIMESH_KEY_PAIR(key,dlist));
00166        
00167        glNewList(dlist.m_dlist,GL_COMPILE);
00168 
00169        glEnable(GL_CULL_FACE);
00170 
00171        glCullFace(GL_BACK);
00172 
00173        if (shape->isConcave())
00174        {
00175               btConcaveShape* concaveMesh = (btConcaveShape*) shape;                
00176               //todo pass camera, for some culling             
00177               concaveMesh->processAllTriangles(&drawCallback,aabbMin,aabbMax);
00178        }
00179 
00180        glDisable(GL_CULL_FACE);    
00181 
00182        glEndList();
00183 }
00184 #endif //USE_DISPLAY_LISTS
00185 
00186 void GL_ShapeDrawer::drawCoordSystem()  {
00187     glBegin(GL_LINES);
00188     glColor3f(1, 0, 0);
00189     glVertex3d(0, 0, 0);
00190     glVertex3d(1, 0, 0);
00191     glColor3f(0, 1, 0);
00192     glVertex3d(0, 0, 0);
00193     glVertex3d(0, 1, 0);
00194     glColor3f(0, 0, 1);
00195     glVertex3d(0, 0, 0);
00196     glVertex3d(0, 0, 1);
00197     glEnd();
00198        
00199 }
00200 
00201 
00202 
00203 
00204 
00205 class GlDrawcallback : public btTriangleCallback
00206 {
00207 
00208 public:
00209 
00210        bool   m_wireframe;
00211 
00212        GlDrawcallback()
00213               :m_wireframe(false)
00214        {
00215        }
00216 
00217        virtual void processTriangle(btVector3* triangle,int partId, int triangleIndex)
00218        {
00219 
00220               (void)triangleIndex;
00221               (void)partId;
00222 
00223 
00224               if (m_wireframe)
00225               {
00226                      glBegin(GL_LINES);
00227                      glColor3f(1, 0, 0);
00228                      glVertex3d(triangle[0].getX(), triangle[0].getY(), triangle[0].getZ());
00229                      glVertex3d(triangle[1].getX(), triangle[1].getY(), triangle[1].getZ());
00230                      glColor3f(0, 1, 0);
00231                      glVertex3d(triangle[2].getX(), triangle[2].getY(), triangle[2].getZ());
00232                      glVertex3d(triangle[1].getX(), triangle[1].getY(), triangle[1].getZ());
00233                      glColor3f(0, 0, 1);
00234                      glVertex3d(triangle[2].getX(), triangle[2].getY(), triangle[2].getZ());
00235                      glVertex3d(triangle[0].getX(), triangle[0].getY(), triangle[0].getZ());
00236                      glEnd();
00237               } else
00238               {
00239                      glBegin(GL_TRIANGLES);
00240                      glColor3f(1, 0, 0);
00241                      glVertex3d(triangle[0].getX(), triangle[0].getY(), triangle[0].getZ());
00242                      glColor3f(0, 1, 0);
00243                      glVertex3d(triangle[1].getX(), triangle[1].getY(), triangle[1].getZ());
00244                      glColor3f(0, 0, 1);
00245                      glVertex3d(triangle[2].getX(), triangle[2].getY(), triangle[2].getZ());
00246                      glEnd();
00247               }
00248        }
00249 };
00250 
00251 class TriangleGlDrawcallback : public btInternalTriangleIndexCallback
00252 {
00253 public:
00254        virtual void internalProcessTriangleIndex(btVector3* triangle,int partId,int  triangleIndex)
00255        {
00256               (void)triangleIndex;
00257               (void)partId;
00258 
00259 
00260               glBegin(GL_TRIANGLES);//LINES);
00261               glColor3f(1, 0, 0);
00262               glVertex3d(triangle[0].getX(), triangle[0].getY(), triangle[0].getZ());
00263               glVertex3d(triangle[1].getX(), triangle[1].getY(), triangle[1].getZ());
00264               glColor3f(0, 1, 0);
00265               glVertex3d(triangle[2].getX(), triangle[2].getY(), triangle[2].getZ());
00266               glVertex3d(triangle[1].getX(), triangle[1].getY(), triangle[1].getZ());
00267               glColor3f(0, 0, 1);
00268               glVertex3d(triangle[2].getX(), triangle[2].getY(), triangle[2].getZ());
00269               glVertex3d(triangle[0].getX(), triangle[0].getY(), triangle[0].getZ());
00270               glEnd();
00271        }
00272 };
00273 
00274 void GL_ShapeDrawer::drawCylinder(float radius,float halfHeight, int upAxis)
00275 {
00276        
00277 
00278        glPushMatrix();
00279        switch (upAxis)
00280        {
00281        case 0:
00282               glRotatef(-90.0, 0.0, 1.0, 0.0);
00283               glTranslatef(0.0, 0.0, -halfHeight);
00284               break;
00285        case 1:
00286               glRotatef(-90.0, 1.0, 0.0, 0.0);
00287               glTranslatef(0.0, 0.0, -halfHeight);
00288               break;
00289        case 2:
00290               
00291               glTranslatef(0.0, 0.0, -halfHeight);
00292               break;
00293        default:
00294               {
00295                      assert(0);
00296               }
00297 
00298        }
00299        
00300        GLUquadricObj *quadObj = gluNewQuadric();
00301 
00302        //The gluCylinder subroutine draws a cylinder that is oriented along the z axis. 
00303        //The base of the cylinder is placed at z = 0; the top of the cylinder is placed at z=height. 
00304        //Like a sphere, the cylinder is subdivided around the z axis into slices and along the z axis into stacks.
00305        
00306        gluQuadricDrawStyle(quadObj, (GLenum)GLU_FILL);
00307        gluQuadricNormals(quadObj, (GLenum)GLU_SMOOTH);
00308        
00309        gluDisk(quadObj,0,radius,15, 10);
00310        
00311        gluCylinder(quadObj, radius, radius, 2.f*halfHeight, 15, 10);
00312        glTranslatef(0.0, 0.0, 2.*halfHeight);
00313        glRotatef(-180.0, 0.0, 1.0, 0.0);
00314        gluDisk(quadObj,0,radius,15, 10);
00315 
00316        glPopMatrix();
00317        gluDeleteQuadric(quadObj);
00318 }
00319 
00320 
00321 
00322 void GL_ShapeDrawer::drawOpenGL(btScalar* m, const btCollisionShape* shape, const btVector3& color,int   debugMode)
00323 {
00324 
00325        
00326        glPushMatrix(); 
00327   btglMultMatrix(m);
00328 
00329        if (shape->getShapeType() == UNIFORM_SCALING_SHAPE_PROXYTYPE)
00330        {
00331               const btUniformScalingShape* scalingShape = static_cast<const btUniformScalingShape*>(shape);
00332               const btConvexShape* convexShape = scalingShape->getChildShape();
00333               float  scalingFactor = (float)scalingShape->getUniformScalingFactor();
00334               {
00335                      btScalar tmpScaling[4][4]={{scalingFactor,0,0,0},
00336                             {0,scalingFactor,0,0},
00337                             {0,0,scalingFactor,0},
00338                             {0,0,0,1}};
00339                      
00340                      drawOpenGL( (btScalar*)tmpScaling,convexShape,color,debugMode);
00341               }
00342               glPopMatrix();
00343               return;
00344        }
00345 
00346        if (shape->getShapeType() == COMPOUND_SHAPE_PROXYTYPE)
00347        {
00348               const btCompoundShape* compoundShape = static_cast<const btCompoundShape*>(shape);
00349               for (int i=compoundShape->getNumChildShapes()-1;i>=0;i--)
00350               {
00351                      btTransform childTrans = compoundShape->getChildTransform(i);
00352                      const btCollisionShape* colShape = compoundShape->getChildShape(i);
00353                      btScalar childMat[16];
00354                      childTrans.getOpenGLMatrix(childMat);
00355                      drawOpenGL(childMat,colShape,color,debugMode);
00356               }
00357 
00358        } else
00359        {
00360               //drawCoordSystem();
00361            
00362               //glPushMatrix();
00363               glEnable(GL_COLOR_MATERIAL);
00364               glColor3f(color.x(),color.y(), color.z());
00365 
00366               
00367 
00368               bool useWireframeFallback = true;
00369 
00370               if (!(debugMode & btIDebugDraw::DBG_DrawWireframe))
00371               {
00374                      switch (shape->getShapeType())
00375                      {
00376                      case BOX_SHAPE_PROXYTYPE:
00377                             {
00378                                    const btBoxShape* boxShape = static_cast<const btBoxShape*>(shape);
00379                                    btVector3 halfExtent = boxShape->getHalfExtentsWithMargin();
00380                                    glScaled(2*halfExtent[0], 2*halfExtent[1], 2*halfExtent[2]);
00381                                    glutSolidCube(1.0);
00382                                    useWireframeFallback = false;
00383                                    break;
00384                             }
00385               
00386                      
00387                      case SPHERE_SHAPE_PROXYTYPE:
00388                             {
00389                                    const btSphereShape* sphereShape = static_cast<const btSphereShape*>(shape);
00390                                    float radius = sphereShape->getMargin();//radius doesn't include the margin, so draw with margin
00391                                    glutSolidSphere(radius,10,10);
00392                                    useWireframeFallback = false;
00393                                    break;
00394                             }
00395                      
00396                      case CONE_SHAPE_PROXYTYPE:
00397                             {
00398                                    const btConeShape* coneShape = static_cast<const btConeShape*>(shape);
00399                                    int upIndex = coneShape->getConeUpIndex();
00400                                    float radius = coneShape->getRadius();//+coneShape->getMargin();
00401                                    float height = coneShape->getHeight();//+coneShape->getMargin();
00402                                    switch (upIndex)
00403                                    {
00404                                    case 0:
00405                                           glRotatef(90.0, 0.0, 1.0, 0.0);
00406                                           break;
00407                                    case 1:
00408                                           glRotatef(-90.0, 1.0, 0.0, 0.0);
00409                                           break;
00410                                    case 2:
00411                                           break;
00412                                    default:
00413                                           {
00414                                           }
00415                                    };
00416                                    
00417                                    glTranslatef(0.0, 0.0, -0.5*height);
00418                                    glutSolidCone(radius,height,10,10);
00419                                    useWireframeFallback = false;
00420                                    break;
00421 
00422                             }
00423               
00424 
00425                      case STATIC_PLANE_PROXYTYPE:
00426                             {
00427                                    const btStaticPlaneShape* staticPlaneShape = static_cast<const btStaticPlaneShape*>(shape);
00428                                    btScalar planeConst = staticPlaneShape->getPlaneConstant();
00429                                    const btVector3& planeNormal = staticPlaneShape->getPlaneNormal();
00430                                    btVector3 planeOrigin = planeNormal * planeConst;
00431                                    btVector3 vec0,vec1;
00432                                    btPlaneSpace1(planeNormal,vec0,vec1);
00433                                    btScalar vecLen = 100.f;
00434                                    btVector3 pt0 = planeOrigin + vec0*vecLen;
00435                                    btVector3 pt1 = planeOrigin - vec0*vecLen;
00436                                    btVector3 pt2 = planeOrigin + vec1*vecLen;
00437                                    btVector3 pt3 = planeOrigin - vec1*vecLen;
00438                                    glBegin(GL_LINES);
00439                                    glVertex3f(pt0.getX(),pt0.getY(),pt0.getZ());
00440                                    glVertex3f(pt1.getX(),pt1.getY(),pt1.getZ());
00441                                    glVertex3f(pt2.getX(),pt2.getY(),pt2.getZ());
00442                                    glVertex3f(pt3.getX(),pt3.getY(),pt3.getZ());
00443                                    glEnd();
00444 
00445                                    
00446                                    break;
00447 
00448                             }
00449 
00450                      case CYLINDER_SHAPE_PROXYTYPE:
00451                             {
00452                                    const btCylinderShape* cylinder = static_cast<const btCylinderShape*>(shape);
00453                                    int upAxis = cylinder->getUpAxis();
00454                                    
00455                                    
00456                                    float radius = cylinder->getRadius();
00457                                    float halfHeight = cylinder->getHalfExtentsWithMargin()[upAxis];
00458 
00459                                    drawCylinder(radius,halfHeight,upAxis);
00460 
00461                                    break;
00462                             }
00463                      
00464                      default:
00465                             {
00466                                    
00467                                    
00468                                    if (shape->isConvex())
00469                                    {
00470                                           btConvexShape* convexShape = (btConvexShape*)shape;
00471                                           if (!shape->getUserPointer())
00472                                           {
00473                                                  //create a hull approximation
00474                                                  void* mem = btAlignedAlloc(sizeof(btShapeHull),16);
00475                                                  btShapeHull* hull = new(mem) btShapeHull(convexShape);
00476                                    
00478                                                  m_shapeHulls.push_back(hull);
00479 
00480                                                  btScalar margin = shape->getMargin();
00481                                                  hull->buildHull(margin);
00482                                                  convexShape->setUserPointer(hull);
00483 
00484                                                  
00485                                           //     printf("numTriangles = %d\n", hull->numTriangles ());
00486                                           //     printf("numIndices = %d\n", hull->numIndices ());
00487                                           //     printf("numVertices = %d\n", hull->numVertices ());
00488                                                  
00489 
00490                                           }
00491                                           
00492                                           
00493 
00494 
00495                                           if (shape->getUserPointer())
00496                                           {
00497                                                  //glutSolidCube(1.0);
00498                                                  btShapeHull* hull = (btShapeHull*)shape->getUserPointer();
00499 
00500                                                  
00501                                                  if (hull->numTriangles () > 0)
00502                                                  {
00503                                                         int index = 0;
00504                                                         const unsigned int* idx = hull->getIndexPointer();
00505                                                         const btVector3* vtx = hull->getVertexPointer();
00506                                                         
00507                                                         glBegin (GL_TRIANGLES);
00508 
00509                                                         for (int i = 0; i < hull->numTriangles (); i++)
00510                                                         {
00511                                                                int i1 = index++;
00512                                                                int i2 = index++;
00513                                                                int i3 = index++;
00514                                                                btAssert(i1 < hull->numIndices () &&
00515                                                                       i2 < hull->numIndices () &&
00516                                                                       i3 < hull->numIndices ());
00517 
00518                                                                int index1 = idx[i1];
00519                                                                int index2 = idx[i2];
00520                                                                int index3 = idx[i3];
00521                                                                btAssert(index1 < hull->numVertices () &&
00522                                                                       index2 < hull->numVertices () &&
00523                                                                       index3 < hull->numVertices ());
00524 
00525                                                                btVector3 v1 = vtx[index1];
00526                                                                btVector3 v2 = vtx[index2];
00527                                                                btVector3 v3 = vtx[index3];
00528                                                                btVector3 normal = (v3-v1).cross(v2-v1);
00529                                                                normal.normalize ();
00530                                                                
00531                                                                glNormal3f(normal.getX(),normal.getY(),normal.getZ());
00532                                                                glVertex3f (v1.x(), v1.y(), v1.z());
00533                                                                glVertex3f (v2.x(), v2.y(), v2.z());
00534                                                                glVertex3f (v3.x(), v3.y(), v3.z());
00535                                                                
00536                                                         }
00537                                                         glEnd ();
00538                                           
00539                                           }
00540                                    } else
00541                                    {
00542 //                                        printf("unhandled drawing\n");
00543                                    }
00544                                    
00545 
00546                             }
00547                      }
00548               }
00549 
00550               }
00551               
00552 
00553               
00554 
00556               if (debugMode==btIDebugDraw::DBG_DrawFeaturesText && (shape->isPolyhedral()))
00557               {
00558                      btPolyhedralConvexShape* polyshape = (btPolyhedralConvexShape*) shape;
00559                      
00560                      {
00561                             glRasterPos3f(0.0,  0.0,  0.0);
00562                             //BMF_DrawString(BMF_GetFont(BMF_kHelvetica10),polyshape->getExtraDebugInfo());
00563 
00564                             glColor3f(1.f, 1.f, 1.f);
00565                             int i;
00566                             for (i=0;i<polyshape->getNumVertices();i++)
00567                             {
00568                                    btPoint3 vtx;
00569                                    polyshape->getVertex(i,vtx);
00570                                    glRasterPos3f(vtx.x(),  vtx.y(),  vtx.z());
00571                                    char buf[12];
00572                                    sprintf(buf," %d",i);
00573                                    BMF_DrawString(BMF_GetFont(BMF_kHelvetica10),buf);
00574                             }
00575 
00576                             for (i=0;i<polyshape->getNumPlanes();i++)
00577                             {
00578                                    btVector3 normal;
00579                                    btPoint3 vtx;
00580                                    polyshape->getPlane(normal,vtx,i);
00581                                    btScalar d = vtx.dot(normal);
00582 
00583                                    glRasterPos3f(normal.x()*d,  normal.y()*d, normal.z()*d);
00584                                    char buf[12];
00585                                    sprintf(buf," plane %d",i);
00586                                    BMF_DrawString(BMF_GetFont(BMF_kHelvetica10),buf);
00587                                    
00588                             }
00589                      }
00590                             
00591               }
00592 
00593 
00594 #ifdef USE_DISPLAY_LISTS
00595 
00596        if (shape->getShapeType() == TRIANGLE_MESH_SHAPE_PROXYTYPE||shape->getShapeType() == GIMPACT_SHAPE_PROXYTYPE)
00597               {
00598                      GLuint dlist =   OGL_get_displaylist_for_shape((btCollisionShape * )shape);
00599                      if (dlist)
00600                      {
00601                             glCallList(dlist);
00602                      }
00603                      else
00604                      {
00605 #else         
00606        if (shape->isConcave())//>getShapeType() == TRIANGLE_MESH_SHAPE_PROXYTYPE||shape->getShapeType() == GIMPACT_SHAPE_PROXYTYPE)
00607 //            if (shape->getShapeType() == TRIANGLE_MESH_SHAPE_PROXYTYPE)
00608               {
00609                      btConcaveShape* concaveMesh = (btConcaveShape*) shape;
00610                      //btVector3 aabbMax(btScalar(1e30),btScalar(1e30),btScalar(1e30));
00611                      //btVector3 aabbMax(100,100,100);//btScalar(1e30),btScalar(1e30),btScalar(1e30));
00612 
00613                      //todo pass camera, for some culling
00614                      btVector3 aabbMax(btScalar(1e30),btScalar(1e30),btScalar(1e30));
00615                      btVector3 aabbMin(-btScalar(1e30),-btScalar(1e30),-btScalar(1e30));
00616 
00617                      GlDrawcallback drawCallback;
00618                      drawCallback.m_wireframe = (debugMode & btIDebugDraw::DBG_DrawWireframe)!=0;
00619 
00620                      concaveMesh->processAllTriangles(&drawCallback,aabbMin,aabbMax);
00621 
00622               }
00623 #endif
00624 
00625 #ifdef USE_DISPLAY_LISTS
00626               }
00627        }
00628 #endif
00629 
00630        /*
00631               if (shape->getShapeType() == CONVEX_TRIANGLEMESH_SHAPE_PROXYTYPE)
00632               {
00633                      btConvexTriangleMeshShape* convexMesh = (btConvexTriangleMeshShape*) shape;
00634                      
00635                      //todo: pass camera for some culling                    
00636                      btVector3 aabbMax(btScalar(1e30),btScalar(1e30),btScalar(1e30));
00637                      btVector3 aabbMin(-btScalar(1e30),-btScalar(1e30),-btScalar(1e30));
00638                      TriangleGlDrawcallback drawCallback;
00639                      convexMesh->getMeshInterface()->InternalProcessAllTriangles(&drawCallback,aabbMin,aabbMax);
00640 
00641               }
00642               */
00643 
00644               
00645 
00646               glDisable(GL_DEPTH_BUFFER_BIT);
00647               glRasterPos3f(0,0,0);//mvtx.x(),  vtx.y(),  vtx.z());
00648               if (debugMode&btIDebugDraw::DBG_DrawText)
00649               {
00650                      BMF_DrawString(BMF_GetFont(BMF_kHelvetica10),shape->getName());
00651               }
00652 
00653               if (debugMode& btIDebugDraw::DBG_DrawFeaturesText)
00654               {
00655                      //BMF_DrawString(BMF_GetFont(BMF_kHelvetica10),shape->getExtraDebugInfo());
00656               }
00657               glEnable(GL_DEPTH_BUFFER_BIT);
00658 
00659        //     glPopMatrix();
00660        }
00661     glPopMatrix();
00662        
00663 }
00664 
00665 
00666 GL_ShapeDrawer::GL_ShapeDrawer()
00667 {
00668 }
00669 
00670 GL_ShapeDrawer::~GL_ShapeDrawer()
00671 {
00672        int i;
00673        for (i=0;i<m_shapeHulls.size();i++)
00674        {
00675               btShapeHull* hull = m_shapeHulls[i];
00676               hull->~btShapeHull();
00677               btAlignedFree(hull);
00678               m_shapeHulls[i] = 0;
00679        }
00680        m_shapeHulls.clear();
00681 }
00682