diff options
| author | 2023-02-25 12:44:13 -0500 | |
|---|---|---|
| committer | 2023-02-25 12:44:13 -0500 | |
| commit | 833afb7ce340030593f5d4fcb3cbd59a19530a7f (patch) | |
| tree | e6f89696755222f2604cdd1a77b6e62dc32cd724 /src/core/hid/motion_input.cpp | |
| parent | Merge pull request #9857 from german77/fwupdate (diff) | |
| parent | core: hid: Restore motion state on refresh and clamp motion values (diff) | |
| download | yuzu-833afb7ce340030593f5d4fcb3cbd59a19530a7f.tar.gz yuzu-833afb7ce340030593f5d4fcb3cbd59a19530a7f.tar.xz yuzu-833afb7ce340030593f5d4fcb3cbd59a19530a7f.zip | |
Merge pull request #9848 from german77/metroid_motion
input_common: Implement dedicated motion from mouse
Diffstat (limited to 'src/core/hid/motion_input.cpp')
| -rw-r--r-- | src/core/hid/motion_input.cpp | 14 |
1 files changed, 14 insertions, 0 deletions
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 | } |