2D Physics Engine
November 2009 - February 2013
In the process of writing my thesis, I wrote a toy physics engine in C++ with OpenGL and SDL 1.2. The constraint-based impulse physics solver I used closely mirrors that of Box2D; however, the algorithm for generating collision contacts is novel. I also added collision detection for particles and soft-body Verlet dynamics; in the process, I produced a few interesting demo programs.
Demo 1: "Pong" (pairwise collision detection test)
[ ys_pong.zip, 773.2 KB, Windows 32-bit ]
The classic arcade game implemented in a physics engine. This version of Pong has a twist: the square ball spins and the paddles can rotate!
↓- move paddle
Z- freeze paddle movement
X- freeze paddle rotation
V- rotate paddle
B- (hold) molasses mode
N- (hold) turbo mode
Demo 2: "Emitters" (particle collision test)
[ ys_particle.zip, 829.36 KB, Windows 32-bit ]
This demo shows off some particle emitters: a "burst" style emitter, two colored flames, a rain emitter, and finally, a rain-of-fire emitter. All particles collide with the map (modeled after a SMB1 warp zone).
Emitters may use other emitters as their particle type. Out of the five emitters, only the "armageddon" emitter does this: the top-level emitter has settings similar to the rain emitter, but the particles created are fire emitters themselves.
→- move emitter
Z- toggle selected emitter
X- enable selected emitter
C- select next emitter
V- select previous emitter
J- zoom camera out
K- zoom camera in
Demo 3: "Stacking" (constraint solver test)
Stacking of rigid bodies is achieved by cataloging contacts and friction as constraints, then solving as shown in Iterative Dynamics with Temporal Coherence (Catto 2005). Contacts are visualized as green dots; the solved forces on them appear as magenta lines.
Home- reset current demo
Esc- next demo
F1- pause simulation
PgDn- step paused simulation
Mouse scroll ↑- zoom camera out
Mouse scroll ↑- zoom camera in
D- move camera
Mouse L- grab rigid body