2D C++ Physics Engine
Created on:
Team Size: 1
Time Frame: 1 Month
Tool 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 projet to a web version with Emscripten. You can left click to place circles and right click to place squares.
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 confortable.
- 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 developper at Electronic Arts for 4 years. They accumulated a total of 260’000 views. In these, The Cherno looks at my code and makes comments on the various things that could be improved.