r/Physics • u/Only_Scheme_8594 • 7h ago
I simulated Gravity and Spacetime curvature in openGL
okay so Im a 2nd year cse student and I'm passionate about physics. I initially saw the kavan gravity sim on youtube and wanted to recreate it.I started working on this 2 months back. I had to learn c++,opengl, make this in 2D (freespace and earths gravity) and a little bit of GR. Although low level programming is a pain in the ass, I had alot of fun making this.
working: The engine runs a dual-layer loop: a physics solver updates the 2D positions of the bodies gravitational forces while a vertex generation pass simultaneously warps the underlying 3D wireframe mesh downward along the Y-axis using the gravitational potential. This keeps the planets orbiting smoothly on a flat plane while the grid dynamically bends around them in real-time to simulate relativistic spacetime curvature.
future improvements: I would love to make this more accurate (physics wise) and add textures after i improve my opengl skills.maybe even make the central star a raytracer :)