TGViewer
C++ - Reddit C++ - Reddit @r_cpp · 230 subscribers
Post #24951 22
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
GitHub GitHub - KikiKian/orrery: Orerry (noun.) — a mechanical, usually clockwork-driven model of the solar system that illustrates the… Orerry (noun.) — a mechanical, usually clockwork-driven model of the solar system that illustrates the relative positions and motions of planets and moons, typically with a sun at the center. - Kik...
More from @r_cpp
  1. Oct 6, 2026WasmBolt — The LLVM Project in your browser https://anutosh21.github.io/WasmBolt/ https://…
  2. Oct 6, 2026How I speed up my overall build times by 4x and incremental builds by 9x for test builds *…
  3. Oct 6, 2026Why do people on Windows mostly choose Visual Studio? https://redd.it/1weku08 @r_cpp
  4. Oct 6, 2026Jonas Persson: Making every byte count https://youtu.be/GbwrztrY4kc https://redd.it/1wf1l3…
  5. Oct 6, 2026It annoys me that coroutines are described as "functions that can be suspended" Any functi…
  6. Oct 6, 2026==2896379== logger no timeout configured, using default 1000 ms ==2896379== ==2896379== HE…
Threads Profile ViewerView any public Threads profile without an account.Open ThreadLook →Writing with AI? Make it sound human.Metric37 rewrites AI drafts so they read naturally. Free AI detector, 1,500 words free.Try Metric37 →