Skip to content

Commit 7eebf7d

Browse files
authored
Merge pull request #15 from Im-Rises/staging
Staging
2 parents 90037c8 + 05ba31a commit 7eebf7d

18 files changed

Lines changed: 259 additions & 85 deletions

.github/workflows/cpp-cmake-publish.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,15 @@ jobs:
2929
name: artifact-windows
3030
path: |
3131
./PhysicalEngine.exe
32+
./imgui.ini
3233
build-ubuntu:
3334
name: Build ubuntu
3435
runs-on: ubuntu-latest
3536
steps:
3637
- uses: actions/checkout@v3
3738
- name: Install libs
3839
run: |
39-
sudo apt-get install libsfml-dev
40+
sudo apt-get install libglfw3-dev
4041
sudo apt install xorg-dev
4142
- name: Configure CMake
4243
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}}
@@ -50,13 +51,14 @@ jobs:
5051
name: artifact-ubuntu
5152
path: |
5253
./PhysicalEngineLauncher
54+
./imgui.ini
5355
build-macos:
5456
name: Build macos
5557
runs-on: macos-latest
5658
steps:
5759
- uses: actions/checkout@v3
5860
- name: Install libs
59-
run: brew install sfml
61+
run: brew install glfw
6062
- name: Configure CMake
6163
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}}
6264
- name: Build
@@ -69,6 +71,7 @@ jobs:
6971
name: artifact-macos
7072
path: |
7173
./PhysicalEngineLauncher
74+
./imgui.ini
7275
release-project:
7376
name: Release project
7477
runs-on: ubuntu-latest

CMakePresets.json

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -28,26 +28,6 @@
2828
"cacheVariables": {
2929
"CMAKE_BUILD_TYPE": "Debug"
3030
}
31-
},
32-
{
33-
"name": "linux-debug",
34-
"displayName": "Linux Debug",
35-
"generator": "Ninja",
36-
"binaryDir": "${sourceDir}/out/build/${presetName}",
37-
"installDir": "${sourceDir}/out/install/${presetName}",
38-
"cacheVariables": {
39-
"CMAKE_BUILD_TYPE": "Debug"
40-
},
41-
"condition": {
42-
"type": "equals",
43-
"lhs": "${hostSystemName}",
44-
"rhs": "Linux"
45-
},
46-
"vendor": {
47-
"microsoft.com/VisualStudioRemoteSettings/CMake/1.0": {
48-
"sourceDir": "$env{HOME}/.vs/$ms{projectDirName}"
49-
}
50-
}
5131
}
5232
]
5333
}

PhysicalEngine/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ include_directories("${CMAKE_SOURCE_DIR}/dependencies/stb")
77
file(GLOB SRCS_HEADERS_IMGUI "${CMAKE_SOURCE_DIR}/dependencies/imgui/*.cpp" "${CMAKE_SOURCE_DIR}/dependencies/imgui/*.h")
88
file(GLOB SRCS_HEADERS_GLAD "${CMAKE_SOURCE_DIR}/dependencies/glad/**/*.c" "${CMAKE_SOURCE_DIR}/dependencies/glad/**/*.h")
99

