Search code examples
androidaccelerometerlibgdxtilt

TILT control a 3d obj file on libgdx


I am a new to android development and libgdx...,

supposedly i loaded a 3d .obj file oval (earth) in libgdx and i wanted to control it using accelerometer downward and sideways..,

how could i do that any suggestion,.


Solution

  • If you want to read accelerometer values for axises x, y, z use this

    float accelX = Gdx.input.getAccelerometerX();
    float accelY = Gdx.input.getAccelerometerY();
    float accelZ = Gdx.input.getAccelerometerZ();
    

    If you want to get rotation matrix for rendering from these values, its better to use getRotationMatrix() from SensorManager or its abstraction in Input class

    public void getRotationMatrix (float[] matrix) {
        SensorManager.getRotationMatrix(matrix, null, accelerometerValues, magneticFieldValues);
    }
    

    Take a look at this tutorial