diff options
Diffstat (limited to 'src/core')
| -rw-r--r-- | src/core/hid/emulated_controller.cpp | 12 | ||||
| -rw-r--r-- | src/core/hid/motion_input.cpp | 14 | ||||
| -rw-r--r-- | src/core/hid/motion_input.h | 6 |
3 files changed, 30 insertions, 2 deletions
diff --git a/src/core/hid/emulated_controller.cpp b/src/core/hid/emulated_controller.cpp index 6d5a3dead..a29c9a6f8 100644 --- a/src/core/hid/emulated_controller.cpp +++ b/src/core/hid/emulated_controller.cpp | |||
| @@ -363,7 +363,17 @@ void EmulatedController::ReloadInput() { | |||
| 363 | SetMotion(callback, index); | 363 | SetMotion(callback, index); |
| 364 | }, | 364 | }, |
| 365 | }); | 365 | }); |
| 366 | motion_devices[index]->ForceUpdate(); | 366 | |
| 367 | // Restore motion state | ||
| 368 | auto& emulated_motion = controller.motion_values[index].emulated; | ||
| 369 | auto& motion = controller.motion_state[index]; | ||
| 370 | emulated_motion.ResetRotations(); | ||
| 371 | emulated_motion.ResetQuaternion(); | ||
| 372 | motion.accel = emulated_motion.GetAcceleration(); | ||
| 373 | motion.gyro = emulated_motion.GetGyroscope(); | ||
| 374 | motion.rotation = emulated_motion.GetRotations(); | ||
| 375 | motion.orientation = emulated_motion.GetOrientation(); | ||
| 376 | motion.is_at_rest = !emulated_motion.IsMoving(motion_sensitivity); | ||
| 367 | } | 377 | } |
| 368 | 378 | ||
| 369 | for (std::size_t index = 0; index < camera_devices.size(); ++index) { | 379 | for (std::size_t index = 0; index < camera_devices.size(); ++index) { |
diff --git a/src/core/hid/motion_input.cpp b/src/core/hid/motion_input.cpp index eef6edf4b..0dd66c1cc 100644 --- a/src/core/hid/motion_input.cpp +++ b/src/core/hid/motion_input.cpp | |||
| @@ -10,6 +10,8 @@ MotionInput::MotionInput() { | |||
| 10 | // Initialize PID constants with default values | 10 | // Initialize PID constants with default values |
| 11 | SetPID(0.3f, 0.005f, 0.0f); | 11 | SetPID(0.3f, 0.005f, 0.0f); |
| 12 | SetGyroThreshold(ThresholdStandard); | 12 | SetGyroThreshold(ThresholdStandard); |
| 13 | ResetQuaternion(); | ||
| 14 | ResetRotations(); | ||
| 13 | } | 15 | } |
| 14 | 16 | ||
| 15 | void MotionInput::SetPID(f32 new_kp, f32 new_ki, f32 new_kd) { | 17 | void MotionInput::SetPID(f32 new_kp, f32 new_ki, f32 new_kd) { |
| @@ -20,11 +22,19 @@ void MotionInput::SetPID(f32 new_kp, f32 new_ki, f32 new_kd) { | |||
| 20 | 22 | ||
| 21 | void MotionInput::SetAcceleration(const Common::Vec3f& acceleration) { | 23 | void MotionInput::SetAcceleration(const Common::Vec3f& acceleration) { |
| 22 | accel = acceleration; | 24 | accel = acceleration; |
| 25 | |||
| 26 | accel.x = std::clamp(accel.x, -AccelMaxValue, AccelMaxValue); | ||
| 27 | accel.y = std::clamp(accel.y, -AccelMaxValue, AccelMaxValue); | ||
| 28 | accel.z = std::clamp(accel.z, -AccelMaxValue, AccelMaxValue); | ||
| 23 | } | 29 | } |
| 24 | 30 | ||
| 25 | void MotionInput::SetGyroscope(const Common::Vec3f& gyroscope) { | 31 | void MotionInput::SetGyroscope(const Common::Vec3f& gyroscope) { |
| 26 | gyro = gyroscope - gyro_bias; | 32 | gyro = gyroscope - gyro_bias; |
| 27 | 33 | ||
| 34 | gyro.x = std::clamp(gyro.x, -GyroMaxValue, GyroMaxValue); | ||
| 35 | gyro.y = std::clamp(gyro.y, -GyroMaxValue, GyroMaxValue); | ||
| 36 | gyro.z = std::clamp(gyro.z, -GyroMaxValue, GyroMaxValue); | ||
| 37 | |||
| 28 | // Auto adjust drift to minimize drift | 38 | // Auto adjust drift to minimize drift |
| 29 | if (!IsMoving(IsAtRestRelaxed)) { | 39 | if (!IsMoving(IsAtRestRelaxed)) { |
| 30 | gyro_bias = (gyro_bias * 0.9999f) + (gyroscope * 0.0001f); | 40 | gyro_bias = (gyro_bias * 0.9999f) + (gyroscope * 0.0001f); |
| @@ -61,6 +71,10 @@ void MotionInput::ResetRotations() { | |||
| 61 | rotations = {}; | 71 | rotations = {}; |
| 62 | } | 72 | } |
| 63 | 73 | ||
| 74 | void MotionInput::ResetQuaternion() { | ||
| 75 | quat = {{0.0f, 0.0f, -1.0f}, 0.0f}; | ||
| 76 | } | ||
| 77 | |||
| 64 | bool MotionInput::IsMoving(f32 sensitivity) const { | 78 | bool MotionInput::IsMoving(f32 sensitivity) const { |
| 65 | return gyro.Length() >= sensitivity || accel.Length() <= 0.9f || accel.Length() >= 1.1f; | 79 | return gyro.Length() >= sensitivity || accel.Length() <= 0.9f || accel.Length() >= 1.1f; |
| 66 | } | 80 | } |
diff --git a/src/core/hid/motion_input.h b/src/core/hid/motion_input.h index 9180bb9aa..e2c1bbf95 100644 --- a/src/core/hid/motion_input.h +++ b/src/core/hid/motion_input.h | |||
| @@ -20,6 +20,9 @@ public: | |||
| 20 | static constexpr float IsAtRestStandard = 0.01f; | 20 | static constexpr float IsAtRestStandard = 0.01f; |
| 21 | static constexpr float IsAtRestThight = 0.005f; | 21 | static constexpr float IsAtRestThight = 0.005f; |
| 22 | 22 | ||
| 23 | static constexpr float GyroMaxValue = 5.0f; | ||
| 24 | static constexpr float AccelMaxValue = 7.0f; | ||
| 25 | |||
| 23 | explicit MotionInput(); | 26 | explicit MotionInput(); |
| 24 | 27 | ||
| 25 | MotionInput(const MotionInput&) = default; | 28 | MotionInput(const MotionInput&) = default; |
| @@ -40,6 +43,7 @@ public: | |||
| 40 | 43 | ||
| 41 | void EnableReset(bool reset); | 44 | void EnableReset(bool reset); |
| 42 | void ResetRotations(); | 45 | void ResetRotations(); |
| 46 | void ResetQuaternion(); | ||
| 43 | 47 | ||
| 44 | void UpdateRotation(u64 elapsed_time); | 48 | void UpdateRotation(u64 elapsed_time); |
| 45 | void UpdateOrientation(u64 elapsed_time); | 49 | void UpdateOrientation(u64 elapsed_time); |
| @@ -69,7 +73,7 @@ private: | |||
| 69 | Common::Vec3f derivative_error; | 73 | Common::Vec3f derivative_error; |
| 70 | 74 | ||
| 71 | // Quaternion containing the device orientation | 75 | // Quaternion containing the device orientation |
| 72 | Common::Quaternion<f32> quat{{0.0f, 0.0f, -1.0f}, 0.0f}; | 76 | Common::Quaternion<f32> quat; |
| 73 | 77 | ||
| 74 | // Number of full rotations in each axis | 78 | // Number of full rotations in each axis |
| 75 | Common::Vec3f rotations; | 79 | Common::Vec3f rotations; |