10-
set(SRCS main.cpp PhysicalEngine.cpp Scene/Scene.cpp Scene/Camera.cpp InputManager.cpp Scene/GameObject.cpp Scene/Shader/Shader.cpp Vector3d/Vector3d.cpp Scene/Mesh/Mesh.cpp Scene/Mesh/Sphere/Sphere.cpp Scene/Mesh/Cuboid/Cube.cpp Scene/Mesh/Cuboid/CuboidRectangle.cpp Scene/Mesh/Cuboid/MyCube.cpp "Scene/Mesh/Cuboid/MyCubeUseIndice.cpp")
11-
set(HEADERS PhysicalEngine.h Scene/Scene.h Scene/Camera.h InputManager.h Scene/GameObject.h Scene/Shader/Shader.h Vector3d/Vector3d.h Scene/Mesh/Mesh.h Scene/Mesh/Sphere/Sphere.h Scene/Mesh/Cuboid/Cube.h Scene/Mesh/Cuboid/CuboidRectangle.h Scene/Mesh/Cuboid/MyCube.h "Scene/Mesh/Cuboid/MyCubeUseIndice.h")
10+
set(SRCS main.cpp PhysicalEngine.cpp Scene/Scene.cpp Scene/Camera.cpp InputManager.cpp Scene/GameObject.cpp Scene/Shader/Shader.cpp Vector3d/Vector3d.cpp Scene/Mesh/Mesh.cpp Scene/Mesh/Sphere/Sphere.cpp Scene/Mesh/Cuboid/Cube.cpp Scene/Mesh/Cuboid/CuboidRectangle.cpp Scene/Mesh/Cuboid/MyCube.cpp "Scene/Mesh/Cuboid/MyCubeUseIndice.cpp" "Integrator/Integrator.cpp" "Game.cpp" "Particule/Particule.cpp")
11+
set(HEADERS PhysicalEngine.h Scene/Scene.h Scene/Camera.h InputManager.h Scene/GameObject.h Scene/Shader/Shader.h Vector3d/Vector3d.h Scene/Mesh/Mesh.h Scene/Mesh/Sphere/Sphere.h Scene/Mesh/Cuboid/Cube.h Scene/Mesh/Cuboid/CuboidRectangle.h Scene/Mesh/Cuboid/MyCube.h "Integrable/Integrable.h" "Scene/Mesh/Cuboid/MyCubeUseIndice.h" "Integrator/Integrator.h" "Game.h" "Particule/Particule.h")
1212

1313
add_executable(${PROJECT_NAME} ${SRCS} ${HEADERS} ${SRCS_HEADERS_IMGUI} ${SRCS_HEADERS_GLAD})
1414

PhysicalEngine/Game.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#include "Game.h"
2+
#include "Scene/GameObject.h"
3+
#include "Scene/Mesh/Sphere/Sphere.h"
4+
5+
Game::Game() {
6+
m_p = new Particule();
7+
}
8+
9+
Game::~Game() {
10+
delete m_p;
11+
}
12+
13+
void Game::start(Scene* scene) {
14+
GameObject* gameobject = new GameObject(Sphere(1, 20, 20));
15+
scene->addGameObject(gameobject);
16+
gameobject->AddRigidbody(m_p);
17+
scene->addPhysicalComponent();
18+
}
19+
void Game::goLeft() {
20+
m_p->setSpeed(0, -0.5, 0);
21+
}
22+
void Game::goRight() {
23+
m_p->setSpeed(0, 0.5, 0);
24+
}
25+
void Game::goUp() {
26+
m_p->setSpeed(0.5, 0, 0);
27+
}
28+
void Game::goDown() {
29+
m_p->setSpeed(-0.5, 0, 0);
30+
}

PhysicalEngine/Game.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#ifndef GAME_H
2+
#define GAME_H
3+
4+
#include "Particule/Particule.h"
5+
#include "Scene/Scene.h"
6+
7+
class Game {
8+
private:
9+
Particule *m_p;
10+
11+
public:
12+
Game();
13+
~Game();
14+
void start(Scene *scene);
15+
void goLeft();
16+
void goRight();
17+
void goUp();
18+
void goDown();
19+
};
20+
#endif //GAME_H

PhysicalEngine/InputManager.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,25 @@ void InputManager::keyPressed(GLFWwindow *window, int key, PhysicalEngine *engin
4242
glfwSetWindowShouldClose(window, GLFW_TRUE);
4343
break;
4444
}
45+
case GLFW_KEY_RIGHT: {
46+
engine->m_game.goRight();
47+
break;
48+
}
49+
case GLFW_KEY_LEFT: {
50+
engine->m_game.goLeft();
51+
break;
52+
}
53+
case GLFW_KEY_UP: {
54+
engine->m_game.goUp();
55+
break;
56+
}
57+
case GLFW_KEY_DOWN : {
58+
engine->m_game.goDown();
59+
break;
60+
}
61+
default: {
62+
break;
63+
}
4564
}
4665
}
4766

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,18 @@
11
#ifndef INTEGRABLE_H
22
#define INTEGRABLE_H
33

4-
virtual class Integrable() {
5-
virtual void recalculateAll(float time);
6-
}
4+
#include "../Vector3d/Vector3d.h"
5+
6+
7+
class Integrable {
8+
9+
protected:
10+
Vector3d m_position;
11+
12+
public:
13+
const Vector3d& getPosition() const { return m_position; };
14+
15+
virtual void recalculateAll(float time){};
16+
};
717

