Creating a cloth simulation
In this recipe we will learn how to simulate cloth by creating a grid of particles connected by springs.
Getting Ready
In this recipe, we will be using the particle system described in the recipe Creating a particle system in 2D from Chapter 5, Building Particle Systems.
We will also be using the Springs
class created in the recipe Creating springs from Chapter 5, Building Particle Systems.
So, you will need to add the following files to your project:
Particle.h
ParticleSystem.h
Spring.h
Spring.cpp
How to do it…
We will create a grid of particles connected with springs to create a cloth simulation.
Include the particle system file in your project by adding the following code on top of your source file:
#include "ParticleSystem.h"
Add the
using
statements before the application class declaration as shown in the following code:using namespace ci; using namespace ci::app; using namespace std;
Create an instance of a
ParticleSystem
object and member variables to store the top corners...