官方文檔:http://bulletphysics.org
開源代碼:https://github.com/bulletphysics/bullet3/releases
API文檔:http://bulletphysics.org/Bullet/BulletFull/annotated.htmlhtml
btCollisionWorld
btDynamicsWorld
btCollisionWorld
btDiscreteDynamicsWorld
btDynamicsWorld
// 初始化場景 // 用於配置碰撞檢測堆棧大小,默認碰撞算法,接觸副本池的大小 btDefaultCollisionConfiguration* collisionConfiguration = new btDefaultCollisionConfiguration(); // 用於計算重疊對象(碰撞檢測,接觸點計算)(接觸點會被封裝成 btPersistentManifold 對象) btCollisionDispatcher* dispatcher = new btCollisionDispatcher(collisionConfiguration); // 提供成對的aabb重疊監測(重疊對象的管理,存儲,增長刪除等) btBroadphaseInterface* overlappingPairCache = new btDbvtBroadphase(); btSequentialImpulseConstraintSolver* solver = new btSequentialImpulseConstraintSolver; btDynamicsWorld* world = new btDiscreteDynamicsWorld(dispatcher, overlappingPairCache, solver, collisionConfiguration);
void btDynamicsWorld::addRigidBody(btRigidBody* body)
void btCollisionWorld::removeCollisionObject(btCollisionObject* collisionObject)
int btCollisionWorld::getNumCollisionObjects()
btAlignedObjectArray<btCollisionObject*> btCollisionWorld::getCollisionObjectArray()
void btDynamicsWorld::setGravity(const btVector3& gravity)
void btDynamicsWorld::performDiscreteCollisionDetection()
int btDynamicsWorld::stepSimulation(btScalar timeStep, int maxSubSteps = 1, btScalar fixedTimeStep = btScalar(1.)/btScalar(60.))
#include "btBulletDynamicsCommon.h" #include <stdio.h> int main(int argc, char** argv) { int i; ///-----initialization_start----- ///collision configuration contains default setup for memory, collision setup. Advanced users can create their own configuration. btDefaultCollisionConfiguration* collisionConfiguration = new btDefaultCollisionConfiguration(); ///use the default collision dispatcher. For parallel processing you can use a diffent dispatcher (see Extras/BulletMultiThreaded) btCollisionDispatcher* dispatcher = new btCollisionDispatcher(collisionConfiguration); ///btDbvtBroadphase is a good general purpose broadphase. You can also try out btAxis3Sweep. btBroadphaseInterface* overlappingPairCache = new btDbvtBroadphase(); ///the default constraint solver. For parallel processing you can use a different solver (see Extras/BulletMultiThreaded) btSequentialImpulseConstraintSolver* solver = new btSequentialImpulseConstraintSolver; btDiscreteDynamicsWorld* dynamicsWorld = new btDiscreteDynamicsWorld(dispatcher,overlappingPairCache,solver,collisionConfiguration); dynamicsWorld->setGravity(btVector3(0,-10,0)); ///-----initialization_end----- //keep track of the shapes, we release memory at exit. //make sure to re-use collision shapes among rigid bodies whenever possible! btAlignedObjectArray<btCollisionShape*> collisionShapes; ///create a few basic rigid bodies btCollisionShape* groundShape = new btBoxShape(btVector3(btScalar(50.),btScalar(50.),btScalar(50.))); btTransform groundTransform; groundTransform.setIdentity(); groundTransform.setOrigin(btVector3(0,-56,0)); btScalar mass(0.); //rigidbody is dynamic if and only if mass is non zero, otherwise static bool isDynamic = (mass != 0.f); btVector3 localInertia(0,0,0); if (isDynamic) groundShape->calculateLocalInertia(mass,localInertia); //using motionstate is optional, it provides interpolation capabilities, and only synchronizes 'active' objects btDefaultMotionState* myMotionState = new btDefaultMotionState(groundTransform); btRigidBody::btRigidBodyConstructionInfo rbInfo(mass,myMotionState,groundShape,localInertia); btRigidBody* body = new btRigidBody(rbInfo); //add the body to the dynamics world dynamicsWorld->addRigidBody(body); //cleanup in the reverse order of creation/initialization delete body; delete myMotionState; delete groundShape; delete dynamicsWorld; delete solver; delete overlappingPairCache; delete dispatcher; delete collisionConfiguration; }