diff --git a/Demos/ConvexDecompositionDemo/ConvexDecompositionDemo.cpp b/Demos/ConvexDecompositionDemo/ConvexDecompositionDemo.cpp index 58b6f8c6b..9c43627d4 100644 --- a/Demos/ConvexDecompositionDemo/ConvexDecompositionDemo.cpp +++ b/Demos/ConvexDecompositionDemo/ConvexDecompositionDemo.cpp @@ -28,7 +28,8 @@ subject to the following restrictions: #include "LinearMath/btIDebugDraw.h" #include "LinearMath/btGeometryUtil.h" #include "BulletCollision/CollisionShapes/btShapeHull.h" - +#include "GLDebugDrawer.h" +GLDebugDrawer gDebugDrawer; //#define TEST_SERIALIZATION //#define NO_OBJ_TO_BULLET @@ -69,6 +70,8 @@ btVector3 convexDecompositionObjectOffset(10,0,0); unsigned int tcount = 0; +//sEnableSAT creates the data structures required for performing SAT tests between convex polyhedra, as alternative to GJK +bool sEnableSAT = false; void ConvexDecompositionDemo::initPhysics() { @@ -153,11 +156,14 @@ m_collisionConfiguration = new btDefaultCollisionConfiguration(); void ConvexDecompositionDemo::initPhysics(const char* filename) { + sEnableSAT = !sEnableSAT; gContactAddedCallback = &MyContactCallback; setupEmptyDynamicsWorld(); + getDynamicsWorld()->setDebugDrawer(&gDebugDrawer); + setTexturing(true); setShadows(true); @@ -327,7 +333,8 @@ void ConvexDecompositionDemo::initPhysics(const char* filename) btConvexHullShape* convexShape = new btConvexHullShape(&(vertices[0].getX()),vertices.size()); #endif - + if (sEnableSAT) + convexShape->initializePolyhedralFeatures(); convexShape->setMargin(0.01f); m_convexShapes.push_back(convexShape); m_convexCentroids.push_back(centroid); @@ -395,6 +402,8 @@ void ConvexDecompositionDemo::initPhysics(const char* filename) convexShape->addPoint(hull->getVertexPointer()[i]); } + if (sEnableSAT) + convexShape->initializePolyhedralFeatures(); delete tmpConvexShape; delete hull; @@ -737,5 +746,8 @@ void ConvexDecompositionDemo::exitPhysics() } - - +void ConvexDecompositionDemo::clientResetScene() +{ + exitPhysics(); + initPhysics("file.obj"); +} diff --git a/Demos/ConvexDecompositionDemo/ConvexDecompositionDemo.h b/Demos/ConvexDecompositionDemo/ConvexDecompositionDemo.h index b0db79a92..a206a8dc1 100644 --- a/Demos/ConvexDecompositionDemo/ConvexDecompositionDemo.h +++ b/Demos/ConvexDecompositionDemo/ConvexDecompositionDemo.h @@ -64,6 +64,8 @@ public: void exitPhysics(); + virtual void clientResetScene(); + virtual ~ConvexDecompositionDemo() { exitPhysics(); diff --git a/Demos/ConvexDecompositionDemo/main.cpp b/Demos/ConvexDecompositionDemo/main.cpp index b8f3a6567..9173e5be0 100644 --- a/Demos/ConvexDecompositionDemo/main.cpp +++ b/Demos/ConvexDecompositionDemo/main.cpp @@ -6,7 +6,6 @@ #include "btBulletDynamicsCommon.h" -GLDebugDrawer gDebugDrawer; int main(int argc,char** argv) { @@ -17,13 +16,9 @@ int main(int argc,char** argv) convexDecompDemo->initPhysics(filename); - convexDecompDemo->getDynamicsWorld()->setDebugDrawer(&gDebugDrawer); + - convexDecompDemo->clientResetScene(); - - - glutmain(argc, argv,640,480,"Bullet Physics Demo. http://www.continuousphysics.com/Bullet/phpBB2/",convexDecompDemo); delete convexDecompDemo; diff --git a/src/LinearMath/btConvexHullComputer.cpp b/src/LinearMath/btConvexHullComputer.cpp index c03c901c0..d58ac955f 100644 --- a/src/LinearMath/btConvexHullComputer.cpp +++ b/src/LinearMath/btConvexHullComputer.cpp @@ -1931,11 +1931,15 @@ void btConvexHullInternal::merge(IntermediateHull& h0, IntermediateHull& h1) } } - -static bool pointCmp(const btConvexHullInternal::Point32& p, const btConvexHullInternal::Point32& q) +class pointCmp { - return (p.y < q.y) || ((p.y == q.y) && ((p.x < q.x) || ((p.x == q.x) && (p.z < q.z)))); -} + public: + + bool operator() ( const btConvexHullInternal::Point32& p, const btConvexHullInternal::Point32& q ) const + { + return (p.y < q.y) || ((p.y == q.y) && ((p.x < q.x) || ((p.x == q.x) && (p.z < q.z)))); + } +}; void btConvexHullInternal::compute(const void* coords, bool doubleCoords, int stride, int count) { @@ -2026,7 +2030,7 @@ void btConvexHullInternal::compute(const void* coords, bool doubleCoords, int st points[i].index = i; } } - points.quickSort(pointCmp); + points.quickSort(pointCmp()); vertexPool.reset(); vertexPool.setArraySize(count);