In this recipe, we will learn how we can create springs.
Springs are objects that connect two particles and force them to be at a defined rest distance.
In this example, we will create random particles, and whenever the user presses a mouse button, two random particles will be connected by a new spring with a random rest distance.
We will be using the same particle system developed in the previous recipe, Creating a particle system in 2D. Create the Particle
and ParticleSystem
classes described in that recipe and include the ParticleSystem.h
file at the top of the application source file.
We will be creating a Spring
class, so it is necessary to create the following files:
Spring.h
Spring.cpp