I am currently designing my own physics engine in C++ to familiarise myself with how video game engines work and with low-level optimisation. I'm sharing in this page my progress on the physics engine.
GitHub repo: https://github.com/CASTEL-Florian/Physics-Engine/tree/main
For this project, I decided to use the C++ language with OpenGL and GLAD. I followed a tutorial online to learn how to render objects, lighting and use instancing.
The first thing I wanted to try was to generate a terrain using Perlin noise and have a sphere collide with it. A collision is detected if the bottom of the sphere is lower than the height of the terrain. When a collision is detected, the sphere is moved up and its speed is reflected relative to the terrain normal.
In order to have an efficient implementation of the collision detection phase, I implemented a grid-based spatial partitioning: the space is divided into a grid and the program checks for collisions between objects within the same or neighboring cells. I'm also using multithreading and GPU instancing to enhance the performance when dealing with a very high number of spheres.
In the following video, the scene contains 5000 spheres.