Browse Source

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

feature_fragments
vanitasvitae 5 years ago
parent
commit
e645e14844
Signed by: vanitasvitae
GPG Key ID: 62BEE9264BF17311
  1. 10
      app/src/main/java/de/trac/spherical/rendering/SphereSurfaceView.java

10
app/src/main/java/de/trac/spherical/rendering/SphereSurfaceView.java

@ -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

Loading…
Cancel
Save