I officially started working on Gemini Physics on the 4th of July.
Why then? The mood was right I suppose. But also because I don’t really care about being social and celebrating yet another arbitrary point in time. People love to be told when and how to celebrate and be happy. I like to have more control than that.
I’ve been trying to make this idea work for some time now, with varying success. I finally sat down and worked out an elegant solution with my day off, and these are the results.
I have always had a minimalistic approach to things. I like doing things in the most efficient way possible. With respect to programming, this translates in to code complexity. I’ve spent quite some time learning the ins and outs of writing simple code, and this shows just how far I have come. Aside from the rendering code, all the physics (including math) you see in the video are written in 350 lines of c++.
The idea is that everything you need to do an accurate 2D physics simulation are: particles, edges, and constraints. The rules for these are are quite simple.
Particles: Move based on their velocity and acceleration
Constraints: Keep particles a certain distance from each other
Edges: Prevent particles from passing through them
With those 3 simple primitives and rules, we can construct an extremely robust and accurate simulation.
We can derive lots of cool features using these rules:
- Rigid bodies that we’re all used to seeing
- Soft bodies by changing a single number
- Arbitrary shapes by changing edge configuration
- Self intersecting shapes
- Completely continuous with no tunneling
- Thin, fast moving, heavy objects simulated no problem
It is a very elegant solution that I’m very happy with. It will make a nice base for Gemini Physics (coming soon to a game near you).