diff options
author | Martho42 <marshob@gmail.com> | 2015-04-04 17:03:56 -0700 |
---|---|---|
committer | Martho42 <marshob@gmail.com> | 2015-04-04 17:03:56 -0700 |
commit | 7a2698bb44021b7b51a85f2dee3c722f33924ead (patch) | |
tree | 88651ae7affc68478a6f52ce38767f9e1dc52d39 /platform/android/java | |
parent | 5d99e15e43d5a446b35d48e8a3b08a478f1998a9 (diff) |
Fixes the accelerometer
Resolves the issue of the accelerometer behaving differently across devices with landscape as default and devices with portrait as default.
Diffstat (limited to 'platform/android/java')
-rw-r--r-- | platform/android/java/src/com/android/godot/Godot.java | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/platform/android/java/src/com/android/godot/Godot.java b/platform/android/java/src/com/android/godot/Godot.java index 1fd37c98cd..2abb4cec53 100644 --- a/platform/android/java/src/com/android/godot/Godot.java +++ b/platform/android/java/src/com/android/godot/Godot.java @@ -571,9 +571,24 @@ public class Godot extends Activity implements SensorEventListener, IDownloaderC } @Override public void onSensorChanged(SensorEvent event) { - float x = event.values[0]; - float y = event.values[1]; - float z = event.values[2]; + Display display = ((WindowManager) getSystemService(WINDOW_SERVICE)).getDefaultDisplay(); + int displayRotation = display.getRotation(); + + float[] adjustedValues = new float[3]; + final int axisSwap[][] = { + { 1, -1, 0, 1 }, // ROTATION_0 + {-1, -1, 1, 0 }, // ROTATION_90 + {-1, 1, 0, 1 }, // ROTATION_180 + { 1, 1, 1, 0 } }; // ROTATION_270 + + final int[] as = axisSwap[displayRotation]; + adjustedValues[0] = (float)as[0] * event.values[ as[2] ]; + adjustedValues[1] = (float)as[1] * event.values[ as[3] ]; + adjustedValues[2] = event.values[2]; + + float x = adjustedValues[0]; + float y = adjustedValues[1]; + float z = adjustedValues[2]; GodotLib.accelerometer(x,y,z); } |