summaryrefslogtreecommitdiff
path: root/src/core/hid/motion_input.cpp
diff options
context:
space:
mode:
authorGravatar liamwhite2023-02-25 12:44:13 -0500
committerGravatar GitHub2023-02-25 12:44:13 -0500
commit833afb7ce340030593f5d4fcb3cbd59a19530a7f (patch)
treee6f89696755222f2604cdd1a77b6e62dc32cd724 /src/core/hid/motion_input.cpp
parentMerge pull request #9857 from german77/fwupdate (diff)
parentcore: hid: Restore motion state on refresh and clamp motion values (diff)
downloadyuzu-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.cpp14
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
15void MotionInput::SetPID(f32 new_kp, f32 new_ki, f32 new_kd) { 17void 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
21void MotionInput::SetAcceleration(const Common::Vec3f& acceleration) { 23void 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
25void MotionInput::SetGyroscope(const Common::Vec3f& gyroscope) { 31void 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
74void MotionInput::ResetQuaternion() {
75 quat = {{0.0f, 0.0f, -1.0f}, 0.0f};
76}
77
64bool MotionInput::IsMoving(f32 sensitivity) const { 78bool 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}