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

Method initPhysics

examples/ExtendedTutorials/Chain.cpp:43–114  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

41};
42
43void ChainExample::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 {
67 //create a few dynamic rigidbodies
68 // Re-using the same collision is better for memory usage and performance
69 btBoxShape* colShape = createBoxShape(btVector3(1, 1, 0.25));
70
71 m_collisionShapes.push_back(colShape);
72
73 /// Create Dynamic Objects
74 btTransform startTransform;
75 startTransform.setIdentity();
76
77 btScalar mass(1.f);
78
79 //rigidbody is dynamic if and only if mass is non zero, otherwise static
80 bool isDynamic = (mass != 0.f);
81
82 btVector3 localInertia(0, 0, 0);
83 if (isDynamic)
84 colShape->calculateLocalInertia(mass, localInertia);
85
86 btAlignedObjectArray<btRigidBody*> boxes;
87 int lastBoxIndex = TOTAL_BOXES - 1;
88 for (int i = 0; i < TOTAL_BOXES; ++i)
89 {
90 startTransform.setOrigin(btVector3(
91 btScalar(0),
92 btScalar(5 + i * 2),
93 btScalar(0)));
94 boxes.push_back(createRigidBody((i == lastBoxIndex) ? 0 : mass, startTransform, colShape));
95 }
96
97 //add N-1 spring constraints
98 for (int i = 0; i < TOTAL_BOXES - 1; ++i)
99 {
100 btRigidBody* b1 = boxes[i];

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