Developer builds 2D physics engine in C++ and SDL2 using Separating Axis Theorem
A developer has built a 2D physics engine from scratch in C++ and SDL2, deliberately avoiding external physics libraries to deeply understand collision detection. The project uses the Separating Axis Theorem (SAT), which determines whether two convex shapes collide by checking if any axis exists where their projections do not overlap. Key implementation challenges included ensuring collision normals point in the correct direction and applying mass-weighted positional correction so lighter objects move more than heavier ones during collisions. The current engine tests every entity pair each frame, resulting in O(n²) complexity that limits scalability beyond a few dozen shapes. The developer plans to add spatial partitioning, true angular velocity, and eventually integrate the engine into a tile-based game, with source code available on GitHub.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.

Discussion (0)
Log in to join the discussion and vote.
Log in