818
#endif // !INTEGRABLE_H

PhysicalEngine/Integrator/Integrator.cpp

Lines changed: 36 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,38 +5,50 @@ Integrator::Integrator() {
55

66
}
77

8-
void Integrator::AddIntegrable(Particule& integrable) {
8+
void Integrator::AddIntegrable(Integrable* integrable) {
99
m_integrableList.push_back(integrable);
1010
}
1111

12+
1213
void Integrator::UpdateAll(double time) {
14+
m_fixedDeltaTime += time;
15+
m_timeToAdjustFrameRate += time;
16+
if (m_timeToAdjustFrameRate > 1 / m_fixeFrameRate) {
17+
for (Integrable* integrable : m_integrableList) {
18+
integrable->recalculateAll(m_fixedDeltaTime);
19+
}
20+
21+
22+
m_timeToAdjustFrameRate -= 1 / m_fixeFrameRate;
23+
if (m_timeToAdjustFrameRate > 1) {
24+
m_timeToAdjustFrameRate -= 1;
25+
}
26+
m_fixedDeltaTime = 0;
27+
}
1328

14-
for (Particule integrable : m_integrableList) {
15-
integrable.recalculateAll(time);
16-
}
1729
}
1830

1931
void Integrator::boucle() {
20-
double deltaTime=0;
21-
int numbTest = 0;
22-
while (!m_StopPhysics) {
23-
24-
auto start = std::chrono::high_resolution_clock::now();
25-
if (deltaTime != 0) {
26-
UpdateAll(deltaTime);
27-
}
28-
using namespace std::chrono_literals;
29-
std::this_thread::sleep_for(2000ms);
30-
auto end = std::chrono::high_resolution_clock::now();
32+
//double deltaTime=0;
33+
//int numbTest = 0;
34+
//while (!m_StopPhysics) {
35+
//
36+
// auto start = std::chrono::high_resolution_clock::now();
37+
// if (deltaTime != 0) {
38+
// UpdateAll(deltaTime);
39+
// }
40+
// using namespace std::chrono_literals;
41+
// std::this_thread::sleep_for(2000ms);
42+
// auto end = std::chrono::high_resolution_clock::now();
3143

3244

33-
deltaTime =std::chrono::duration_cast<std::chrono::nanoseconds>(end - start).count();
34-
deltaTime *= 0.000000001;
35-
printf("time = %f \n", deltaTime);
36-
37-
if (numbTest >= 5) {
38-
m_StopPhysics = true;
39-
}
40-
numbTest += 1;
41-
}
45+
// deltaTime =std::chrono::duration_cast<std::chrono::nanoseconds>(end - start).count();
46+
// deltaTime *= 0.000000001;
47+
// printf("time = %f \n", deltaTime);
48+
//
49+
// if (numbTest >= 5) {
50+
// m_StopPhysics = true;
51+
// }
52+
// numbTest += 1;
53+
//}
4254
}

PhysicalEngine/Integrator/Integrator.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,25 @@
11
#ifndef INTEGRATOR_H
22
#define INTEGRATOR_H
33

4-
#include "../../PhysicalEngine/Particule/Particule.h"
54
#include <iostream>
65
#include <iterator>
76
#include <list>
87
#include <chrono>
8+
#include "../Integrable/Integrable.h"
99

1010
class Integrator {
1111

1212
private:
13-
std::list<Particule> m_integrableList;
14-
bool m_StopPhysics = false;
13+
std::list<Integrable*> m_integrableList;
14+
int m_fixeFrameRate = 50;
15+
float m_fixedDeltaTime = 0;
16+
float m_timeToAdjustFrameRate = 0;
1517

1618
public:
1719

1820
Integrator();
1921

20-
void AddIntegrable(Particule &integrable);
22+
void AddIntegrable(Integrable * integrable);
2123

2224
void UpdateAll(double time);
2325

PhysicalEngine/Particule/Particule.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ void Particule::calculateSpeed(float time) {
1515
}
1616

1717
void Particule::recalculateAll(float time) {
18+
1819
calculateSpeed(time);
1920
calculatePosition(time);
2021

0 commit comments

Comments
 (0)