KAgent separate
From KokkugiaWiki
arguments:
pop (ArrayList): an arraylist of the population of agents which it will separate from.
returns:
a vector which is the sum of the separation required from the nearest neighbors with an inverse weighting based on distance.
// separation
kVec separate (ArrayList pop) {
kVec sum = new kVec(0,0,0);
int count = 0;
for (int i = 0 ; i < pop.size(); i++) {
kAgent other = (kAgent) pop.get(i);
float dist = pos.distance(other.pos);
if ((dist > 0) && (dist < rangeOfVision/1.5)) {
kVec diff = kVec.clone(pos);
diff.minus(other.pos);
diff.normalize();
diff.scale(1/dist);
sum.plus(diff);
count++;
}
}
if (count > 0) {
sum.scale(1/(float)count);
}
sumSep = kVec.clone(sum);
return sum;
}
