diff --git a/CMakeLists.txt b/CMakeLists.txt index d13dfa3..afb4dd9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -25,9 +25,11 @@ find_package(glm CONFIG REQUIRED) find_package(assimp REQUIRED) +find_package(ReactPhysics3D REQUIRED) + file(MAKE_DIRECTORY bin) file(GLOB_RECURSE SOURCES "src/*.cpp" "src/*.h") add_executable(${PROJECT_NAME} ${SOURCES}) set_target_properties(${PROJECT_NAME} PROPERTIES OUTPUT_NAME "gltest") -target_link_libraries(${PROJECT_NAME} ${SDL2_LIBRARIES} ${GLEW_LIBRARIES} ${GLUT_LIBRARIES} OpenGL::GL OpenGL::GLU glfw glm::glm assimp) \ No newline at end of file +target_link_libraries(${PROJECT_NAME} ${SDL2_LIBRARIES} ${GLEW_LIBRARIES} ${GLUT_LIBRARIES} OpenGL::GL OpenGL::GLU glfw glm::glm assimp ReactPhysics3D::ReactPhysics3D) \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index bfdcd17..f4c1919 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -5,8 +5,9 @@ #include #include -#include "rendering/part.h" +#include "part.h" #include "rendering/renderer.h" +#include "physics/simulation.h" #include "camera.h" void errorCatcher(int id, const char* str); @@ -45,10 +46,16 @@ int main() { } }); + simulationInit(); renderInit(window); + float lastTime = glfwGetTime(); do { + float deltaTime = glfwGetTime() - lastTime; + lastTime = glfwGetTime(); + processInput(window); + physicsStep(deltaTime); render(window); glfwSwapBuffers(window); diff --git a/src/rendering/part.h b/src/part.h similarity index 81% rename from src/rendering/part.h rename to src/part.h index 7268d2b..8da119b 100644 --- a/src/rendering/part.h +++ b/src/part.h @@ -1,6 +1,6 @@ #pragma once #include -#include "material.h" +#include "rendering/material.h" struct Part { glm::vec3 position; diff --git a/src/physics/simulation.cpp b/src/physics/simulation.cpp new file mode 100644 index 0000000..0ae82dc --- /dev/null +++ b/src/physics/simulation.cpp @@ -0,0 +1,34 @@ +#include +#include +#include "../part.h" + +#include "simulation.h" + +namespace rp = reactphysics3d; + +extern std::vector parts; + +rp::PhysicsCommon physicsCommon; +rp::PhysicsWorld* world; +rp::RigidBody* body; + +void simulationInit() { + world = physicsCommon.createPhysicsWorld(); + + rp::Vector3 position(0, 20, 0); + rp::Quaternion orientation = rp::Quaternion::identity(); + rp::Transform transform(position, orientation); + body = world->createRigidBody(transform); +} + +void physicsStep(float deltaTime) { + // Step the simulation a few steps + world->update(deltaTime); + + // Get the updated position of the body + const rp::Transform& transform = body->getTransform(); + const rp::Vector3& position = transform.getPosition(); + + // Display the position of the body + std::cout << "Body Position: (" << position.x << ", " << position.y << ", " << position.z << ")" << std::endl; +} \ No newline at end of file diff --git a/src/physics/simulation.h b/src/physics/simulation.h new file mode 100644 index 0000000..38ba9ea --- /dev/null +++ b/src/physics/simulation.h @@ -0,0 +1,4 @@ +#pragma once + +void simulationInit(); +void physicsStep(float deltaTime); \ No newline at end of file diff --git a/src/rendering/renderer.cpp b/src/rendering/renderer.cpp index c4e175c..195a99f 100644 --- a/src/rendering/renderer.cpp +++ b/src/rendering/renderer.cpp @@ -11,7 +11,7 @@ #include "mesh.h" #include "defaultmeshes.h" #include "../camera.h" -#include "part.h" +#include "../part.h" #include "renderer.h"