Skip to content

Latest commit

ย 

History

12 Commits

Folders and files

NameName
Last commit message
Last commit date
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐ŸŒŒ Black Hole Simulation

Black Hole Simulation Demo

A real-time 2D Black Hole & Orbital Mechanics Simulation built using Modern C++20 and OpenGL.

C++ OpenGL GLFW GLM CMake License


๐ŸŽฅ Demo

The original recording can be viewed here:

๐Ÿ“น Watch Full Demo


๐Ÿ“– Overview

This project is a real-time physics simulation of a black hole interacting with surrounding celestial bodies through Newtonian gravity.

The simulation demonstrates stable orbital mechanics, gravitational attraction, and fixed timestep physics while rendering everything using Modern OpenGL and GLSL shaders.

The project was built primarily as a graphics programming and physics-engine learning project while also serving as the foundation for a lightweight rendering framework (SOGL).


โœจ Features

  • ๐ŸŒŒ Newtonian Gravity Simulation
  • โšซ Massive Black Hole Object
  • ๐Ÿช Stable Planetary Orbits
  • ๐Ÿ”„ Fixed Timestep Physics
  • ๐ŸŽฏ Euler Integration
  • ๐Ÿš€ Modern OpenGL Rendering
  • ๐ŸŽจ GLSL Shader Pipeline
  • ๐Ÿงฉ Modular Engine Architecture
  • ๐Ÿ“ฆ Custom SOGL Rendering Framework
  • โšก Real-time Simulation
  • ๐Ÿ”ต Procedurally Generated Circle Meshes
  • ๐Ÿ–ฅ Cross-platform build using CMake

๐Ÿง  Physics

The simulation uses Newton's Universal Law of Gravitation.

Gravitational Force

[ F = G\frac{m_1m_2}{r^2} ]

Acceleration

[ a = \frac{F}{m} ]

Velocity Update

[ v = v + a\Delta t ]

Position Update

[ x = x + v\Delta t ]

The physics engine runs using a fixed timestep to ensure deterministic and stable orbital motion independent of rendering frame rate.


๐Ÿ— Project Structure

BlackHoleSimulation
โ”‚
โ”œโ”€โ”€ assets/
โ”‚   โ”œโ”€โ”€ models/
โ”‚   โ”œโ”€โ”€ shaders/
โ”‚   โ””โ”€โ”€ textures/
โ”‚
โ”œโ”€โ”€ docs/
โ”‚   โ”œโ”€โ”€ demo.gif
โ”‚   โ”œโ”€โ”€ demo.mp4
โ”‚
โ”œโ”€โ”€ libs/
โ”‚   โ”œโ”€โ”€ glad/
โ”‚   โ”œโ”€โ”€ glfw/
โ”‚   โ””โ”€โ”€ glm/
โ”‚
โ”œโ”€โ”€ SOGL/
โ”‚   โ”œโ”€โ”€ graphic/
โ”‚   โ”œโ”€โ”€ shaders/
โ”‚   โ””โ”€โ”€ window/
โ”‚
โ”œโ”€โ”€ src/
โ”‚   โ”œโ”€โ”€ core/
โ”‚   โ”œโ”€โ”€ rendering/
โ”‚   โ”œโ”€โ”€ simulation/
โ”‚   โ””โ”€โ”€ main.cpp
โ”‚
โ”œโ”€โ”€ CMakeLists.txt
โ””โ”€โ”€ README.md

๐Ÿ›  Technologies Used

Technology Purpose
C++20 Programming Language
OpenGL 4.6 Graphics API
GLFW Window & Input
GLAD OpenGL Loader
GLM Mathematics
GLSL Shader Programming
CMake Build System

โš™ Requirements

  • C++20 compatible compiler
  • CMake 3.20+
  • OpenGL 4.6 capable GPU
  • Git

Windows

  • MinGW-w64 or
  • Visual Studio 2022

๐Ÿš€ Getting Started

1. Clone the Repository

git clone https://github.com/KrishMaheshwariDev/Black-Hole-Simulation

cd Black-Hole-Simulation

2. Configure Project

cmake -B build

3. Build

cmake --build build

4. Run

Windows

./build/BlackHoleSim.exe

or

cd build

BlackHoleSim.exe

๐ŸŽฎ Controls

Key Action
ESC Exit Simulation
NumPad - Zoom out
NumPad + Zoom in

๐Ÿงฉ SOGL Framework

This project also includes SOGL, a lightweight OpenGL rendering framework created during development.

It provides abstractions over:

  • Window Creation
  • Vertex Arrays
  • Vertex Buffers
  • Mesh Rendering
  • Shader Management
  • Renderer Utilities

SOGL is intentionally lightweight and educational, designed for graphics experiments rather than production use.


๐Ÿ“š What I Learned

This project provided hands-on experience with:

  • Modern OpenGL
  • Graphics Pipeline
  • GLSL Programming
  • Mesh Generation
  • Orbital Mechanics
  • Newtonian Gravity
  • Numerical Integration
  • Fixed Timestep Game Loops
  • CMake Project Organization
  • Engine Architecture

๐Ÿšง Future Improvements

  • Multiple Black Holes
  • N-Body Simulation
  • Camera Controls
  • Zoom & Pan
  • ImGui Controls
  • Collision Detection
  • Accretion Disk
  • Particle Effects
  • Relativistic Physics
  • Barnes-Hut Optimization
  • Save / Load Simulation

๐Ÿค Contributing

Contributions, suggestions, and bug reports are welcome.

If you'd like to improve the project:

  1. Fork the repository.
  2. Create a new branch.
  3. Commit your changes.
  4. Open a Pull Request.

๐Ÿ“„ License

This project is licensed under the MIT License.

Feel free to use the code for learning, experimentation, or personal projects.


๐Ÿ‘จโ€๐Ÿ’ป Author

Krish Maheshwari

B.Tech Computer Science (Data Science)

GitHub:

https://github.com/KrishMaheshwariDev

LinkedIn:

https://www.linkedin.com/in/krish-maheshwari

โญ If you found this project interesting, consider giving it a star!

It helps others discover the project and motivates future development.

About

Yep A Black Hole Simulation from scratch... made with OpenGL 3.3

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages