mirror of
https://github.com/vanitasvitae/Spherical
synced 2024-11-22 12:22:08 +01:00
Use GAME_ROTATION_VECTOR to get rid of gyro drift when API lvl allows
This commit is contained in:
parent
e54017584c
commit
e645e14844
1 changed files with 8 additions and 2 deletions
|
@ -7,6 +7,7 @@ import android.hardware.SensorEventListener;
|
||||||
import android.hardware.SensorManager;
|
import android.hardware.SensorManager;
|
||||||
import android.opengl.GLSurfaceView;
|
import android.opengl.GLSurfaceView;
|
||||||
import android.opengl.Matrix;
|
import android.opengl.Matrix;
|
||||||
|
import android.os.Build;
|
||||||
import android.view.MotionEvent;
|
import android.view.MotionEvent;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -29,8 +30,13 @@ public class SphereSurfaceView extends GLSurfaceView implements SensorEventListe
|
||||||
Matrix.setIdentityM(rotationMatrix, 0);
|
Matrix.setIdentityM(rotationMatrix, 0);
|
||||||
|
|
||||||
SensorManager manager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE);
|
SensorManager manager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE);
|
||||||
Sensor accelerometer = manager.getSensorList(Sensor.TYPE_ROTATION_VECTOR).get(0);
|
Sensor sensor;
|
||||||
manager.registerListener(this, accelerometer, SensorManager.SENSOR_DELAY_GAME);
|
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
|
@Override
|
||||||
|
|
Loading…
Reference in a new issue