Real-Time Cloth Simulation

[implementation | videos | executable demo ]

Implementation and Sample Code

Cloth Simulation

The cloth simulation algorithm I implemented is based on the paper "Advanced Character Physics" by Thomas Jakobsen in the proceedings of the Game Developer's Conference, San Jose, 2001. The method represents a piece of cloth as an array of particles linked by distance constraints. The particles of the cloth are updated in two different ways: The cloth particle system is maintained using an array of packed floats to optimize speed and memory usage.

Source Code: SimCloth.h, SimCloth.cpp


The projectiles in the scene are simply spheres that can be launched at a particular speed and direction, and then fly under the force of gravity until they collide. Projectiles are also integrated using the Verlet integration scheme. Iterative relaxation is used to handle collisions between spheres, with the ground, and with cloth. In the relaxation process the cloth is allowed to effect the spheres, enabling the spheres to display realistic response to collision with the cloth.

Source Code: SimSphere.h, SimSphere.cpp, ProjectileLaunchParams.h

Scene Manager

For this demo I implemented a very simple scene manager, that maintains a list of all objects in the scene for simulation and rendering, and culls those objects that are not active. The scene manager is initialized in a main program, which renders the objects in the scene, along with the cannon model, and allows simple user interaction.

Source Code: SimScene.h, SimScene.cpp, main.cpp



Hanging Cloth with Collisions

This scene shows 2 pieces of cloth, 900 particles each,  hanging in the air. The cloth sheets react when they are impacted by  projectiles launched from the cannon. The cloth also exerts force back onto the projectiles, causing them to lose velocity and drop to the ground.

The simulation together with  rendering runs at approximately 41 frames per second.

Videos: <MPEG 2.0MB>

Pinned Cloth with Collisions and Object Support

This scene more clearly illustrates the ability of the cloth to exert forces on objects in the scene. The cloth net, with 900 particles, reacts when impacted by the projectiles. The cloth exerts a force back on the particles, holding them suspended in the net.

The simulation together with  rendering runs at approximately 42 frames per second.

Videos: <MPEG 4.1MB>


Hanging Cloth and Cannon