callback method

void callback(
  1. int a,
  2. int b,
  3. int c
)
override

Implementation

void callback(int a, int b, int c) {
  final Vector2 pa = system.positionBuffer.data[a];
  final Vector2 pb = system.positionBuffer.data[b];
  final Vector2 pc = system.positionBuffer.data[c];
  final double dabx = pa.x - pb.x;
  final double daby = pa.y - pb.y;
  final double dbcx = pb.x - pc.x;
  final double dbcy = pb.y - pc.y;
  final double dcax = pc.x - pa.x;
  final double dcay = pc.y - pa.y;
  double maxDistanceSquared =
      Settings.maxTriadDistanceSquared * system.squaredDiameter;
  if (dabx * dabx + daby * daby < maxDistanceSquared &&
      dbcx * dbcx + dbcy * dbcy < maxDistanceSquared &&
      dcax * dcax + dcay * dcay < maxDistanceSquared) {
    if (system.triadCount >= system.triadCapacity) {
      int oldCapacity = system.triadCapacity;
      int newCapacity = system.triadCount != 0
          ? 2 * system.triadCount
          : Settings.minParticleBufferCapacity;
      system.triadBuffer = BufferUtils.reallocateBufferWithAlloc(
          system.triadBuffer, oldCapacity, newCapacity, allocPsTriad);
      system.triadCapacity = newCapacity;
    }
    PsTriad triad = system.triadBuffer[system.triadCount];
    triad.indexA = a;
    triad.indexB = b;
    triad.indexC = c;
    triad.flags = system.flagsBuffer.data[a] |
        system.flagsBuffer.data[b] |
        system.flagsBuffer.data[c];
    triad.strength = def.strength;
    final double midPointx = 1.0 / 3.0 * (pa.x + pb.x + pc.x);
    final double midPointy = 1.0 / 3.0 * (pa.y + pb.y + pc.y);
    triad.pa.x = pa.x - midPointx;
    triad.pa.y = pa.y - midPointy;
    triad.pb.x = pb.x - midPointx;
    triad.pb.y = pb.y - midPointy;
    triad.pc.x = pc.x - midPointx;
    triad.pc.y = pc.y - midPointy;
    triad.ka = -(dcax * dabx + dcay * daby);
    triad.kb = -(dabx * dbcx + daby * dbcy);
    triad.kc = -(dbcx * dcax + dbcy * dcay);
    triad.s = pa.cross(pb) + pb.cross(pc) + pc.cross(pa);
    system.triadCount++;
  }
}