In this recipe we are going to learn how to connect particles with splines in 3D.
In this recipe we are going to use the particle's code base from the recipe Creating a particle system, from Chapter 5, Building Particle Systems. We are going to use the 3D version.
We will create splines connecting particles.
Include the necessary header file inside
ParticleSystem.h
:#include "cinder/BSpline.h"
Add a new property to the
ParticleSystem
class:ci::BSpline3f spline;
Implement the
computeBSpline
method for theParticleSystem
class:void ParticleSystem::computeBspline(){ std::vector<ci::Vec3f> splinePoints; std::vector<Particle*>::iterator it; for(it = particles.begin(); it != particles.end(); ++it ){ ++it; splinePoints.push_back( ci::Vec3f( (*it)->position ) ); } spline = ci::BSpline3f( splinePoints, 3, false, false ); }
At the end of the
ParticleSystem
update method, invoke the following code:computeBSpline();
Replace...