1
0
Fork 0
mirror of https://github.com/vanitasvitae/Spherical synced 2024-11-22 04:12:07 +01:00

Use GAME_ROTATION_VECTOR to get rid of gyro drift when API lvl allows

This commit is contained in:
vanitasvitae 2017-09-14 11:01:14 +02:00
parent e54017584c
commit e645e14844
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311

View file

@ -7,6 +7,7 @@ import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.opengl.GLSurfaceView;
import android.opengl.Matrix;
import android.os.Build;
import android.view.MotionEvent;
/**
@ -29,8 +30,13 @@ public class SphereSurfaceView extends GLSurfaceView implements SensorEventListe
Matrix.setIdentityM(rotationMatrix, 0);
SensorManager manager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE);
Sensor accelerometer = manager.getSensorList(Sensor.TYPE_ROTATION_VECTOR).get(0);
manager.registerListener(this, accelerometer, SensorManager.SENSOR_DELAY_GAME);
Sensor sensor;
if (Build.VERSION.SDK_INT >= 18) {
sensor = manager.getSensorList(Sensor.TYPE_GAME_ROTATION_VECTOR).get(0);
} else {
sensor = manager.getSensorList(Sensor.TYPE_ROTATION_VECTOR).get(0);
}
manager.registerListener(this, sensor, SensorManager.SENSOR_DELAY_GAME);
}
@Override