Particle System – Spring Physics

I saw a video online recently of several cubes flying into the scene and stacking up to form a larger cube. A pretty simple yet powerful effect. The effect was achieved using Particle Flow, so the movement of the particles are entirely animated. Check it out below:

After seeing this, I immediately wanted to try it, but with a more general solution. So, off I went to write a physics system for my particle engine. Now, there are a lot of challenges in getting a particle rocketing through 3D space to land in exactly the right position with physics alone. There are a few options. With physics, we can exponentially increase a force on the particle in the direction of the destination with relation to the distance from the destination. Another possibility is merging a pure physics system with a pure spline animation to allow a random initial velocity, but a guaranteed stopping point.

My first step however, is developing some way to attract the particles to their destination. I decided to start with a spring system. Although the system will exert forces on the particles to aim the particles at the destination, it is very unlikely that they will pass directly through a predetermined point, and instead orbit around the destination.

For those interested, here’s the nice little gem used to compute the spring force. I modified this algorithm from a cloth simulator used in the book “Physics for Game Developers”.

D3DXVECTOR3 Collector::GetForce(Particle particle)
{
    D3DXVECTOR3 forceVector = GetVector(particle);    // From particle to destination
    float length = D3DXVec3Length(&forceVector);
    float k = 1;    // tensile constant
    float d = 1;    // damping constant
    float dot = D3DXVec3Dot(&particle.m_velocity, &forceVector);
    D3DXVECTOR3 force = (k * length + d * (dot / length)) * (forceVector / length);
    return force;
}

Leave a Comment

Tags: , ,

January 16, 2011 Graphics, Physics