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

Method createPhysicsWorld

testbed/scenes/boxtower/BoxTowerScene.cpp:62–102  ·  view source on GitHub ↗

Create the physics world

Source from the content-addressed store, hash-verified

60
61// Create the physics world
62void 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
105void BoxTowerScene::initBodiesPositions() {

Callers

nothing calls this directly

Calls 6

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

Tested by

no test coverage detected