I'm playing arround with particle effects and while I'm not managed to code the finder function to connect emitter nodes to particle nodes I managed to code some affectors as lambda functions, in case somebody wondered about how this can be done.
I'm on the other hand am interested in how can the finder command be done?
Simple fall from up to down:
function<void(Particle&, Time)> Fallaffector = [&](Particle& particle, Time dt) { particle.position += Vector2f(0.f,50.f)*dt.asSeconds();};
Can look comparable to a waterfall cascade in case start position of particle is randomized as (start position + std::rand()%factor):
function<void(Particle&, Time)> Fallaffector = [&](Particle& particle, Time dt) {float posx = (particle.position.x - 400.f) / 2; if (particle.position.y < 350) { particle.position += Vector2f(-posx / 15 + static_cast<int>(particle.position.x) % 30, std::rand() % 50 + std::rand() % 75)*dt.asSeconds(); } else { particle.position += Vector2f(std::rand()%140, std::rand()%50)*dt.asSeconds(); }};
Circular rotation around 300 300:
function<void(Particle&, Time)> Rotator = [&](Particle& particle, Time dt) {Vector2f pos = particle.position; float s = sin(55); float c = cos(55); pos -= Vector2f(300 , 300); float xnew = pos.x*c - pos.y*s; float ynew = pos.x * s + pos.y * c; xnew += 300; ynew += 300; particle.position = Vector2f(xnew, ynew); };
Lines become a rotating cloud
function<void(Particle&, Time)> Rotator = [&](Particle& particle, Time dt) {Vector2f pos = particle.position; float s = sin(55); float c = cos(55); pos -= Vector2f(300 + std::rand()%10, 300); float xnew = pos.x*c - pos.y*s; float ynew = pos.x * s + pos.y * c; xnew += 400; ynew += 300; particle.position = Vector2f(xnew, ynew); };