inline void SchoolFish::applySeparation(Vector &accumulator) { FlockEntity *e = getNearestFlockEntity(); if (e) { const float dist = getNearestFlockEntityDist(); if (dist < separationDistance) { float ratio = dist / separationDistance; if (ratio < minUrgency) ratio = minUrgency; else if (ratio > maxUrgency) ratio = maxUrgency; ratio *= strengthSeparation; Vector change(e->position - this->position); if (!change.isZero()) { change.setLength2D(-ratio); accumulator += change; } } // Are we too far from nearest flockmate? Then Move Closer /* else if (dist > separationDistance) change |= ratio; */ } }
inline void SchoolFish::applySeparation(Vector &accumulator) { FlockEntity *e = getNearestFlockEntity(); if (e) { Vector change; float ratio; change = e->position - this->position; float nearestFlockEntityDist = change.getLength2D(); ratio = nearestFlockEntityDist / separationDistance; if (ratio < minUrgency) ratio = minUrgency; else if (ratio > maxUrgency) ratio = maxUrgency; ratio *= strengthSeparation; if (nearestFlockEntityDist < separationDistance) { if (!change.isZero()) change.setLength2D(-ratio); //Change.SetMagnitudeOfVector(-Ratio) // Are we too far from nearest flockmate? Then Move Closer /* else if (nearestFlockEntityDist > separationDistance) change |= ratio; */ } else change = Vector(0,0,0); // Add Change to Accumulator /* if Flock <> nil then Flock.BoidApplyRule( Self, fbSeparation, Accumulator, Change ); */ accumulator += change; } }