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

Method createPhysicsWorld

testbed/scenes/cubes/CubesScene.cpp:55–90  ·  view source on GitHub ↗

Create the physics world

Source from the content-addressed store, hash-verified

53
54// Create the physics world
55void 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
93void CubesScene::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