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)
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 Game Engine in C++: [4] Planes
This video illustrates the new feature of planes or layers in the engine.
This allows the game to have depth / pseudo 3D effects. Ideas for this would be e.g. allowing for pillars in front of a player obstructing the player view - possibly quite a nice game effect.
Next, Ill look to adding alpha blending to the drawing routine.
I will release all code on GitHub once Ive finalised the engine - and have nice looking code to boot!
Using the Chili Framework: http://wiki.planetchili.net/index.php... - thanks Chili! 2D Game Engine in C++: [4] Planes](https://i.ytimg.com/vi/qqHSr180imE/mqdefault.jpg)





