bullet3的三種碰撞檢測
以下三種方式都是可以達(dá)到碰撞檢測的效果:
btCollisionWorld::contactTest
檢測指定對象是否與場景發(fā)生碰撞;btCollisionWorld::performDiscreteCollisionDetection
檢測場景中所有的碰撞;btDynamicsWorld::stepSimulation
模擬運(yùn)動(dòng)。
還有一種射線檢測,但是與這里的物體碰撞稍微有些區(qū)別,這里就不展開來講了。
0. 準(zhǔn)備工作
先創(chuàng)建一個(gè)場景,增加一個(gè)地板(box)
btDefaultCollisionConfiguration* g_colConfig; btCollisionDispatcher* g_dispatcher; btBroadphaseInterface* g_broadInterface; btSequentialImpulseConstraintSolver* g_solver; btDynamicsWorld* g_world; // 場景信息,退出的時(shí)候需要deleteg_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);