use of spacegraph.space2d.phys.callbacks.QueryCallback in project narchy by automenta.
the class Explosion method explodeBlastRadius.
public static void explodeBlastRadius(World world, Vec2 center, float blastRadius, float blastPower) {
final float m_blastRadiusSq = blastRadius * blastRadius;
// find all bodies with fixtures in blast radius AABB
QueryCallback queryCallback = new QueryCallback() {
@Override
public boolean reportFixture(Fixture fixture) {
Body body = fixture.getBody();
Vec2 bodyCom = body.getWorldCenter();
// ignore bodies outside the blast range
if ((bodyCom.sub(center)).lengthSquared() < m_blastRadiusSq) {
applyBlastImpulse(body, center, bodyCom, blastPower);
return true;
}
return false;
}
};
world.queryAABB(queryCallback, new AABB(center.sub(new Vec2(blastRadius, blastRadius)), center.add(new Vec2(blastRadius, blastRadius))));
}
Aggregations