It helps not being an idiot

This commit is contained in:
maelstrom 2024-09-28 15:55:27 +02:00
parent 47f36c814c
commit 27aabfba0e
6 changed files with 51 additions and 4 deletions

View file

@ -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)
target_link_libraries(${PROJECT_NAME} ${SDL2_LIBRARIES} ${GLEW_LIBRARIES} ${GLUT_LIBRARIES} OpenGL::GL OpenGL::GLU glfw glm::glm assimp ReactPhysics3D::ReactPhysics3D)

View file

@ -5,8 +5,9 @@
#include <stdio.h>
#include <vector>
#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);

View file

@ -1,6 +1,6 @@
#pragma once
#include <glm/glm.hpp>
#include "material.h"
#include "rendering/material.h"
struct Part {
glm::vec3 position;

View file

@ -0,0 +1,34 @@
#include <reactphysics3d/reactphysics3d.h>
#include <vector>
#include "../part.h"
#include "simulation.h"
namespace rp = reactphysics3d;
extern std::vector<Part> 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;
}

4
src/physics/simulation.h Normal file
View file

@ -0,0 +1,4 @@
#pragma once
void simulationInit();
void physicsStep(float deltaTime);

View file

@ -11,7 +11,7 @@
#include "mesh.h"
#include "defaultmeshes.h"
#include "../camera.h"
#include "part.h"
#include "../part.h"
#include "renderer.h"