This project is an implementation of a 2D gravity simulation using the Barnes-Hut algorithm and a quadtree data structure. The simulation is written in C++ and utilizes the SFML library for rendering.
Please note that the current implementation is not optimal, and there are numerous improvements that can be made.
- use MVC design pattern
- fix the quadtree instead of reconstructing it
- tried it, i think its slower but i have to look at it again some other time
- change datastructure from an array of objects (AoO) to an object of arrays (OoA), this should improve memory access
- lastly implement real multithreading and if possible do calculations directly on the gpu
- kinda did it i think, it runs with
$5-7$ fps with$n=500'000$
- kinda did it i think, it runs with
- some graphics API, not SFML lol
- implement spacial hashing and some integrator for the physics
The Barnes-Hut algorithm is a method used to compute the gravitational forces between bodies in a system, where each body has a mass, position, and velocity. A quadtree is used to divide the 2D space containing the bodies into distinct sections. This allows the algorithm to calculate gravitational forces more efficiently.
This simulation is done with
The Barnes-Hut algorithm is not perfect; therefore, this simulation only provides an approximation of a real gravitational system. In a real
Unfortunately, the two-dimensional gravitational force appears incorrect and is not as interesting as its three-dimensional counterpart. As a result, this simulation represents just a
To run the simulation, you will need a compiler that supports C++11 or later and the SFML library.
- GCC, Clang, or another C++11-compatible compiler
- SFML library
To build and run the simulation:
- Clone the repository:
git clone https://github.com/mazzeaar/gravity_sim.git
- Navigate to the project directory:
cd gravity_sim
- Build the project:
cmake .
- Run the simulation:
make run
or
make && ./gravity_sim
- myself
- gpt4
- the guy who invented the barnes-hut algorithm
Imagine having a license lol