diff options
Diffstat (limited to 'src/core')
| -rw-r--r-- | src/core/hid/emulated_controller.cpp | 6 | ||||
| -rw-r--r-- | src/core/hid/emulated_controller.h | 1 | ||||
| -rw-r--r-- | src/core/hid/input_converter.cpp | 1 | ||||
| -rw-r--r-- | src/core/hid/motion_input.cpp | 36 | ||||
| -rw-r--r-- | src/core/hid/motion_input.h | 2 |
5 files changed, 42 insertions, 4 deletions
diff --git a/src/core/hid/emulated_controller.cpp b/src/core/hid/emulated_controller.cpp index db71f1c19..ecab85893 100644 --- a/src/core/hid/emulated_controller.cpp +++ b/src/core/hid/emulated_controller.cpp | |||
| @@ -376,6 +376,7 @@ void EmulatedController::ReloadInput() { | |||
| 376 | motion.accel = emulated_motion.GetAcceleration(); | 376 | motion.accel = emulated_motion.GetAcceleration(); |
| 377 | motion.gyro = emulated_motion.GetGyroscope(); | 377 | motion.gyro = emulated_motion.GetGyroscope(); |
| 378 | motion.rotation = emulated_motion.GetRotations(); | 378 | motion.rotation = emulated_motion.GetRotations(); |
| 379 | motion.euler = emulated_motion.GetEulerAngles(); | ||
| 379 | motion.orientation = emulated_motion.GetOrientation(); | 380 | motion.orientation = emulated_motion.GetOrientation(); |
| 380 | motion.is_at_rest = !emulated_motion.IsMoving(motion_sensitivity); | 381 | motion.is_at_rest = !emulated_motion.IsMoving(motion_sensitivity); |
| 381 | } | 382 | } |
| @@ -980,14 +981,11 @@ void EmulatedController::SetMotion(const Common::Input::CallbackStatus& callback | |||
| 980 | emulated.UpdateOrientation(raw_status.delta_timestamp); | 981 | emulated.UpdateOrientation(raw_status.delta_timestamp); |
| 981 | force_update_motion = raw_status.force_update; | 982 | force_update_motion = raw_status.force_update; |
| 982 | 983 | ||
| 983 | if (is_configuring) { | ||
| 984 | return; | ||
| 985 | } | ||
| 986 | |||
| 987 | auto& motion = controller.motion_state[index]; | 984 | auto& motion = controller.motion_state[index]; |
| 988 | motion.accel = emulated.GetAcceleration(); | 985 | motion.accel = emulated.GetAcceleration(); |
| 989 | motion.gyro = emulated.GetGyroscope(); | 986 | motion.gyro = emulated.GetGyroscope(); |
| 990 | motion.rotation = emulated.GetRotations(); | 987 | motion.rotation = emulated.GetRotations(); |
| 988 | motion.euler = emulated.GetEulerAngles(); | ||
| 991 | motion.orientation = emulated.GetOrientation(); | 989 | motion.orientation = emulated.GetOrientation(); |
| 992 | motion.is_at_rest = !emulated.IsMoving(motion_sensitivity); | 990 | motion.is_at_rest = !emulated.IsMoving(motion_sensitivity); |
| 993 | } | 991 | } |
diff --git a/src/core/hid/emulated_controller.h b/src/core/hid/emulated_controller.h index 429655355..6e01f4e12 100644 --- a/src/core/hid/emulated_controller.h +++ b/src/core/hid/emulated_controller.h | |||
| @@ -106,6 +106,7 @@ struct ControllerMotion { | |||
| 106 | Common::Vec3f accel{}; | 106 | Common::Vec3f accel{}; |
| 107 | Common::Vec3f gyro{}; | 107 | Common::Vec3f gyro{}; |
| 108 | Common::Vec3f rotation{}; | 108 | Common::Vec3f rotation{}; |
| 109 | Common::Vec3f euler{}; | ||
| 109 | std::array<Common::Vec3f, 3> orientation{}; | 110 | std::array<Common::Vec3f, 3> orientation{}; |
| 110 | bool is_at_rest{}; | 111 | bool is_at_rest{}; |
| 111 | }; | 112 | }; |
diff --git a/src/core/hid/input_converter.cpp b/src/core/hid/input_converter.cpp index 7cee39a53..a38e3bb3f 100644 --- a/src/core/hid/input_converter.cpp +++ b/src/core/hid/input_converter.cpp | |||
| @@ -54,6 +54,7 @@ Common::Input::ButtonStatus TransformToButton(const Common::Input::CallbackStatu | |||
| 54 | case Common::Input::InputType::Analog: | 54 | case Common::Input::InputType::Analog: |
| 55 | status.value = TransformToTrigger(callback).pressed.value; | 55 | status.value = TransformToTrigger(callback).pressed.value; |
| 56 | status.toggle = callback.analog_status.properties.toggle; | 56 | status.toggle = callback.analog_status.properties.toggle; |
| 57 | status.inverted = callback.analog_status.properties.inverted_button; | ||
| 57 | break; | 58 | break; |
| 58 | case Common::Input::InputType::Trigger: | 59 | case Common::Input::InputType::Trigger: |
| 59 | status.value = TransformToTrigger(callback).pressed.value; | 60 | status.value = TransformToTrigger(callback).pressed.value; |
diff --git a/src/core/hid/motion_input.cpp b/src/core/hid/motion_input.cpp index 0dd66c1cc..b60478dbb 100644 --- a/src/core/hid/motion_input.cpp +++ b/src/core/hid/motion_input.cpp | |||
| @@ -1,6 +1,8 @@ | |||
| 1 | // SPDX-FileCopyrightText: Copyright 2020 yuzu Emulator Project | 1 | // SPDX-FileCopyrightText: Copyright 2020 yuzu Emulator Project |
| 2 | // SPDX-License-Identifier: GPL-2.0-or-later | 2 | // SPDX-License-Identifier: GPL-2.0-or-later |
| 3 | 3 | ||
| 4 | #include <cmath> | ||
| 5 | |||
| 4 | #include "common/math_util.h" | 6 | #include "common/math_util.h" |
| 5 | #include "core/hid/motion_input.h" | 7 | #include "core/hid/motion_input.h" |
| 6 | 8 | ||
| @@ -51,6 +53,20 @@ void MotionInput::SetQuaternion(const Common::Quaternion<f32>& quaternion) { | |||
| 51 | quat = quaternion; | 53 | quat = quaternion; |
| 52 | } | 54 | } |
| 53 | 55 | ||
| 56 | void MotionInput::SetEulerAngles(const Common::Vec3f& euler_angles) { | ||
| 57 | const float cr = std::cos(euler_angles.x * 0.5f); | ||
| 58 | const float sr = std::sin(euler_angles.x * 0.5f); | ||
| 59 | const float cp = std::cos(euler_angles.y * 0.5f); | ||
| 60 | const float sp = std::sin(euler_angles.y * 0.5f); | ||
| 61 | const float cy = std::cos(euler_angles.z * 0.5f); | ||
| 62 | const float sy = std::sin(euler_angles.z * 0.5f); | ||
| 63 | |||
| 64 | quat.w = cr * cp * cy + sr * sp * sy; | ||
| 65 | quat.xyz.x = sr * cp * cy - cr * sp * sy; | ||
| 66 | quat.xyz.y = cr * sp * cy + sr * cp * sy; | ||
| 67 | quat.xyz.z = cr * cp * sy - sr * sp * cy; | ||
| 68 | } | ||
| 69 | |||
| 54 | void MotionInput::SetGyroBias(const Common::Vec3f& bias) { | 70 | void MotionInput::SetGyroBias(const Common::Vec3f& bias) { |
| 55 | gyro_bias = bias; | 71 | gyro_bias = bias; |
| 56 | } | 72 | } |
| @@ -222,6 +238,26 @@ Common::Vec3f MotionInput::GetRotations() const { | |||
| 222 | return rotations; | 238 | return rotations; |
| 223 | } | 239 | } |
| 224 | 240 | ||
| 241 | Common::Vec3f MotionInput::GetEulerAngles() const { | ||
| 242 | // roll (x-axis rotation) | ||
| 243 | const float sinr_cosp = 2 * (quat.w * quat.xyz.x + quat.xyz.y * quat.xyz.z); | ||
| 244 | const float cosr_cosp = 1 - 2 * (quat.xyz.x * quat.xyz.x + quat.xyz.y * quat.xyz.y); | ||
| 245 | |||
| 246 | // pitch (y-axis rotation) | ||
| 247 | const float sinp = std::sqrt(1 + 2 * (quat.w * quat.xyz.y - quat.xyz.x * quat.xyz.z)); | ||
| 248 | const float cosp = std::sqrt(1 - 2 * (quat.w * quat.xyz.y - quat.xyz.x * quat.xyz.z)); | ||
| 249 | |||
| 250 | // yaw (z-axis rotation) | ||
| 251 | const float siny_cosp = 2 * (quat.w * quat.xyz.z + quat.xyz.x * quat.xyz.y); | ||
| 252 | const float cosy_cosp = 1 - 2 * (quat.xyz.y * quat.xyz.y + quat.xyz.z * quat.xyz.z); | ||
| 253 | |||
| 254 | return { | ||
| 255 | std::atan2(sinr_cosp, cosr_cosp), | ||
| 256 | 2 * std::atan2(sinp, cosp) - Common::PI / 2, | ||
| 257 | std::atan2(siny_cosp, cosy_cosp), | ||
| 258 | }; | ||
| 259 | } | ||
| 260 | |||
| 225 | void MotionInput::ResetOrientation() { | 261 | void MotionInput::ResetOrientation() { |
| 226 | if (!reset_enabled || only_accelerometer) { | 262 | if (!reset_enabled || only_accelerometer) { |
| 227 | return; | 263 | return; |
diff --git a/src/core/hid/motion_input.h b/src/core/hid/motion_input.h index 9f3fc1cf7..482719359 100644 --- a/src/core/hid/motion_input.h +++ b/src/core/hid/motion_input.h | |||
| @@ -35,6 +35,7 @@ public: | |||
| 35 | void SetAcceleration(const Common::Vec3f& acceleration); | 35 | void SetAcceleration(const Common::Vec3f& acceleration); |
| 36 | void SetGyroscope(const Common::Vec3f& gyroscope); | 36 | void SetGyroscope(const Common::Vec3f& gyroscope); |
| 37 | void SetQuaternion(const Common::Quaternion<f32>& quaternion); | 37 | void SetQuaternion(const Common::Quaternion<f32>& quaternion); |
| 38 | void SetEulerAngles(const Common::Vec3f& euler_angles); | ||
| 38 | void SetGyroBias(const Common::Vec3f& bias); | 39 | void SetGyroBias(const Common::Vec3f& bias); |
| 39 | void SetGyroThreshold(f32 threshold); | 40 | void SetGyroThreshold(f32 threshold); |
| 40 | 41 | ||
| @@ -54,6 +55,7 @@ public: | |||
| 54 | [[nodiscard]] Common::Vec3f GetGyroBias() const; | 55 | [[nodiscard]] Common::Vec3f GetGyroBias() const; |
| 55 | [[nodiscard]] Common::Vec3f GetRotations() const; | 56 | [[nodiscard]] Common::Vec3f GetRotations() const; |
| 56 | [[nodiscard]] Common::Quaternion<f32> GetQuaternion() const; | 57 | [[nodiscard]] Common::Quaternion<f32> GetQuaternion() const; |
| 58 | [[nodiscard]] Common::Vec3f GetEulerAngles() const; | ||
| 57 | 59 | ||
| 58 | [[nodiscard]] bool IsMoving(f32 sensitivity) const; | 60 | [[nodiscard]] bool IsMoving(f32 sensitivity) const; |
| 59 | [[nodiscard]] bool IsCalibrated(f32 sensitivity) const; | 61 | [[nodiscard]] bool IsCalibrated(f32 sensitivity) const; |