| 40 | }; |
| 41 | |
| 42 | void SimpleBoxExample::initPhysics() |
| 43 | { |
| 44 | m_guiHelper->setUpAxis(1); |
| 45 | |
| 46 | createEmptyDynamicsWorld(); |
| 47 | |
| 48 | m_guiHelper->createPhysicsDebugDrawer(m_dynamicsWorld); |
| 49 | |
| 50 | if (m_dynamicsWorld->getDebugDrawer()) |
| 51 | m_dynamicsWorld->getDebugDrawer()->setDebugMode(btIDebugDraw::DBG_DrawWireframe + btIDebugDraw::DBG_DrawContactPoints); |
| 52 | |
| 53 | ///create a few basic rigid bodies |
| 54 | btBoxShape* groundShape = createBoxShape(btVector3(btScalar(50.), btScalar(50.), btScalar(50.))); |
| 55 | m_collisionShapes.push_back(groundShape); |
| 56 | |
| 57 | btTransform groundTransform; |
| 58 | groundTransform.setIdentity(); |
| 59 | groundTransform.setOrigin(btVector3(0, -50, 0)); |
| 60 | { |
| 61 | btScalar mass(0.); |
| 62 | createRigidBody(mass, groundTransform, groundShape, btVector4(0, 0, 1, 1)); |
| 63 | } |
| 64 | |
| 65 | { |
| 66 | //create a few dynamic rigidbodies |
| 67 | // Re-using the same collision is better for memory usage and performance |
| 68 | btBoxShape* colShape = createBoxShape(btVector3(1, 1, 1)); |
| 69 | |
| 70 | m_collisionShapes.push_back(colShape); |
| 71 | |
| 72 | /// Create Dynamic Objects |
| 73 | btTransform startTransform; |
| 74 | startTransform.setIdentity(); |
| 75 | |
| 76 | btScalar mass(1.f); |
| 77 | |
| 78 | //rigidbody is dynamic if and only if mass is non zero, otherwise static |
| 79 | bool isDynamic = (mass != 0.f); |
| 80 | |
| 81 | btVector3 localInertia(0, 0, 0); |
| 82 | if (isDynamic) |
| 83 | colShape->calculateLocalInertia(mass, localInertia); |
| 84 | |
| 85 | startTransform.setOrigin(btVector3( |
| 86 | btScalar(0), |
| 87 | btScalar(20), |
| 88 | btScalar(0))); |
| 89 | createRigidBody(mass, startTransform, colShape); |
| 90 | } |
| 91 | |
| 92 | m_guiHelper->autogenerateGraphicsObjects(m_dynamicsWorld); |
| 93 | } |
| 94 | |
| 95 | void SimpleBoxExample::renderScene() |
| 96 | { |
nothing calls this directly
no test coverage detected