summaryrefslogtreecommitdiff
path: root/src/android
diff options
context:
space:
mode:
authorGravatar german772023-05-09 23:44:00 -0600
committerGravatar bunnei2023-06-03 00:06:01 -0700
commitaa957df0dcd01afeac41afe7a7246f57b61acedc (patch)
treecc7bcc8a71f9b0b1d231f48f29054a00ea8f15cb /src/android
parentandroid: vulkan_device: Skip BGR565 emulation on S8gen2. (diff)
downloadyuzu-aa957df0dcd01afeac41afe7a7246f57b61acedc.tar.gz
yuzu-aa957df0dcd01afeac41afe7a7246f57b61acedc.tar.xz
yuzu-aa957df0dcd01afeac41afe7a7246f57b61acedc.zip
android: Invert rotation to match phone orientation
Diffstat (limited to 'src/android')
-rw-r--r--src/android/app/src/main/java/org/yuzu/yuzu_emu/activities/EmulationActivity.kt32
1 files changed, 27 insertions, 5 deletions
diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/activities/EmulationActivity.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/activities/EmulationActivity.kt
index 1301583a0..4a0f88f52 100644
--- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/activities/EmulationActivity.kt
+++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/activities/EmulationActivity.kt
@@ -13,9 +13,12 @@ import android.hardware.SensorEvent
13import android.hardware.SensorEventListener 13import android.hardware.SensorEventListener
14import android.hardware.SensorManager 14import android.hardware.SensorManager
15import android.os.Bundle 15import android.os.Bundle
16import android.view.* 16import android.view.InputDevice
17import android.view.KeyEvent 17import android.view.KeyEvent
18import android.view.MotionEvent 18import android.view.MotionEvent
19import android.view.Surface
20import android.view.View
21import android.view.WindowManager
19import android.view.inputmethod.InputMethodManager 22import android.view.inputmethod.InputMethodManager
20import androidx.appcompat.app.AppCompatActivity 23import androidx.appcompat.app.AppCompatActivity
21import androidx.preference.PreferenceManager 24import androidx.preference.PreferenceManager
@@ -49,6 +52,7 @@ open class EmulationActivity : AppCompatActivity(), SensorEventListener {
49 private val gyro = FloatArray(3) 52 private val gyro = FloatArray(3)
50 private val accel = FloatArray(3) 53 private val accel = FloatArray(3)
51 private var motionTimestamp: Long = 0 54 private var motionTimestamp: Long = 0
55 private var flipMotionOrientation: Boolean = false
52 56
53 private lateinit var game: Game 57 private lateinit var game: Game
54 58
@@ -173,15 +177,33 @@ open class EmulationActivity : AppCompatActivity(), SensorEventListener {
173 } 177 }
174 178
175 override fun onSensorChanged(event: SensorEvent) { 179 override fun onSensorChanged(event: SensorEvent) {
180 val rotation = this.display?.rotation
181 if (rotation == Surface.ROTATION_90) {
182 flipMotionOrientation = true
183 }
184 if (rotation == Surface.ROTATION_270) {
185 flipMotionOrientation = false
186 }
187
176 if (event.sensor.type == Sensor.TYPE_ACCELEROMETER) { 188 if (event.sensor.type == Sensor.TYPE_ACCELEROMETER) {
177 accel[0] = -event.values[1] / SensorManager.GRAVITY_EARTH 189 if (flipMotionOrientation) {
178 accel[1] = event.values[0] / SensorManager.GRAVITY_EARTH 190 accel[0] = event.values[1] / SensorManager.GRAVITY_EARTH
191 accel[1] = -event.values[0] / SensorManager.GRAVITY_EARTH
192 } else {
193 accel[0] = -event.values[1] / SensorManager.GRAVITY_EARTH
194 accel[1] = event.values[0] / SensorManager.GRAVITY_EARTH
195 }
179 accel[2] = -event.values[2] / SensorManager.GRAVITY_EARTH 196 accel[2] = -event.values[2] / SensorManager.GRAVITY_EARTH
180 } 197 }
181 if (event.sensor.type == Sensor.TYPE_GYROSCOPE) { 198 if (event.sensor.type == Sensor.TYPE_GYROSCOPE) {
182 // Investigate why sensor value is off by 6x 199 // Investigate why sensor value is off by 6x
183 gyro[0] = event.values[1] / 6.0f 200 if (flipMotionOrientation) {
184 gyro[1] = -event.values[0] / 6.0f 201 gyro[0] = -event.values[1] / 6.0f
202 gyro[1] = event.values[0] / 6.0f
203 } else {
204 gyro[0] = event.values[1] / 6.0f
205 gyro[1] = -event.values[0] / 6.0f
206 }
185 gyro[2] = event.values[2] / 6.0f 207 gyro[2] = event.values[2] / 6.0f
186 } 208 }
187 209