Advertisement
Guest User

Untitled

a guest
Oct 8th, 2015
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
D 0.47 KB | None | 0 0
  1. // Incrementally fix particle distances.
  2. for(auto i = 0; i < 20; i++) {
  3.     foreach(j, p; taskPool.parallel(particles, numParticles/16)) {
  4.         auto chg = vec2(0, 0);
  5.         foreach(k, q; p.neighbors) {
  6.             auto delta = q.pos - p.pos;
  7.             auto dir = delta.normalize;
  8.             auto mov = delta - dir * separation;
  9.             chg += mov * 0.5;
  10.         }
  11.         changes[j] = chg;
  12.     }
  13.     foreach(j, chg; changes) {
  14.         particles[j].pos += chg;
  15.     }
  16. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement