This project is a n-body-type simulation of a galaxy. It utilizes a compute shader for real-time calculations of gravitational interactions between randomly generated spheres acting as stars. The simulation, built using OpenGL and GLFW, provides an environment to observe the effects of gravity, dark matter, and dark energy on celestial bodies as they move and interact in a virtual space. For this project, I was inspired by Angel Uriot. 🌌
- git (https://git-scm.com/downloads)
- cmake (https://cmake.org/download)
- make (http://ftp.gnu.org/gnu/make)
- g++ (https://gcc.gnu.org) you can use another compiler if you want
- glfw (https://www.glfw.org/)
- glad (https://glad.dav1d.de/)
- glm (https://glm.g-truc.net/)
- imgui (https://github.com/ocornut/imgui)
- stb (https://github.com/nothings/stb/) used stb_image for icon
> git clone https://github.com/ahmedkerouat/galaxySimulator.git
> cd galaxySimulator
> mkdir build
> cd build
> cmake ..
> make
> ./galaxySimulator
The project consists of multiple header files, each providing specific functionalities. Here's an overview of the key components:
-
sphere.h: This header file contains the Sphere class, which is used for rendering stars. It allows customization of the number of vertices and triangles that make up a sphere.
-
shader.h: The shader.h file provides functions for loading and compiling OpenGL shaders and creating shader programs. For instance, it includes a utility function, loadShaderSource, to load shader source code from external files.
-
shader_config.h: This header includes the configuration data for fragment & vertex shaders.
-
camera.h: The Camera class defined in this header is responsible for controlling the view and perspective within the simulation. It manages user input for camera movements.
You can control various aspects of the simulation through the user interface.
-
Number of Spheres: Adjust the number of randomly generated celestial spheres.
-
Radius: Customizes the radius of the galaxy.
-
Epsilon: A simulation parameter that limits the interaction between the spheres.
-
Delta Time: Specifies the time step for the simulation.
-
Dark Matter Mass: Sets the mass of dark matter within the simulation.
-
Dark Energy Effect: Determines the acceleration due to dark energy.
-
Pause/Resume: Pauses and resumes the simulation.
Within the simulation, you can control diverse camera parameters :
-
Right Mouse Button : Controls the camera's rotation.
-
Left Mouse Button : Controls the camera's position.
-
Scroll: Zoom in and out of the simulation.
-
Space button : Resets camera position to default.
On the menu Ctrl + Lmb to change precisely a simulation parameter using the slider
If you have a suggestion to improve the project, please feel free to create a pull request. Alternatively, you can open an issue to discuss your ideas.
Project is licensed under the MIT LICENSE