The attraction, repulsion, and spinning forces
Let's extend our particle's model with three new control parameters—attraction/repulsion, spinning forces inside the emitter (the force
and spinning
parameters), and friction that freezes the motion (the friction
parameter).
Note
An example of this is 03-Particles/03-ParticlesForces
.
The example is based on the 03-Particles/02-ParticlesEmitter
project, implemented in the previous section. Add a declaration of the new parameters to the Params
class declaration:
float force; //Attraction/repulsion force inside emitter float spinning; //Spinning force inside emitter float friction; //Friction, in the range [0, 1]
Then add their initialization in Params::setup()
:
force = 0; spinning = 0; friction = 0;
Finally, implement these parameters by inserting the following code in the Particle::update()
function after the vel.rotate(...)
line:
ofPoint acc; //Acceleration ofPoint delta = pos - param.eCenter; float len = delta.length(); if ( ofInRange...