My final project modeled a simplified version of General Relativity. General Relativity is currently the most accurate theory of gravity. It states that gravity is simply the curvature of space-time caused by mass/energy. I modeled space-time as a 2D grid. This is for easier visualization at the expense of accuracy. My grid uses "extrinsic" curvature, which occurs when a surface bends in an extra dimension. In reality, General Relativity involves "intrinsic" curvature, which is unintuitive but allows for curvature without requiring an extra spatial dimension. Instead, space has intrinsic curvature if distances and parallel lines do not behave as they do in flat Euclidean space. This explanation is a gross simplification, but suitable for visualization.
The spheres are rendered by loading a sphere `.obj` file. The file has a low vertex count (~30), enabling efficient transformation and rendering. Since the sphere was not centered at the origin, preprocessing involved subtracting the centroid from each vertex. This allows uniform scale transformations. Vertex Buffers are used to store each sphere's vertex positions and colors, allowing unique coloring at render time.
The background adds a lot to the realism of the scene. Using GLM, a normalized random 3D vector is generated to create a direction. By placing points along that direction on the far plane, stars are rendered in a static skybox that doesn't parallax with camera motion.
The grid is created by bilinearly interpolating between the four corner vertices:
The number of rows and columns is an input parameter. The program generates equally spaced vertices and creates an index buffer to tell OpenGL how to connect them into a grid.
The grid curvature is modeled after a Flamm paraboloid. The original equation caused no vertical deformation directly under a mass, so I modified it to create a smoother, more realistic dip with exponential falloff.
Original Flamm Paraboloid Equation:
Modified equation with falloff:
To simulate the motion of gravitational bodies, I used a method called Position-Based Dynamics (PBD). Unlike traditional force-based methods, PBD focuses on updating positions directly based on constraints, which makes it more stable for real-time simulations. At each time step, gravitational accelerations are computed between each pair of objects using Newton's law of universal gravitation. The velocities are then updated accordingly and used to predict new positions. These predicted positions are corrected based on collision or distance constraints if necessary. This method ensures visually stable orbits and allows chaotic behavior when multiple objects are introduced close together emulating real gravitational n-body systems.