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