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

Function main

helloworld/Main.cpp:15–47  ·  view source on GitHub ↗

Main function

Source from the content-addressed store, hash-verified

13
14// Main function
15int main(int argc, char** argv) {
16
17 // First you need to create the PhysicsCommon object. This is a factory module
18 // that you can use to create physics world and other objects. It is also responsible
19 // for logging and memory management
20 PhysicsCommon physicsCommon;
21
22 // Create a physics world
23 PhysicsWorld* world = physicsCommon.createPhysicsWorld();
24
25 // Create a rigid body in the world
26 Vector3 position(0, 20, 0);
27 Quaternion orientation = Quaternion::identity();
28 Transform transform(position, orientation);
29 RigidBody* body = world->createRigidBody(transform);
30
31 const decimal timeStep = 1.0f / 60.0f;
32
33 // Step the simulation a few steps
34 for (int i=0; i < 20; i++) {
35
36 world->update(timeStep);
37
38 // Get the updated position of the body
39 const Transform& transform = body->getTransform();
40 const Vector3& position = transform.getPosition();
41
42 // Display the position of the body
43 std::cout << "Body Position: (" << position.x << ", " << position.y << ", " << position.z << ")" << std::endl;
44 }
45
46 return 0;
47}

Callers

nothing calls this directly

Calls 3

createRigidBodyMethod · 0.80
createPhysicsWorldMethod · 0.45
updateMethod · 0.45

Tested by

no test coverage detected