官方文档:http://bulletphysics.org
开源代码:https://github.com/bulletphysics/bullet3/releases
API文档:http://bulletphysics.org/Bullet/BulletFull/annotated.html
bullet3的三种碰撞检测
以下三种方式都是可以达到碰撞检测的效果:
btCollisionWorld::contactTest
检测指定对象是否与场景发生碰撞;btCollisionWorld::performDiscreteCollisionDetection
检测场景中所有的碰撞;btDynamicsWorld::stepSimulation
模拟运动。
还有一种射线检测,但是与这里的物体碰撞稍微有些区别,这里就不展开来讲了。
0. 准备工作
先创建一个场景,增加一个地板(box)
btDefaultCollisionConfiguration* g_colConfig;
btCollisionDispatcher* g_dispatcher;
btBroadphaseInterface* g_broadInterface;
btSequentialImpulseConstraintSolver* g_solver;
btDynamicsWorld* g_world; // 场景信息,退出的时候需要delete
g_colConfig = new btDefaultCollisionConfiguration();
g_dispatcher = new btCollisionDispatcher(g_colConfig);
g_broadInterface = new btDbvtBroadphase();
g_solver = new btSequentialImpulseConstraintSolver;
g_world = new btDiscreteDynamicsWorld(g_dispatcher, g_broadInterface, g_solver, g_colConfig);
g_world->setGravity(btVector3(0,-10,0)); // 设置重力加速度
// add a test box
{
btCollisionShape* shape = new btBoxShape(btVector3(btScalar(1000.),btScalar(10.),btScalar(