Java 类com.badlogic.gdx.physics.box2d.QueryCallback 实例源码

项目:JavityEngine    文件:JPhysic.java   
public static List<RaycastHit> raycastPoint(final Vector2 pointToTest) {
    final List<RaycastHit> hits = new ArrayList<RaycastHit>();
    Vector2 end = pointToTest.add(new Vector2(1, 1));
    //TODO move to static single object
    physic.physicWorld.QueryAABB(new QueryCallback() {
        @Override
        public boolean reportFixture(Fixture fixture) {
            if (fixture.testPoint(pointToTest)) {
                hits.add(new RaycastHit(fixture, pointToTest));
            }
            return true;
        }
    }, pointToTest.x < end.x ? pointToTest.x : end.x, pointToTest.y < end.y ? pointToTest.y : end.y,
            pointToTest.x > end.x ? pointToTest.x : end.x, pointToTest.y > end.y ? pointToTest.y : end.y);

    return hits;
}
项目:M-M    文件:Box2DService.java   
/** Changes to second stage of the game. */
public void setSoloMode() {
    soloMode = true;
    for (final Minion minion : minions) {
        minion.setDestroyed(true);
    }
    // Spawning additional obstacles:
    final boolean[] isTaken = new boolean[1];
    final QueryCallback callback = new QueryCallback() {
        @Override
        public boolean reportFixture(final Fixture fixture) {
            isTaken[0] = true;
            return false;
        }
    };
    final float width = Box2DUtil.WIDTH * 2f / 5f - Block.HALF_SIZE;
    final float height = Box2DUtil.HEIGHT * 2f / 5f - Block.HALF_SIZE;
    for (int index = 0; index < 15; index++) {
        final float x = MathUtils.random(-width, width);
        final float y = MathUtils.random(-height, height);
        isTaken[0] = false;
        world.QueryAABB(callback, x - Block.HALF_SIZE, y - Block.HALF_SIZE, x + Block.HALF_SIZE,
                y + Block.HALF_SIZE);
        if (!isTaken[0]) {
            gameController.addBlock(spawnBlock(x, y));
        }
    }
}
项目:Codelabs    文件:DragAndDropSample.java   
@Override
public boolean touchDown(int screenX, int screenY, int pointer, int button) {
    /*
     * Define a new QueryCallback. This callback will be used in
     * world.QueryAABB method.
     */
    QueryCallback queryCallback = new QueryCallback() {

        @Override
        public boolean reportFixture(Fixture fixture) {
            boolean testResult;

            /*
             * If the hit point is inside the fixture of the body, create a
             * new MouseJoint.
             */
            if (testResult = fixture.testPoint(touchPosition.x,
                    touchPosition.y)) {
                mouseJointDef.bodyB = fixture.getBody();
                mouseJointDef.target.set(touchPosition.x, touchPosition.y);
                mouseJoint = (MouseJoint) world.createJoint(mouseJointDef);
            }

            return testResult;
        }
    };

    /* Translate camera point to world point */
    camera.unproject(touchPosition.set(screenX, screenY, 0));

    /*
     * Query the world for all fixtures that potentially overlap the touched
     * point.
     */
    world.QueryAABB(queryCallback, touchPosition.x, touchPosition.y,
            touchPosition.x, touchPosition.y);

    return true;
}
项目:tilt-game-android    文件:PhysicsWorld.java   
public void QueryAABB(final QueryCallback pCallback, final float pLowerX, final float pLowerY, final float pUpperX, final float pUpperY) {
    this.mWorld.QueryAABB(pCallback, pLowerX, pLowerY, pUpperX, pUpperY);
}
项目:geometri-destroyer    文件:GeometriDestroyer.java   
@Override
public boolean touchDown(int screenX, int screenY, int pointer, int button) {
    if (!gameRunning) {
        return false;
    }
    float x = ((float)screenX) / Gdx.graphics.getWidth() * Constants.WIDTH;
    float y = Constants.HEIGHT - ((float)screenY) / Gdx.graphics.getHeight() * Constants.HEIGHT;
    world.QueryAABB(new QueryCallback() {
        @Override
        public boolean reportFixture(Fixture fixture) {
            if (fixture.getBody().getUserData() instanceof Entity && ((Entity)fixture.getBody().getUserData()).isDestroyable()) {
                if (gameRunning) {
                    world.destroyBody(fixture.getBody());
                    if (boxesLeft > 0) {
                        --boxesLeft;
                    }
                    if (boxesLeft == 0) {
                        victoryChecker = new VictoryChecker() {
                            @Override
                            public void check() {
                                boolean sleeping = true;
                                Iterator<Body> i = world.getBodies();
                                while (i.hasNext()) {
                                    Body body = i.next();
                                    if (body.getUserData() instanceof Entity) {
                                        if (body.isAwake()) {
                                            sleeping = false;
                                        }
                                    }
                                }
                                if (sleeping) {
                                    victory();
                                }
                            }
                        };
                    }
                }
            }
            return false;
        }
    }, x, y, x, y);
    return false;
}
项目:liblol    文件:LolScene.java   
/**
 * Construct a new scene
 *
 * @param media  All image and sound assets for the game
 * @param config The game-wide configuration
 */
LolScene(Media media, Config config) {
    mMedia = media;
    mConfig = config;
    // compute the width and height, in meters
    float w = config.mWidth / config.mPixelMeterRatio;
    float h = config.mHeight / config.mPixelMeterRatio;
    // set up the game camera, with (0, 0) in the bottom left
    mCamera = new OrthographicCamera(w, h);
    mCamera.position.set(w / 2, h / 2, 0);
    mCamera.zoom = 1;

    // set up the event lists
    mOneTimeEvents = new ArrayList<>();
    mRepeatEvents = new ArrayList<>();

    // set default camera bounds
    mCamBound = new Vector2();
    mCamBound.set(w, h);

    // create a world with no default gravitational forces
    mWorld = new World(new Vector2(0, 0), true);

    // set up the containers for holding anything we can render
    mRenderables = new ArrayList<>(5);
    for (int i = 0; i < 5; ++i) {
        mRenderables.add(new ArrayList<Renderable>());
    }

    // set up the callback for finding out who in the physics world was touched
    mTouchVec = new Vector3();
    mTouchCallback = new QueryCallback() {
        @Override
        public boolean reportFixture(Fixture fixture) {
            // if the hit point is inside the fixture of the body we report
            // it
            if (fixture.testPoint(mTouchVec.x, mTouchVec.y)) {
                BaseActor hs = (BaseActor) fixture.getBody().getUserData();
                if (hs.mEnabled) {
                    mHitActor = hs;
                    return false;
                }
            }
            return true;
        }
    };

    // prepare other collections
    mGlyphLayout = new GlyphLayout();
    mTapHandlers = new ArrayList<>();
}
项目:NationSoccer    文件:PhysicsWorld.java   
public void QueryAABB(final QueryCallback pCallback, final float pLowerX, final float pLowerY, final float pUpperX, final float pUpperY) {
    this.mWorld.QueryAABB(pCallback, pLowerX, pLowerY, pUpperX, pUpperY);
}