Gemini Physics Development 1: Continuous Particles

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.

Philosophy aside…


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).

16 thoughts on “Gemini Physics Development 1: Continuous Particles”

    1. Nope. I want to port this to 3D soon actually. Basically the only difference is that instead of colliding particles with edges, you need to collide edges with edges and particles with faces.

  1. Wow… I’m pretty excited by this. Can I ask how you’re *resolving* collisions?

    This seems like the tricky part… are you sweep-testing in-between each solver iteration? Anyway I’m really glad to see that this sort of “everything is cloth” type of simulation is feasible :)

    1. Thanks! I’ll probably write a full post on this soon, but briefly…

      For each particle, I sweep test it with the edges and find the earliest time of impact. I solve collisions by simply moving their positions to the right place. Verlet integration handles the rest. And yes, I detect and solve collisions in between each iteration. The trick is not not move on to the next iteration until all particles are in a collision free state.

      PS. I love N+, you guys did a great job on it!

      1. Thanks! :)

        I’ve got more questions, but I guess I could wait till the next blog post. Ah, I can’t wait… too exciting!!

        I’m surprised you don’t get lock-ups with the “don’t proceed until all constraints are solved” rule.

        I’m really impressed, but also really curious…

        When you find the earliest time of collision, is there any global ordering? i.e if particles ABC collide at time t=0.1, and particles CDE collide at time t=0.2, how is C moved?

        Feel free to tell me to wait until the next blog post :)

        This sort of simple but robust system has been a goal of mine for a while, I’m really glad that it’s demonstrable/possible, kudos!

        1. Good questions!

          I will answer those and some others I got in more detail in the next post :)

          It was definitely tricky to get this right, and I almost gave up on it after trying on like 5 different occasions…

          The first time it worked I think I literally screamed haha

  2. Just stumbled upon this by chance. This is really impressive! I’m really looking forward for more. Verlet friction can be tricky…

Leave a Reply