Creating a particle system in 2D
In this recipe, we are going to learn how we can build a basic particle system in two dimensions using the Verlet algorithm.
Getting ready
We will need to create two classes, a Particle
class representing a single particle, and a ParticleSystem
class to manage our particles.
Using your IDE of choice, create the following files:
Particle.h
Particle.cpp
ParticleSystem.h
ParticleSystem.cpp
How to do it…
We will learn how we can create a basic particle system. Perform the following steps to do so:
First, let's declare our
Particle
class in theParticle.h
file and include the necessary Cinder files:#pragma once #include "cinder/gl/gl.h" #include "cinder/Vector.h" class Particle{ };
Let's add, to the class declaration, the necessary member variables –
ci::Vec2f
to store the position, previous position, and applied forces; andfloat
to store particle radius, mass, and drag.ci::Vec2f position, prevPosition; ci::Vec2f forces; float radius; float mass; float drag;
The last thing...