Create the physics world
| 60 | |
| 61 | // Create the physics world |
| 62 | void BoxTowerScene::createPhysicsWorld() { |
| 63 | |
| 64 | // Gravity vector in the physics world |
| 65 | mWorldSettings.gravity = rp3d::Vector3(mEngineSettings.gravity.x, mEngineSettings.gravity.y, mEngineSettings.gravity.z); |
| 66 | |
| 67 | // Create the physics world for the physics simulation |
| 68 | mPhysicsWorld = mPhysicsCommon.createPhysicsWorld(mWorldSettings); |
| 69 | mPhysicsWorld->setEventListener(this); |
| 70 | |
| 71 | // Create all the boxes of the scene |
| 72 | for (int i=0; i<NB_BOXES; i++) { |
| 73 | |
| 74 | // Create a sphere and a corresponding rigid in the physics world |
| 75 | Box* box = new Box(rp3d::BodyType::DYNAMIC, true, BOX_SIZE, mPhysicsCommon, mPhysicsWorld, mMeshFolderPath); |
| 76 | |
| 77 | // Set the box color |
| 78 | box->setColor(mObjectColorDemo); |
| 79 | box->setSleepingColor(mSleepingColorDemo); |
| 80 | |
| 81 | // Change the material properties of the rigid body |
| 82 | rp3d::Material& material = box->getCollider()->getMaterial(); |
| 83 | material.setBounciness(rp3d::decimal(0.2)); |
| 84 | |
| 85 | // Add the sphere the list of boxes in the scene |
| 86 | mBoxes.push_back(box); |
| 87 | mPhysicsObjects.push_back(box); |
| 88 | } |
| 89 | |
| 90 | // ---------- Create the floor --------- |
| 91 | |
| 92 | mFloor = new Box(rp3d::BodyType::STATIC, true, FLOOR_SIZE, mPhysicsCommon, mPhysicsWorld, mMeshFolderPath); |
| 93 | mPhysicsObjects.push_back(mFloor); |
| 94 | |
| 95 | // Set the box color |
| 96 | mFloor->setColor(mFloorColorDemo); |
| 97 | mFloor->setSleepingColor(mFloorColorDemo); |
| 98 | |
| 99 | // Change the material properties of the rigid body |
| 100 | rp3d::Material& material = mFloor->getCollider()->getMaterial(); |
| 101 | material.setBounciness(rp3d::decimal(0.2)); |
| 102 | } |
| 103 | |
| 104 | // Initialize the bodies positions |
| 105 | void BoxTowerScene::initBodiesPositions() { |
nothing calls this directly
no test coverage detected