VERY experimental Nintendo Switch 2 emulator
C++
android: Invert rotation to match phone orientation
german773e1613dc20a2
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.ktindex 1301583a03..4a0f88f527 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.SensorEventimport android.hardware.SensorEventListenerimport android.hardware.SensorManagerimport android.os.Bundle-import android.view.*+import android.view.InputDeviceimport android.view.KeyEventimport android.view.MotionEvent+import android.view.Surface+import android.view.View+import android.view.WindowManagerimport android.view.inputmethod.InputMethodManagerimport androidx.appcompat.app.AppCompatActivityimport androidx.preference.PreferenceManager@@ -49,6 +52,7 @@ open class EmulationActivity : AppCompatActivity(), SensorEventListener {private val gyro = FloatArray(3)private val accel = FloatArray(3)private var motionTimestamp: Long = 0+ private var flipMotionOrientation: Boolean = falseprivate lateinit var game: Game@@ -173,15 +177,33 @@ open class EmulationActivity : AppCompatActivity(), SensorEventListener {}override fun onSensorChanged(event: SensorEvent) {+ val rotation = this.display?.rotation+ if (rotation == Surface.ROTATION_90) {+ flipMotionOrientation = true+ }+ if (rotation == Surface.ROTATION_270) {+ flipMotionOrientation = false+ }+if (event.sensor.type == Sensor.TYPE_ACCELEROMETER) {- accel[0] = -event.values[1] / SensorManager.GRAVITY_EARTH- accel[1] = event.values[0] / SensorManager.GRAVITY_EARTH+ if (flipMotionOrientation) {+ accel[0] = event.values[1] / SensorManager.GRAVITY_EARTH+ accel[1] = -event.values[0] / SensorManager.GRAVITY_EARTH+ } else {+ accel[0] = -event.values[1] / SensorManager.GRAVITY_EARTH+ accel[1] = event.values[0] / SensorManager.GRAVITY_EARTH+ }accel[2] = -event.values[2] / SensorManager.GRAVITY_EARTH}if (event.sensor.type == Sensor.TYPE_GYROSCOPE) {// Investigate why sensor value is off by 6x- gyro[0] = event.values[1] / 6.0f- gyro[1] = -event.values[0] / 6.0f+ if (flipMotionOrientation) {+ gyro[0] = -event.values[1] / 6.0f+ gyro[1] = event.values[0] / 6.0f+ } else {+ gyro[0] = event.values[1] / 6.0f+ gyro[1] = -event.values[0] / 6.0f+ }gyro[2] = event.values[2] / 6.0f}