Im-Rises / NBodySimulator

N-Body simulations made in C++ with OpenGL (Bruteforce, Barnes-Hut, GPU)

Home Page:https://im-rises.github.io/nbody-simulator-webgl/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

NBodySimulator

cmakeLogo cppLogo openglLogo glfwLogo

Description

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.

Videos

demo-video.mp4

Longer video πŸš€πŸš€ here πŸš€πŸš€

Dependencies

  • 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

How to use

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 the root of the project. If you don't do this, the UI will not be displayed correctly.

Windows

cmakeLogo

For Windows users you don't need to install the libs. You can just download the app and run it.

.\NBodySimulator.exe

Linux

cmakeLogo

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

MacOs

cmakeLogo

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

Compilation

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

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

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

MacOs

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

Controls

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.

Github-Actions

CodeQL CMake Cpp Cmake Publish flawfinder cpp-linter

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.

Libraries

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

Documentation

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

Contributors

Quentin MOREL:

GitHub contributors

About

N-Body simulations made in C++ with OpenGL (Bruteforce, Barnes-Hut, GPU)

https://im-rises.github.io/nbody-simulator-webgl/


Languages

Language:C++ 94.1%Language:CMake 2.4%Language:GLSL 2.0%Language:Batchfile 0.8%Language:Shell 0.7%