/* * Copyright (c) 2005 Erwin Coumans http://continuousphysics.com/Bullet/ * * Permission to use, copy, modify, distribute and sell this software * and its documentation for any purpose is hereby granted without fee, * provided that the above copyright notice appear in all copies. * Erwin Coumans makes no representations about the suitability * of this software for any purpose. * It is provided "as is" without express or implied warranty. */ /* Continuous Convex Collision Demo demonstrates an efficient continuous collision detection algorithm. Both linear and angular velocities are supported. Convex Objects are sampled using Supporting Vertex. Motion using Exponential Map. Future ideas: Comparison with Screwing Motion. Also comparision with Algebraic CCD and Interval Arithmetic methods (Stephane Redon) */ ///This low level demo need internal access, and intentionally doesn't include the btBulletCollisionCommon.h headerfile #include "LinearMath/btQuaternion.h" #include "LinearMath/btTransform.h" #include "BulletCollision/NarrowPhaseCollision/btVoronoiSimplexSolver.h" #include "BulletCollision/CollisionShapes/btBoxShape.h" #include "BulletCollision/CollisionShapes/btMinkowskiSumShape.h" #include "BulletCollision/NarrowPhaseCollision/btGjkPairDetector.h" #include "BulletCollision/NarrowPhaseCollision/btGjkConvexCast.h" #include "BulletCollision/NarrowPhaseCollision/btSubSimplexConvexCast.h" #include "BulletCollision/NarrowPhaseCollision/btContinuousConvexCollision.h" #include "LinearMath/btTransformUtil.h" #include "DebugCastResult.h" #include "BulletCollision/CollisionShapes/btSphereShape.h" #include "BulletCollision/CollisionShapes/btTetrahedronShape.h" #include "BulletCollision/NarrowPhaseCollision/btVoronoiSimplexSolver.h" #include "BulletCollision/NarrowPhaseCollision/btConvexPenetrationDepthSolver.h" #include "GL_ShapeDrawer.h" #include "ContinuousConvexCollision.h" #include "GlutStuff.h" float yaw=0.f,pitch=0.f,roll=0.f; const int maxNumObjects = 4; const int numObjects = 2; btVector3 angVels[numObjects]; btVector3 linVels[numObjects]; btPolyhedralConvexShape* shapePtr[maxNumObjects]; btTransform fromTrans[maxNumObjects]; btTransform toTrans[maxNumObjects]; int screenWidth = 640; int screenHeight = 480; int main(int argc,char** argv) { btContinuousConvexCollisionDemo* ccdDemo = new btContinuousConvexCollisionDemo(); ccdDemo->setCameraDistance(40.f); ccdDemo->initPhysics(); return glutmain(argc, argv,screenWidth,screenHeight,"Continuous Convex Collision Demo",ccdDemo); } void btContinuousConvexCollisionDemo::initPhysics() { fromTrans[0].setOrigin(btVector3(0,10,20)); toTrans[0].setOrigin(btVector3(0,10,-20)); fromTrans[1].setOrigin(btVector3(-2,7,0)); toTrans[1].setOrigin(btVector3(-2,10,0)); btMatrix3x3 identBasis; identBasis.setIdentity(); btMatrix3x3 basisA; basisA.setIdentity(); basisA.setEulerZYX(0.f,-SIMD_HALF_PI,0.f); fromTrans[0].setBasis(identBasis); toTrans[0].setBasis(basisA); fromTrans[1].setBasis(identBasis); toTrans[1].setBasis(identBasis); toTrans[1].setBasis(identBasis); btVector3 boxHalfExtentsA(10,1,1); btVector3 boxHalfExtentsB(1.1f,1.1f,1.1f); btBoxShape* boxA = new btBoxShape(boxHalfExtentsA); // btBU_Simplex1to4* boxA = new btBU_Simplex1to4(btPoint3(-2,0,-2),btPoint3(2,0,-2),btPoint3(0,0,2),btPoint3(0,2,0)); // btBU_Simplex1to4* boxA = new btBU_Simplex1to4(btPoint3(-12,0,0),btPoint3(12,0,0)); btBoxShape* boxB = new btBoxShape(boxHalfExtentsB); // btBU_Simplex1to4 boxB(btPoint3(0,10,0),btPoint3(0,-10,0)); shapePtr[0] = boxA; shapePtr[1] = boxB; shapePtr[0]->setMargin(0.01f); shapePtr[1]->setMargin(0.01f); for (int i=0;im_fraction,hitTrans); hitTrans.getOpenGLMatrix(m); GL_ShapeDrawer::drawOpenGL(m,shapePtr[0],btVector3(0,1,0),getDebugMode()); btTransformUtil::integrateTransform(fromTrans[i],linVels[i],angVels[i],rayResultPtr->m_fraction,hitTrans); hitTrans.getOpenGLMatrix(m); GL_ShapeDrawer::drawOpenGL(m,shapePtr[i],btVector3(0,1,1),getDebugMode()); } } glFlush(); glutSwapBuffers(); }