MCPcopy Create free account
hub / github.com/bulletphysics/bullet3 / main

Function main

examples/HelloWorld/HelloWorld.cpp:22–180  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

20/// This is a Hello World program for running a basic Bullet physics simulation
21
22int 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);

Callers

nothing calls this directly

Calls 15

getMotionStateMethod · 0.80
btVector3Class · 0.50
upcastFunction · 0.50
setGravityMethod · 0.45
push_backMethod · 0.45
setIdentityMethod · 0.45
calculateLocalInertiaMethod · 0.45
addRigidBodyMethod · 0.45
stepSimulationMethod · 0.45
getXMethod · 0.45
getYMethod · 0.45

Tested by

no test coverage detected