| 20 | /// This is a Hello World program for running a basic Bullet physics simulation |
| 21 | |
| 22 | int main(int argc, char** argv) |
| 23 | { |
| 24 | ///-----includes_end----- |
| 25 | |
| 26 | int i; |
| 27 | ///-----initialization_start----- |
| 28 | |
| 29 | ///collision configuration contains default setup for memory, collision setup. Advanced users can create their own configuration. |
| 30 | btDefaultCollisionConfiguration* collisionConfiguration = new btDefaultCollisionConfiguration(); |
| 31 | |
| 32 | ///use the default collision dispatcher. For parallel processing you can use a diffent dispatcher (see Extras/BulletMultiThreaded) |
| 33 | btCollisionDispatcher* dispatcher = new btCollisionDispatcher(collisionConfiguration); |
| 34 | |
| 35 | ///btDbvtBroadphase is a good general purpose broadphase. You can also try out btAxis3Sweep. |
| 36 | btBroadphaseInterface* overlappingPairCache = new btDbvtBroadphase(); |
| 37 | |
| 38 | ///the default constraint solver. For parallel processing you can use a different solver (see Extras/BulletMultiThreaded) |
| 39 | btSequentialImpulseConstraintSolver* solver = new btSequentialImpulseConstraintSolver; |
| 40 | |
| 41 | btDiscreteDynamicsWorld* dynamicsWorld = new btDiscreteDynamicsWorld(dispatcher, overlappingPairCache, solver, collisionConfiguration); |
| 42 | |
| 43 | dynamicsWorld->setGravity(btVector3(0, -10, 0)); |
| 44 | |
| 45 | ///-----initialization_end----- |
| 46 | |
| 47 | //keep track of the shapes, we release memory at exit. |
| 48 | //make sure to re-use collision shapes among rigid bodies whenever possible! |
| 49 | btAlignedObjectArray<btCollisionShape*> collisionShapes; |
| 50 | |
| 51 | ///create a few basic rigid bodies |
| 52 | |
| 53 | //the ground is a cube of side 100 at position y = -56. |
| 54 | //the sphere will hit it at y = -6, with center at -5 |
| 55 | { |
| 56 | btCollisionShape* groundShape = new btBoxShape(btVector3(btScalar(50.), btScalar(50.), btScalar(50.))); |
| 57 | |
| 58 | collisionShapes.push_back(groundShape); |
| 59 | |
| 60 | btTransform groundTransform; |
| 61 | groundTransform.setIdentity(); |
| 62 | groundTransform.setOrigin(btVector3(0, -56, 0)); |
| 63 | |
| 64 | btScalar mass(0.); |
| 65 | |
| 66 | //rigidbody is dynamic if and only if mass is non zero, otherwise static |
| 67 | bool isDynamic = (mass != 0.f); |
| 68 | |
| 69 | btVector3 localInertia(0, 0, 0); |
| 70 | if (isDynamic) |
| 71 | groundShape->calculateLocalInertia(mass, localInertia); |
| 72 | |
| 73 | //using motionstate is optional, it provides interpolation capabilities, and only synchronizes 'active' objects |
| 74 | btDefaultMotionState* myMotionState = new btDefaultMotionState(groundTransform); |
| 75 | btRigidBody::btRigidBodyConstructionInfo rbInfo(mass, myMotionState, groundShape, localInertia); |
| 76 | btRigidBody* body = new btRigidBody(rbInfo); |
| 77 | |
| 78 | //add the body to the dynamics world |
| 79 | dynamicsWorld->addRigidBody(body); |
nothing calls this directly
no test coverage detected