SolarSystemGL
Newtonian N-body solar-system simulator β€” native OpenGL & WebGL/WebAssembly
Loading...
Searching...
No Matches
SolarSystemGL

A real-time 3D Newtonian N-body solar-system simulator β€” runs natively (OpenGL 3.3) and in the browser (WebGL2 / WebAssembly).

C++ OpenGL WebGL2 Platform License

β–Ά Live demo: https://solar-system-gl.vercel.app πŸ“– API docs: Doxygen reference (served at /docs on the live site)

SolarSystemGL β€” the Sun bending the spacetime-curvature grid, with orbit trails

‍Tip: use docs/assets/hero.png as the repo's social preview image (Settings β†’ Social preview).

What it does

  • Newtonian N-body gravity in double precision (Velocity Verlet, fixed-timestep accumulator), rendered in single precision via a 1 WU = 10⁹ m unit conversion.
  • Nine-body solar system out of the box (Sun + 8 planets) with real masses, distances, and orbital velocities β€” plus bundled presets (asteroid belt, binary stars, TRAPPIST-1, blank slate).
  • Interactive editing: click a body to inspect/edit mass, density, position, velocity; add bodies on the fly (drag-to-place or a form) and watch orbits respond from the next physics step.
  • Visualisation: spacetime-curvature grid, orbit trails, path prediction, Lagrange points, procedural rings & atmospheres, emissive bloom, MSAA, procedural starfield.
  • Save / load simulations to a human-readable text format. On the web build, saves persist in the browser (IndexedDB via IDBFS) and can be exported / imported as files.
  • Runs on phones: touch gestures (drag to orbit, pinch to zoom), a responsive UI that reflows into a More… overflow menu on small screens, and a quality toggle (MSAA) for weaker GPUs.
  • Screenshots: F12 saves a BMP (downloaded in the browser, written to screenshots/ natively).

Responsive mobile layout with the overflow menu

Try it

The fastest way to play is the live demo link above β€” no install. To run locally, build either target below.

Build β€” desktop (Windows / MSVC 2022)

cmake -S . -B build
cmake --build build --config Release
build\Release\SolarSystemGL.exe

Requirements: Visual Studio 2022 (links a vendored glfw3.lib built for VC2022), CMake β‰₯ 3.16, a GPU with OpenGL 3.3. Linux/macOS use the find_package(glfw3) fallback path (see `docs/build.md`).

Build β€” web (WebAssembly)

Needs the Emscripten SDK + Ninja. See `BUILDING-WEB.md` for setup.

emcmake cmake -S . -B build-web -G Ninja -DCMAKE_BUILD_TYPE=Release
cmake --build build-web
python -m http.server -d build-web 8080 # then open http://localhost:8080/SolarSystemGL.html

Controls

Input Action
W A S D Move (free camera)
Right-click + drag Β· one-finger drag Look around / orbit
Scroll wheel Β· two-finger pinch Zoom (orbital) / change speed (free)
Left-click / tap a body Smooth-focus / set orbital target
Space R F 1 2 F1–F3 F5–F8 F11 F12 Pause Β· reset Β· focus Β· camera modes Β· view presets Β· bookmarks Β· demo Β· screenshot
Top action bar System picker, time scale, camera, save/load, settings (overflow β‹― on mobile)

Project layout

src/
β”œβ”€β”€ core/ Application, Camera, Window, Shader, Grid, Framebuffer,
β”‚ Screenshot, SaveLoad, WebPersistence (IDBFS), Platform
β”œβ”€β”€ objects/ CelestialBody (physics + identity), PlanetMesh (GL state)
β”œβ”€β”€ physics/ PhysicsSystem (integrator), PathPredictor, Lagrange
β”œβ”€β”€ ui/ UIManager, Actionbar, modals, Toast, Tutorial, UI (responsive helpers)
└── main.cpp Entry point
shaders/ GLSL sources (embedded at build time; rewritten to ES 3.00 on web)
web/ Emscripten HTML shell
third_party/ glad, GLFW, glm, ImGui (vendored)
docs/ Architecture, build, physics, render, user guide, API refs, ADRs

Documentation

  • Hand-written guides: docs/ β€” architecture, physics, rendering, user guide, ADRs.
  • Generated API reference: Doxygen, served at /docs on the live site (doxygen Doxyfile locally).

License

MIT β€” see [LICENSE](LICENSE). Contributions welcome: `CONTRIBUTING.md`.