Search in sources :

Example 1 with QueryCallback

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))));
}
Also used : Vec2(spacegraph.space2d.phys.common.Vec2) Fixture(spacegraph.space2d.phys.dynamics.Fixture) Body(spacegraph.space2d.phys.dynamics.Body) QueryCallback(spacegraph.space2d.phys.callbacks.QueryCallback) AABB(spacegraph.space2d.phys.collision.AABB)

Aggregations

QueryCallback (spacegraph.space2d.phys.callbacks.QueryCallback)1 AABB (spacegraph.space2d.phys.collision.AABB)1 Vec2 (spacegraph.space2d.phys.common.Vec2)1 Body (spacegraph.space2d.phys.dynamics.Body)1 Fixture (spacegraph.space2d.phys.dynamics.Fixture)1