Skip to content

This is a personal real-time 3D planet system simulation written in C++ using GLFW, OpenGL, imgui and implot, featuring Newtonian gravitational physics.

License

Notifications You must be signed in to change notification settings

Latfoo/gravitySimulator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

39 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Real-Time Gravity Simulation (C++)

This is a personal project where I'm learning to build a real-time simulation of celestial bodies using C++. It began as a simple 2D circle bouncing under gravity, modeled with basic kinematics. Since then, the simulation has evolved significantly: from kinematics to full Newtonian kinetics, and from 2D to 3D.

It now models gravitational interactions and perfectly elastic collisions between spherical objects, visualized in 3D using legacy OpenGL. A minimal GUI has been added to experiment with and observe the relative error of different numerical integrators. The GUI also includes controls for interacting with and managing the simulation at runtime.

This is my first attempt at building a full C++ application outside of university or academic exercises. Starting simple and steadily adding features and accuracy as I learn.

Simulation Preview

Video

Short Demo Video

⚠️ This is a GIF preview. Hence some stuttering or quality loss. Click the GIF to see a short demo video including GUI!

GUI Preview

GUI Preview

Notes

  • The code is work in progress
  • Currently only tested and built in Linux Ubuntu
  • CHANGELOG.md documents current features and development steps
  • Built with C++, OpenGL, GLFW, Imgui, Implot

Further Goals

  • Make it interactive --> enable manual configuration of initial conditions via GUI Window
  • Improve physical accuracy and structure over time
  • Make it cross-platform compatible
  • Learn by building, not just reading

Build

Necessary Packages

These are the required packages for building and running the simulation:

Linux (Ubuntu/Debian)

sudo apt update
sudo apt install libgl1-mesa-dev libglu1-mesa-dev libglfw3-dev cmake

If apt is not available (e.g. on Arch or Fedora), use your distribution’s package manager instead (like pacman or dnf).

MacOS

To install required dependencies on macOS, you can use Homebrew, the macOS package manager. Once Homebrew is installed, install GLFW:

brew install glfw cmake

OpenGL is already included with macOS as a system framework (OpenGL.framework), so no additional OpenGL installation is required.

Build Instructions (Linux and MacOS only):

Build the project:

# Create and enter the build directory
mkdir build && cd build

# Configure the build system (only to be repeated after major changes like new dependencies or files)
cmake ..

# Compile the project 
cmake --build .

Run the simulation:

./GravitySim

Author

Latfoo

About

This is a personal real-time 3D planet system simulation written in C++ using GLFW, OpenGL, imgui and implot, featuring Newtonian gravitational physics.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published