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

This simulation has been made much faster by what I believe is called a "quad tree" algorithm / structure implementation. I have never done one of those before (or any other tree algorithm), and didn't do any research prior to creating one - besides from the inspiration provided by the good folks on reddit's /r/programming sub, so I think it turned out pretty well all considering!

I thought it would be pretty cool to watch the simulation run at different optimisation levels, to see how much the optimisation technique reduces the accuracy of the simulation.

The second number at the top left of each "screen" represents the percentage of physics calculations saved by implementing the tree algorithm at different threshold levels. The higher the threshold, the less emphasis given to calculating individual objects and more emphasis given to calculating objects as groups.

This code also makes use of the first recursive function I've ever made, which worked really nicely!

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++ (v4)Excel with s0lly: 4. Lifetime Budget - A Simple Model ExampleProject Overlay 01: Setting the SceneFirst Games in C++: Krazy Karts (v0.5) - Splitscreen Multiplayer!Learn Pseudo 3D Graphics in Excel!2D Game Engine in C++: [4] PlanesFirst Games in C++: Dungeons and Flagons (v0.7) - FlagonsSimple 2D Game Engine in C++: First DraftLevel Up With... learnopengl.com2D Image Transforms - in Excel!!Excel with s0lly: 1. IntroAI Steering Behaviour Visualisation v4: Displaying Vectors
s0lly |

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

SHARE TO X SHARE TO REDDIT SHARE TO FACEBOOK WALLPAPER