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

Method initPhysics

examples/ExtendedTutorials/Bridge.cpp:43–125  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

41};
42
43void BridgeExample::initPhysics()
44{
45 m_guiHelper->setUpAxis(1);
46
47 createEmptyDynamicsWorld();
48
49 m_guiHelper->createPhysicsDebugDrawer(m_dynamicsWorld);
50
51 if (m_dynamicsWorld->getDebugDrawer())
52 m_dynamicsWorld->getDebugDrawer()->setDebugMode(btIDebugDraw::DBG_DrawWireframe + btIDebugDraw::DBG_DrawContactPoints);
53
54 ///create a few basic rigid bodies
55 btBoxShape* groundShape = createBoxShape(btVector3(btScalar(50.), btScalar(50.), btScalar(50.)));
56 m_collisionShapes.push_back(groundShape);
57
58 btTransform groundTransform;
59 groundTransform.setIdentity();
60 groundTransform.setOrigin(btVector3(0, -50, 0));
61 {
62 btScalar mass(0.);
63 createRigidBody(mass, groundTransform, groundShape, btVector4(0, 0, 1, 1));
64 }
65
66 //create two fixed boxes to hold the planks
67
68 {
69 //create a few dynamic rigidbodies
70 // Re-using the same collision is better for memory usage and performance
71 btScalar plankWidth = 0.4;
72 btScalar plankHeight = 0.2;
73 btScalar plankBreadth = 1;
74 btScalar plankOffset = plankWidth; //distance between two planks
75 btScalar bridgeWidth = plankWidth * TOTAL_PLANKS + plankOffset * (TOTAL_PLANKS - 1);
76 btScalar bridgeHeight = 5;
77 btScalar halfBridgeWidth = bridgeWidth * 0.5f;
78
79 btBoxShape* colShape = createBoxShape(btVector3(plankWidth, plankHeight, plankBreadth));
80
81 m_collisionShapes.push_back(colShape);
82
83 /// Create Dynamic Objects
84 btTransform startTransform;
85 startTransform.setIdentity();
86
87 btScalar mass(1.f);
88
89 //rigidbody is dynamic if and only if mass is non zero, otherwise static
90 bool isDynamic = (mass != 0.f);
91
92 btVector3 localInertia(0, 0, 0);
93 if (isDynamic)
94 colShape->calculateLocalInertia(mass, localInertia);
95
96 //create a set of boxes to represent bridge
97 btAlignedObjectArray<btRigidBody*> boxes;
98 int lastBoxIndex = TOTAL_PLANKS - 1;
99 for (int i = 0; i < TOTAL_PLANKS; ++i)
100 {

Callers

nothing calls this directly

Calls 11

btVector4Class · 0.85
getDebugDrawerMethod · 0.80
setDebugModeMethod · 0.80
btVector3Class · 0.50
setUpAxisMethod · 0.45
push_backMethod · 0.45
setIdentityMethod · 0.45
calculateLocalInertiaMethod · 0.45
addConstraintMethod · 0.45

Tested by

no test coverage detected