reportFixture method
Called for each fixture found in the query AABB. Return false to terminate the query.
Implementation
@override
bool reportFixture(Fixture fixture) {
if (fixture.isSensor) {
return true;
}
final shape = fixture.shape;
final body = fixture.body;
final childCount = shape.childCount;
for (var childIndex = 0; childIndex < childCount; childIndex++) {
final aabb = fixture.getAABB(childIndex);
final particleDiameter = system.particleDiameter;
final aabbLowerBoundx = aabb.lowerBound.x - particleDiameter;
final aabbLowerBoundy = aabb.lowerBound.y - particleDiameter;
final aabbUpperBoundx = aabb.upperBound.x + particleDiameter;
final aabbUpperBoundy = aabb.upperBound.y + particleDiameter;
final firstProxy = ParticleSystem.lowerBound(
system.proxyBuffer,
ParticleSystem.computeTag(
system.inverseDiameter * aabbLowerBoundx,
system.inverseDiameter * aabbLowerBoundy,
),
);
final lastProxy = ParticleSystem.upperBound(
system.proxyBuffer,
ParticleSystem.computeTag(
system.inverseDiameter * aabbUpperBoundx,
system.inverseDiameter * aabbUpperBoundy,
),
);
for (var i = firstProxy; i < lastProxy; ++i) {
final particle = system.proxyBuffer[i].particle;
final ap = particle.position;
if (aabbLowerBoundx <= ap.x &&
ap.x <= aabbUpperBoundx &&
aabbLowerBoundy <= ap.y &&
ap.y <= aabbUpperBoundy) {
final av = particle.velocity;
final temp = Transform.mulTransVec2(
body.previousTransform,
ap,
);
input.p1.setFrom(Transform.mulVec2(body.transform, temp));
input.p2.x = ap.x + step.dt * av.x;
input.p2.y = ap.y + step.dt * av.y;
input.maxFraction = 1.0;
if (fixture.raycast(output, input, childIndex)) {
final p = Vector2(
(1 - output.fraction) * input.p1.x +
output.fraction * input.p2.x +
settings.linearSlop * output.normal.x,
(1 - output.fraction) * input.p1.y +
output.fraction * input.p2.y +
settings.linearSlop * output.normal.y,
);
final vx = step.invDt * (p.x - ap.x);
final vy = step.invDt * (p.y - ap.y);
av.x = vx;
av.y = vy;
final particleMass = system.particleMass;
final ax = particleMass * (av.x - vx);
final ay = particleMass * (av.y - vy);
final b = output.normal;
final fdn = ax * b.x + ay * b.y;
final f = Vector2(fdn * b.x, fdn * b.y);
body.applyLinearImpulse(f, point: p);
}
}
}
}
return true;
}