| 41 | }; |
| 42 | |
| 43 | void 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 | { |
nothing calls this directly
no test coverage detected