2D N-Body Simulation in C++ (v3) @s0lly
2D N-Body Simulation in C++ (v3)  @s0lly
Uploaded April 2019 | Updated November 2026, 3 days ago
This engine allows the user to input thousands of objects and watch an n-body physics display occur.

I've improved the math calculation approach in this iteration (I was using scalar math rather than vector math before!!), as well as redesigning the code - I'm trying to get to grips with SoA design as a little learning project. The code speed has been dramatically improved, but many optimisations await.

I will be looking to add in more complex algorithms to further speed up this process - the folks on reddit have provided me with great materials on how to optimise this further. Should be interesting!

The number at the top left represents the number of objects in the simulation, and the number.at the center-top displays the milliseconds each frame takes to complete.

The codebase can be found here: github.com/s0lly/NBody-Physics - It relies on only a few functions and objects to do all the work, so hopefully it will be quite easy to understand and follow.

Please let me know how I could improve this!


Acknowledgements:

This was made using the Chili Framework: http://wiki.planetchili.net/index.php... - thanks Chili!

Music by Eric Skiff, song "All of Us" for the intro and "Arpanauts" for the main sequence. (Available at EricSkiff.com/music)
2D N-Body Simulation in C++ (v3)First Games in C++: Dungeons and Flagons (v0.5) - Collecting Torches and MenuVisualizing Simple CollisionsOpenGL Engine - Showcase 11: Particles and LightingCreating PixelArt - In Excel!Simple 2D N Body Simulation in C++First Games in C++ - PacMan (Update 1)First Games in C++: Dungeons and Flagons (v0.8) - Shadow Casting Improved!Map Visualizations - in Excel!!First Games in C++: Dungeons and Flagons (v0.95) - Simple AI, Torch Throwing & Main Menu LoadingNBody Sim: Trying out a Different Quad Tree Approach + VisualizationFirst Games in C++: Krazy Karts (v0.2)
s0lly |

2D N-Body Simulation in C++ (v3)

SHARE TO X SHARE TO REDDIT SHARE TO FACEBOOK WALLPAPER