MCPcopy Create free account
hub / github.com/DanielChappuis/reactphysics3d / createPhysicsWorld

Method createPhysicsWorld

testbed/scenes/bridge/BridgeScene.cpp:102–159  ·  view source on GitHub ↗

Create the physics world

Source from the content-addressed store, hash-verified

100
101// Create the physics world
102void BridgeScene::createPhysicsWorld() {
103
104 // Gravity vector in the physics world
105 mWorldSettings.gravity = rp3d::Vector3(mEngineSettings.gravity.x, mEngineSettings.gravity.y, mEngineSettings.gravity.z);
106
107 // Create the physics world for the physics simulation
108 mPhysicsWorld = mPhysicsCommon.createPhysicsWorld(mWorldSettings);
109 mPhysicsWorld->setEventListener(this);
110
111 for (int b=0; b < NB_BRIDGES; b++) {
112
113 // Create all the boxes of the scene
114 for (int i=0; i<NB_BOXES; i++) {
115
116 const uint boxIndex = b * NB_BOXES + i;
117
118 // Create a box and a corresponding rigid in the physics world
119 rp3d::BodyType type = i == 0 || i == NB_BOXES-1 ? rp3d::BodyType::STATIC : rp3d::BodyType::DYNAMIC;
120 mBoxes[boxIndex] = new Box(type, true, BOX_SIZE, mPhysicsCommon, mPhysicsWorld, mMeshFolderPath);
121
122 // Set the box color
123 mBoxes[boxIndex]->setColor(mFloorColorDemo);
124 mBoxes[boxIndex]->setSleepingColor(mSleepingColorDemo);
125
126 // Change the material properties of the rigid body
127 rp3d::Material& material = mBoxes[boxIndex]->getCollider()->getMaterial();
128 material.setBounciness(rp3d::decimal(0.0));
129
130 // Add the box the list of boxes in the scene
131 mPhysicsObjects.push_back(mBoxes[boxIndex]);
132 }
133 }
134
135 // Create all the spheres of the scene
136 for (int i=0; i<NB_BRIDGES; i++) {
137
138 // Create a sphere and a corresponding rigid in the physics world
139 mSpheres[i] = new Sphere(rp3d::BodyType::DYNAMIC, true, SPHERE_RADIUS, mPhysicsCommon, mPhysicsWorld, mMeshFolderPath);
140
141 // Set the box color
142 mSpheres[i]->setColor(mObjectColorDemo);
143 mSpheres[i]->setSleepingColor(mSleepingColorDemo);
144
145 // Change the material properties of the rigid body
146 rp3d::Material& material = mSpheres[i]->getCollider()->getMaterial();
147 material.setBounciness(rp3d::decimal(0.2));
148 mSpheres[i]->getRigidBody()->setMass(SPHERE_MASS);
149
150 // Add the sphere the list of sphere in the scene
151 mPhysicsObjects.push_back(mSpheres[i]);
152 }
153
154 // Set the position of the boxes before the joints creation
155 initBodiesPositions();
156
157 // Create the Ball-and-Socket joints
158 createJoints();
159}

Callers

nothing calls this directly

Calls 8

setEventListenerMethod · 0.80
setColorMethod · 0.80
setSleepingColorMethod · 0.80
setBouncinessMethod · 0.80
Vector3Class · 0.50
getColliderMethod · 0.45
setMassMethod · 0.45
getRigidBodyMethod · 0.45

Tested by

no test coverage detected