This is a simple n-body simulator using bruteforce made with OpenGL in C++ with the help of the ImGui library for the UI.
You can choose between different types of simulation:
- CPU
- GPU
- Barnes-Hut algorithm
The different algorithm still need some work to be optimized, but they are currently working.
You can also test the webgl version 🚀🚀 here 🚀🚀
The source code of the webgl version is available here.
demo-video.mp4
Longer video 🚀🚀 here 🚀🚀
- OpenGL version: 4.6.0
- GLSL version: 4.60
- GLFW version: 3.3.8
- Glad version: 0.1.36
- ImGui version: 1.89.4 WIP
- GLM version: 0.9.8
To download the app, you can click one of the icons below (depending on your operating system). You can also click the release section of the GitHub page.
Depending on you operating system
you will need to install some libs, they are installed differently depending on your
system, please follow one of the section below Windows
or Linux
or MacOs
.
For the compilation, follow the section Compilation
.
The controls are described in the section Controls
.
Warning Be sure to put the
imgui.ini
file in the same folder as the executable. You can find it in theroot
of the project. If you don't do this, the UI will not be displayed correctly.
For Windows users you don't need to install the libs. You can just download the app and run it.
.\NBodySimulator.exe
For Linux users, you need to install the GLFW lib, to do so type one of the following commands:
sudo apt-get install libglfw3
or if you're a developer and want to compile the app, please install this version of GLFW:
sudo apt-get install libglfw3-dev
Then you can start by double-clicking the executable of typing the following command next to it:
./NBodySimulatorLauncher
For macOS users you will need to install Brew, please follow the instruction in the link below:
https://brew.sh
Once it is installed, you can type the following command to install GLFW.
brew install glfw
Then you can start by double-clicking the executable of typing the following command next to it:
./NBodySimulatorLauncher
To compile the app, the first thing you need to do is install a C++ compiler:
- Visual Studio (MSVC)
- Mingw
- ...
You also need to install Cmake:
https://cmake.org
Once your environment is set up, depending on your operating system you'll need to install some libs before compiling
the project. Refer to the section below Windows
or Linux
or MacOs
.
Windows users can directly compile the project by typing the following command at the project root folder:
cmake -B . -DCMAKE_BUILD_TYPE=Release
then
cmake --build . --config Release
Linux's users need to install some libs before compiling the project:
First thing to do is to install CMake, type the following command to install it.
sudo apt-get install cmake
You also need to install the GLFW lib. Type the following command at the project root.
sudo apt-get install libglfw3-dev
You are now able to compile the project. Go to the project root and type the following command:
cmake -B . -DCMAKE_BUILD_TYPE=Release
then
cmake --build . --config Release
For macOS user, you should install brew package manager by following the instructions in the link below:
https://brew.sh
Then type the following command to install cmake:
brew install cmake
and this one to install GLFW
brew install glfw
You are now able to compile the project. Go to the project root and type the following command:
cmake -B . -DCMAKE_BUILD_TYPE=Release
then
cmake --build . --config Release
The speed and some parameters can be modified directly in the ImGui windows.
Action | Key |
---|---|
Translate camera | WASD (← → ↑ ↓) |
Pause/Resume | P |
Move up/down camera | SPACE/SHIFT |
Rotate camera | Right Mouse Button + Mouse movement |
Fullscreen | F11 |
Exit app | ESC |
Show/Hide UI | U |
Note You can the inputs by changing their attribution in the
InputManager.cpp
file, if so you'll need to compile the project.
The project is set with a set of different scripts:
- CodeQL: This script is used to check the code for security issues.
- CMake: This script is used to build the project.
- Cpp Cmake Publish: This script is used to publish the project on GitHub.
- Flawfinder: This script is used to check the code for security issues.
- Cpp Linter: This script is used to check the code for security issues.
glfw:
https://www.glfw.org/docs/latest/
glm:
https://glm.g-truc.net/0.9.9/index.html
glad:
https://glad.dav1d.de/
Dear ImGui:
https://github.com/ocornut/imgui
OpenGL:
https://www.opengl.org/
glm:
https://glm.g-truc.net/0.9.9/index.html
learnopengl (OpenGL tutorial):
https://learnopengl.com/In-Practice/2D-Game/Particles
OpenCL NBody example:
https://github.com/KhronosGroup/OpenCL-SDK/tree/f510201a092363b66969888df49c68721ca2c4fb/samples/extensions/khr/nbody
Quentin MOREL:
- @Im-Rises
- https://github.com/Im-Rises