2D C++ Physics Engine
Created on: July 2022
Team size: 1
Time frame: 1 Month
Tools used: C++
This is a 2D physics engine made in C++ with no libraries. It was made during the physics engine module of the SAE Institute.
It has :
- Circle colliders
- AABB colliders
- Broad phase collision detection with a grid
At first the demo scene was made in SFML. But recently, I ported it to raylib so that I could compile the project to a web version with Emscripten. You can left click to place circles and right click to place squares.
You can read the project's documentation on Read the Docs and see the source on GitHub.
Downloading...
What I Learned
- The math behind a physics engine: Even though I already studied Newton's equations, applying them in code is a different challenge.
- Creating a CMake library: Before this project, using CMake was quite complicated for me and in this project I read a lot of tutorials to be more comfortable.
- What to think about when designing an API: Since my physics engine is a library, I had to think about what the user code would look like.
- Optimization with data structures: To optimize collision detection, we studied multiple data structures (KD-Tree, Quadtree, Grids). I choose to implement a grid.
Code Reviews
The project was also featured in 3 code review videos made by The Cherno, who was an engine programmer at Electronic Arts for 4 years. They accumulated over 318'000 views as I'm writing this. In these, The Cherno looks at my code and makes comments on the various things that could be improved.