Example usage for com.badlogic.gdx Application getInput

List of usage examples for com.badlogic.gdx Application getInput

Introduction

In this page you can find the example usage for com.badlogic.gdx Application getInput.

Prototype

public Input getInput();

Source Link

Usage

From source file:com.davidykay.shootout.Renderer.java

License:Apache License

private void renderShip(GL10 gl, Ship ship, Application app) {
    if (ship.isExploding)
        return;/*from  w  w w .  j  a va2s  .c o  m*/

    shipTexture.bind();
    gl.glPushMatrix();
    gl.glTranslatef(ship.position.x, ship.position.y, ship.position.z);
    gl.glRotatef(45 * (-app.getInput().getAccelerometerY() / 5), 0, 0, 1);
    gl.glRotatef(180, 0, 1, 0);
    shipMesh.render(GL10.GL_TRIANGLES);
    gl.glPopMatrix();
}

From source file:com.davidykay.shootout.screens.GameLoop.java

License:Apache License

@Override
public void update(Application app) {
    simulation.update(app.getGraphics().getDeltaTime());

    Input input = app.getInput();
    final boolean ACCELEROMETER_STEERING = false;
    if (ACCELEROMETER_STEERING) {
        if (input.getAccelerometerY() < 0)
            simulation.moveShipLeft(app.getGraphics().getDeltaTime(), Math.abs(input.getAccelerometerY()) / 10);
        else//from www.ja va2  s  . c  o  m
            simulation.moveShipRight(app.getGraphics().getDeltaTime(),
                    Math.abs(input.getAccelerometerY()) / 10);
    }

    if (input.isKeyPressed(Keys.DPAD_LEFT))
        simulation.moveShipLeft(app.getGraphics().getDeltaTime(), 0.5f);
    if (input.isKeyPressed(Keys.DPAD_RIGHT))
        simulation.moveShipRight(app.getGraphics().getDeltaTime(), 0.5f);

    if (input.justTouched()) {
        final float x = input.getX();
        final float y = input.getY();
        Vector3 nearVector = new Vector3(x, y, 0);
        Vector3 farVector = new Vector3(x, y, 1);

        renderer.unproject(nearVector);
        renderer.unproject(farVector);

        /** Vector tracing between the near plane and the far plane **/
        Vector3 inVector = new Vector3(nearVector);

        final Plane gamePlane = new Plane(new Vector3(0, 0, 0), new Vector3(1, 0, 0), new Vector3(0, 0, 1));

        Ray pickRay = renderer.getCamera().getPickRay(x, y);

        Vector3 intersection = new Vector3();
        Vector3 finalVector;

        if (FLAT_MODE) {
            // Flat Mode
            if (Intersector.intersectRayPlane(pickRay, gamePlane, intersection)) {
                finalVector = new Vector3(intersection);
                if (finalVector.equals(nearVector)) {
                    Gdx.app.log(TAG, String.format("Near Vector! finalVector:(%s)", finalVector.toString()));
                } else {
                    Gdx.app.log(TAG, String.format("INTERSECTION! finalVector:(%s)", finalVector.toString()));
                }
            } else {
                Gdx.app.log(TAG, String.format("NO INTERSECTION. nearVector:(%s)", nearVector.toString()));
                finalVector = new Vector3(nearVector);
            }
        } else {
            // 3D Mode

            finalVector = new Vector3(nearVector);

            //for (Alien alien : aliens) {
            //  if (
            //      Intersector.intersectRayPlane(
            //          pickRay,
            //          gamePlane,
            //          intersection
            //          )
            //     ) {

            //  }
            //}
        }

        //simulation.tapShot(nearVector);
        //simulation.tapShot(finalVector);
        simulation.tapRay(pickRay);
    } else {
        // If we haven't been touched, let's look at the orientation. This in an attempt to lower
        // impulse from user's finger.
        float azimuth = input.getAzimuth();
        float pitch = input.getPitch();
        float roll = input.getRoll();

        simulation.updateOrientation(azimuth, pitch, roll);
    }
}

From source file:com.davidykay.shootout.screens.GameOver.java

License:Apache License

@Override
public void update(Application app) {
    isDone = app.getInput().isTouched();
}

From source file:org.illarion.engine.backend.gdx.GdxEngine.java

License:Open Source License

/**
 * Create a new instance of the engine along with the reference to the libGDX application that is used.
 *
 * @param gdxApplication the active libGDX application
 * @param container      the game container that shows the application
 *///w w w.  j a  va  2 s  .  co m
GdxEngine(@Nonnull final Application gdxApplication, @Nonnull final GameContainer container) {
    if (!gdxApplication.getGraphics().isGL20Available()) {
        Sys.alert("Graphic device failure.", "You graphic device does not seem to support the client.");
        System.exit(-1);
    }
    assets = new GdxAssets(gdxApplication, container);
    sounds = new GdxSounds();
    graphics = new GdxGraphics(this, gdxApplication.getGraphics());
    input = new GdxInput(gdxApplication.getInput());
}