callback method

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

Implementation

void callback(int a, int b, int c) {
  // Create a triad if it will contain particles from both groups.
  int countA = ((a < groupB._firstIndex) ? 1 : 0) +
      ((b < groupB._firstIndex) ? 1 : 0) +
      ((c < groupB._firstIndex) ? 1 : 0);
  if (countA > 0 && countA < 3) {
    int af = system.flagsBuffer.data[a];
    int bf = system.flagsBuffer.data[b];
    int cf = system.flagsBuffer.data[c];
    if ((af & bf & cf & ParticleSystem.k_triadFlags) != 0) {
      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 = af | bf | cf;
        triad.strength = Math.min(groupA._strength, groupB._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++;
      }
    }
  }
}