diff --git a/CMakeLists.txt b/CMakeLists.txt index ce314ec..3d4fa19 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,6 +11,9 @@ include_directories(${SFML_INCLUDE_DIR}) find_package(Eigen3 3.3 REQUIRED NO_MODULE) include_directories(${EIGEN3_INCLUDE_DIR}) +# Find and include ReactPhysics3D +find_package(ReactPhysics3D REQUIRED) + # Set up your project's source files set(SOURCES @@ -21,8 +24,8 @@ set(SOURCES src/game/game.h src/util/easylogging++.cc src/util/easylogging++.h - src/coordinates/isometric_coordinate_transformer.cpp - src/coordinates/isometric_coordinate_transformer.h + src/coordinates/coordinate_transformer.cpp + src/coordinates/coordinate_transformer.h src/coordinates/translated_coordinates.cpp src/coordinates/translated_coordinates.h src/coordinates/coordinates.h @@ -33,9 +36,17 @@ set(SOURCES src/game/game_factory.cpp src/game/game_factory.hpp) +set(PHYSICS_00_SOURCES + src/prototypes/physics_00.cpp + ) + # Add an executable target add_executable(Holesome ${SOURCES}) +add_executable(Physics_00 ${PHYSICS_00_SOURCES}) # Link SFML and other libraries to your executable target target_link_libraries(Holesome sfml-graphics sfml-audio) target_link_libraries(Holesome Eigen3::Eigen) +target_link_libraries(Holesome ReactPhysics3D::ReactPhysics3D) + +target_link_libraries(Physics_00 ReactPhysics3D::ReactPhysics3D) diff --git a/README.md b/README.md index 491eee3..fad188f 100644 --- a/README.md +++ b/README.md @@ -49,3 +49,19 @@ Potential expansions: ## Project Setup Install SFML and Eigen: `sudo apt install libsfml-dev libsfml-doc libeigen3-dev` + +### Compiling ReactPhysics3D from source + +Website: [ReactPhysics3D](https://www.reactphysics3d.com) + +1. Make sure cmake, g++ and make are installed +2. Clone the repository `git clone https://github.com/DanielChappuis/reactphysics3d.git` +3. Build and install the library +``` +cd reactphysics3d +mkdir build +cd build +cmake .. +make +sudo make install +``` diff --git a/src/prototypes/physics_00.cpp b/src/prototypes/physics_00.cpp new file mode 100644 index 0000000..ed8850b --- /dev/null +++ b/src/prototypes/physics_00.cpp @@ -0,0 +1,42 @@ +#include +#include + +// ReactPhysics3D namespace +using namespace reactphysics3d; + +// Main function +int main(int argc, char** argv) { + + // First you need to create the PhysicsCommon object. + // This is a factory module that you can use to create physics + // world and other objects. It is also responsible for + // logging and memory management + PhysicsCommon physicsCommon; + + // Create a physics world + PhysicsWorld* world = physicsCommon.createPhysicsWorld(); + + // Create a rigid body in the world + Vector3 position(0, 20, 0); + Quaternion orientation = Quaternion::identity(); + Transform transform(position, orientation); + RigidBody* body = world->createRigidBody(transform); + + const decimal timeStep = 1.0f / 60.0f; + + // Step the simulation a few steps + for (int i=0; i < 20; i++) { + + world->update(timeStep); + + // Get the updated position of the body + const Transform& transform = body->getTransform(); + const Vector3& position = transform.getPosition(); + + // Display the position of the body + std::cout << "Body Position: (" << position.x << ", " << + position.y << ", " << position.z << ")" << std::endl; + } + + return 0; +} \ No newline at end of file