Create the physics world
| 53 | |
| 54 | // Create the physics world |
| 55 | void PileScene::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 | rp3d::PhysicsWorld* physicsWorld = mPhysicsCommon.createPhysicsWorld(mWorldSettings); |
| 62 | physicsWorld->setEventListener(this); |
| 63 | mPhysicsWorld = physicsWorld; |
| 64 | |
| 65 | for (int i=0; i<NB_COMPOUND_SHAPES; i++) { |
| 66 | |
| 67 | // Create a convex mesh and a corresponding rigid in the physics world |
| 68 | Dumbbell* dumbbell = new Dumbbell(rp3d::BodyType::DYNAMIC, true, mPhysicsCommon, mPhysicsWorld, mMeshFolderPath); |
| 69 | |
| 70 | // Set the box color |
| 71 | dumbbell->setColor(mObjectColorDemo); |
| 72 | dumbbell->setSleepingColor(mSleepingColorDemo); |
| 73 | |
| 74 | // Change the material properties of the rigid body |
| 75 | rp3d::Material& capsuleMaterial = dumbbell->getCapsuleCollider()->getMaterial(); |
| 76 | capsuleMaterial.setBounciness(rp3d::decimal(0.2)); |
| 77 | rp3d::Material& sphere1Material = dumbbell->getSphere1Collider()->getMaterial(); |
| 78 | sphere1Material.setBounciness(rp3d::decimal(0.2)); |
| 79 | rp3d::Material& sphere2Material = dumbbell->getSphere2Collider()->getMaterial(); |
| 80 | sphere2Material.setBounciness(rp3d::decimal(0.2)); |
| 81 | |
| 82 | // Add the mesh the list of dumbbells in the scene |
| 83 | mDumbbells.push_back(dumbbell); |
| 84 | mPhysicsObjects.push_back(dumbbell); |
| 85 | } |
| 86 | |
| 87 | // Create all the boxes of the scene |
| 88 | for (int i=0; i<NB_BOXES; i++) { |
| 89 | |
| 90 | // Create a sphere and a corresponding rigid in the physics world |
| 91 | Box* box = new Box(rp3d::BodyType::DYNAMIC, true, BOX_SIZE, mPhysicsCommon, mPhysicsWorld, mMeshFolderPath); |
| 92 | |
| 93 | // Set the box color |
| 94 | box->setColor(mObjectColorDemo); |
| 95 | box->setSleepingColor(mSleepingColorDemo); |
| 96 | |
| 97 | // Change the material properties of the rigid body |
| 98 | rp3d::Material& material = box->getCollider()->getMaterial(); |
| 99 | material.setBounciness(rp3d::decimal(0.2)); |
| 100 | |
| 101 | // Add the sphere the list of sphere in the scene |
| 102 | mBoxes.push_back(box); |
| 103 | mPhysicsObjects.push_back(box); |
| 104 | } |
| 105 | |
| 106 | // Create all the spheres of the scene |
| 107 | for (int i=0; i<NB_SPHERES; i++) { |
| 108 | |
| 109 | // Create a sphere and a corresponding rigid in the physics world |
| 110 | Sphere* sphere = new Sphere(rp3d::BodyType::DYNAMIC, true, SPHERE_RADIUS, mPhysicsCommon, mPhysicsWorld, mMeshFolderPath); |
| 111 | |
| 112 | // Set the box color |
nothing calls this directly
no test coverage detected