diff options
| author | 2023-05-09 23:44:00 -0600 | |
|---|---|---|
| committer | 2023-06-03 00:06:01 -0700 | |
| commit | aa957df0dcd01afeac41afe7a7246f57b61acedc (patch) | |
| tree | cc7bcc8a71f9b0b1d231f48f29054a00ea8f15cb /src/android | |
| parent | android: vulkan_device: Skip BGR565 emulation on S8gen2. (diff) | |
| download | yuzu-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.kt | 32 |
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 | |||
| 13 | import android.hardware.SensorEventListener | 13 | import android.hardware.SensorEventListener |
| 14 | import android.hardware.SensorManager | 14 | import android.hardware.SensorManager |
| 15 | import android.os.Bundle | 15 | import android.os.Bundle |
| 16 | import android.view.* | 16 | import android.view.InputDevice |
| 17 | import android.view.KeyEvent | 17 | import android.view.KeyEvent |
| 18 | import android.view.MotionEvent | 18 | import android.view.MotionEvent |
| 19 | import android.view.Surface | ||
| 20 | import android.view.View | ||
| 21 | import android.view.WindowManager | ||
| 19 | import android.view.inputmethod.InputMethodManager | 22 | import android.view.inputmethod.InputMethodManager |
| 20 | import androidx.appcompat.app.AppCompatActivity | 23 | import androidx.appcompat.app.AppCompatActivity |
| 21 | import androidx.preference.PreferenceManager | 24 | import 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 | ||