Mylisteofanime nexv
Mylisteofanime nexv

Reputation: 61

How get android device rotation

I want to get the rotation on x, y and z axis enter image description here

I want to get these values

Upvotes: 1

Views: 74

Answers (1)

Maffe
Maffe

Reputation: 430

You can obtain Azimuth, Pitch and Roll in this way:

 private SensorManager sensorManager;
    ...
    // Rotation matrix based on current readings from accelerometer and magnetometer.
    final float[] rotationMatrix = new float[9];
    SensorManager.getRotationMatrix(rotationMatrix, null,
        accelerometerReading, magnetometerReading);

    // Express the updated rotation matrix as three orientation angles.
    final float[] orientationAngles = new float[3];
    SensorManager.getOrientation(rotationMatrix, orientationAngles);

source https://developer.android.com/guide/topics/sensors/sensors_position#java

Upvotes: 1

Related Questions