I'm not insane - gyroscope swaps axes when the screen orientation is inverted when holding the phone upside down.

This commit is contained in:
pelya
2014-06-29 02:59:58 +03:00
parent 283b1d6b3d
commit 4cd55d4d07
3 changed files with 46 additions and 16 deletions

View File

@@ -90,25 +90,30 @@ class AccelerometerReader implements SensorEventListener
static class GyroscopeListener implements SensorEventListener
{
public float x1 = 0.0f, x2 = 0.0f, xc = 0.0f, y1 = 0.0f, y2 = 0.0f, yc = 0.0f, z1 = 0.0f, z2 = 0.0f, zc = 0.0f;
public boolean invertedOrientation = false;
public GyroscopeListener()
{
}
public void onSensorChanged(SensorEvent event)
{
// TODO: vertical orientation
if( Globals.HorizontalOrientation )
if( event.values[0] < x1 || event.values[0] > x2 ||
event.values[1] < y1 || event.values[1] > y2 ||
event.values[2] < z1 || event.values[2] > z2 )
{
if( event.values[0] < x1 || event.values[0] > x2 ||
event.values[1] < y1 || event.values[1] > y2 ||
event.values[2] < z1 || event.values[2] > z2 )
nativeGyroscope(event.values[0] - xc, event.values[1] - yc, event.values[2] - zc);
}
else
{
if( event.values[0] < x1 || event.values[0] > x2 ||
event.values[1] < y1 || event.values[1] > y2 ||
event.values[2] < z1 || event.values[2] > z2 )
nativeGyroscope(-(event.values[1] - yc), event.values[0] - xc, event.values[2] - zc);
if( Globals.HorizontalOrientation )
{
if( invertedOrientation )
nativeGyroscope(-(event.values[0] - xc), -(event.values[1] - yc), event.values[2] - zc);
else
nativeGyroscope(event.values[0] - xc, event.values[1] - yc, event.values[2] - zc);
}
else
{
if( invertedOrientation )
nativeGyroscope(event.values[1] - yc, -(event.values[0] - xc), event.values[2] - zc);
else
nativeGyroscope(-(event.values[1] - yc), event.values[0] - xc, event.values[2] - zc);
}
}
}
public void onAccuracyChanged(Sensor s, int a)