An open API service indexing awesome lists of open source software.

https://github.com/kinetictactic/orbits

2D newtonian gravity sandbox.
https://github.com/kinetictactic/orbits

cpp gravity raylib sandbox simulation

Last synced: 5 months ago
JSON representation

2D newtonian gravity sandbox.

Awesome Lists containing this project

README

          

# Orbits! - A Newtonian Gravity Sandbox

**Orbits!** is a 2D gravity simulation built in C++ using [raylib](https://www.raylib.com/). It simulates Newtonian gravitational interactions between multiple bodies and visualizes their motion and orbital paths in real time. It uses **Velocity Verlet** integration for stable, energy-preserving orbits.

![orbits](assets/orbits.gif)

# Controls

- **Left Click Drag** to add a body and set its velocity. **Scroll** to change the mass of the body.
- **Right Click Drag** to pan the view.
- **Scroll** to zoom in and out.
- **Space** to pause the simulation.

### Touch controls:

- Use buttons for selecting modes.
- In PAN mode, drag to pan the view and pinch to zoom.
- In ADD mode, tap to add a body and drag to set its velocity. Pinch to change the mass of the body.

# Building

Use CMake to build the project. Raylib is automatically downloaded and built as a dependency.

```bash
mkdir build
cmake -B build -S . # -G "MinGW Makefiles"
cmake --build build # or make or mingw32-make
```

orbits.exe will be created in the build directory.

### Building for WebAssembly

To build the project for WebAssembly, you need to use the Emscripten toolchain. First, make sure you have Emscripten installed and set up correctly. Then, you can create a build using the following commands:

```bash
mkdir buildweb
emcmake cmake -B buildweb -S .
cmake --build buildweb

emrun --no_browser --port 8080 buildweb/index.html # to run the server
```

This will generate a WebAssembly version of the project that can be run in a web browser.