I built a real-time N-body gravity simulator in C++/OpenGL — physically accurate with 4th-order Yoshida integration
Yo Reddit!
Finally shipping something I've been building for a while — a gravitational N-body simulator where I was pretty obsessed with making the physics realistic.
The integrator is Yoshida 4th-order symplectic — a step above Velocity Verlet. It runs 3 force evaluations per time step with coefficients derived to cancel lower-order error terms, giving much better long-term energy conservation for orbital sims.
Everything else in real units:
\- G = 6.674×10⁻¹¹ in full SI throughout
\- Planetary masses from real solar mass ratios
\- Orbital distances in real AU, time steps of 1 real day
\- Initial velocities from v = √(GM/r) so orbits are correct from frame 1
\- Momentum-conserving mergers when bodies collide
\- Live readout of speed in km/s and distance in AU — verifiable against NASA
Built with C++17, OpenGL 4.6, GLFW, GLM, ImGui, and stb_easy_font. Runs on Windows and Linux.
Would love any feedback — code structure, physics mistakes, whatever. I also have a bunch of open tickets if anyone wants to jump in (CMake, planet textures, Lagrange points...). And if you dig it, a star on the repo would make my day!
GitHub: https://github.com/kikikian/orrery
https://redd.it/1siaqgc
@r_cpp
Post #24951
22