summaryrefslogtreecommitdiff
path: root/src/core/hid
diff options
context:
space:
mode:
authorGravatar Narr the Reg2021-11-29 12:40:29 -0600
committerGravatar german772021-12-12 23:26:04 -0600
commit316f80af87c3290ad3ceda99fe9cf02f1d935b0c (patch)
tree6b933d2399f02ff42c077d0f2f342b9ffbb21cf5 /src/core/hid
parentMerge pull request #7488 from vonchenplus/support_multiple_videos_playing (diff)
downloadyuzu-316f80af87c3290ad3ceda99fe9cf02f1d935b0c.tar.gz
yuzu-316f80af87c3290ad3ceda99fe9cf02f1d935b0c.tar.xz
yuzu-316f80af87c3290ad3ceda99fe9cf02f1d935b0c.zip
service/hid: Improve console motion accuracy
Diffstat (limited to 'src/core/hid')
-rw-r--r--src/core/hid/emulated_console.cpp3
-rw-r--r--src/core/hid/emulated_console.h2
-rw-r--r--src/core/hid/motion_input.cpp12
-rw-r--r--src/core/hid/motion_input.h5
4 files changed, 16 insertions, 6 deletions
diff --git a/src/core/hid/emulated_console.cpp b/src/core/hid/emulated_console.cpp
index 80db8e9c6..6744c6846 100644
--- a/src/core/hid/emulated_console.cpp
+++ b/src/core/hid/emulated_console.cpp
@@ -157,7 +157,10 @@ void EmulatedConsole::SetMotion(Common::Input::CallbackStatus callback) {
157 motion.rotation = emulated.GetGyroscope(); 157 motion.rotation = emulated.GetGyroscope();
158 motion.orientation = emulated.GetOrientation(); 158 motion.orientation = emulated.GetOrientation();
159 motion.quaternion = emulated.GetQuaternion(); 159 motion.quaternion = emulated.GetQuaternion();
160 motion.gyro_bias = emulated.GetGyroBias();
160 motion.is_at_rest = !emulated.IsMoving(motion_sensitivity); 161 motion.is_at_rest = !emulated.IsMoving(motion_sensitivity);
162 // Find what is this value
163 motion.verticalization_error = 0.0f;
161 164
162 TriggerOnChange(ConsoleTriggerType::Motion); 165 TriggerOnChange(ConsoleTriggerType::Motion);
163} 166}
diff --git a/src/core/hid/emulated_console.h b/src/core/hid/emulated_console.h
index bb3d7ab90..e682a76c2 100644
--- a/src/core/hid/emulated_console.h
+++ b/src/core/hid/emulated_console.h
@@ -50,6 +50,8 @@ struct ConsoleMotion {
50 Common::Vec3f rotation{}; 50 Common::Vec3f rotation{};
51 std::array<Common::Vec3f, 3> orientation{}; 51 std::array<Common::Vec3f, 3> orientation{};
52 Common::Quaternion<f32> quaternion{}; 52 Common::Quaternion<f32> quaternion{};
53 Common::Vec3f gyro_bias{};
54 f32 verticalization_error{};
53 bool is_at_rest{}; 55 bool is_at_rest{};
54}; 56};
55 57
diff --git a/src/core/hid/motion_input.cpp b/src/core/hid/motion_input.cpp
index c25fea966..a23f192d7 100644
--- a/src/core/hid/motion_input.cpp
+++ b/src/core/hid/motion_input.cpp
@@ -23,11 +23,11 @@ void MotionInput::SetAcceleration(const Common::Vec3f& acceleration) {
23} 23}
24 24
25void MotionInput::SetGyroscope(const Common::Vec3f& gyroscope) { 25void MotionInput::SetGyroscope(const Common::Vec3f& gyroscope) {
26 gyro = gyroscope - gyro_drift; 26 gyro = gyroscope - gyro_bias;
27 27
28 // Auto adjust drift to minimize drift 28 // Auto adjust drift to minimize drift
29 if (!IsMoving(0.1f)) { 29 if (!IsMoving(0.1f)) {
30 gyro_drift = (gyro_drift * 0.9999f) + (gyroscope * 0.0001f); 30 gyro_bias = (gyro_bias * 0.9999f) + (gyroscope * 0.0001f);
31 } 31 }
32 32
33 if (gyro.Length2() < gyro_threshold) { 33 if (gyro.Length2() < gyro_threshold) {
@@ -41,8 +41,8 @@ void MotionInput::SetQuaternion(const Common::Quaternion<f32>& quaternion) {
41 quat = quaternion; 41 quat = quaternion;
42} 42}
43 43
44void MotionInput::SetGyroDrift(const Common::Vec3f& drift) { 44void MotionInput::SetGyroBias(const Common::Vec3f& bias) {
45 gyro_drift = drift; 45 gyro_bias = bias;
46} 46}
47 47
48void MotionInput::SetGyroThreshold(f32 threshold) { 48void MotionInput::SetGyroThreshold(f32 threshold) {
@@ -192,6 +192,10 @@ Common::Vec3f MotionInput::GetGyroscope() const {
192 return gyro; 192 return gyro;
193} 193}
194 194
195Common::Vec3f MotionInput::GetGyroBias() const {
196 return gyro_bias;
197}
198
195Common::Quaternion<f32> MotionInput::GetQuaternion() const { 199Common::Quaternion<f32> MotionInput::GetQuaternion() const {
196 return quat; 200 return quat;
197} 201}
diff --git a/src/core/hid/motion_input.h b/src/core/hid/motion_input.h
index 5b5b420bb..bca4520fa 100644
--- a/src/core/hid/motion_input.h
+++ b/src/core/hid/motion_input.h
@@ -24,7 +24,7 @@ public:
24 void SetAcceleration(const Common::Vec3f& acceleration); 24 void SetAcceleration(const Common::Vec3f& acceleration);
25 void SetGyroscope(const Common::Vec3f& gyroscope); 25 void SetGyroscope(const Common::Vec3f& gyroscope);
26 void SetQuaternion(const Common::Quaternion<f32>& quaternion); 26 void SetQuaternion(const Common::Quaternion<f32>& quaternion);
27 void SetGyroDrift(const Common::Vec3f& drift); 27 void SetGyroBias(const Common::Vec3f& bias);
28 void SetGyroThreshold(f32 threshold); 28 void SetGyroThreshold(f32 threshold);
29 29
30 void EnableReset(bool reset); 30 void EnableReset(bool reset);
@@ -36,6 +36,7 @@ public:
36 [[nodiscard]] std::array<Common::Vec3f, 3> GetOrientation() const; 36 [[nodiscard]] std::array<Common::Vec3f, 3> GetOrientation() const;
37 [[nodiscard]] Common::Vec3f GetAcceleration() const; 37 [[nodiscard]] Common::Vec3f GetAcceleration() const;
38 [[nodiscard]] Common::Vec3f GetGyroscope() const; 38 [[nodiscard]] Common::Vec3f GetGyroscope() const;
39 [[nodiscard]] Common::Vec3f GetGyroBias() const;
39 [[nodiscard]] Common::Vec3f GetRotations() const; 40 [[nodiscard]] Common::Vec3f GetRotations() const;
40 [[nodiscard]] Common::Quaternion<f32> GetQuaternion() const; 41 [[nodiscard]] Common::Quaternion<f32> GetQuaternion() const;
41 42
@@ -69,7 +70,7 @@ private:
69 Common::Vec3f gyro; 70 Common::Vec3f gyro;
70 71
71 // Vector to be substracted from gyro measurements 72 // Vector to be substracted from gyro measurements
72 Common::Vec3f gyro_drift; 73 Common::Vec3f gyro_bias;
73 74
74 // Minimum gyro amplitude to detect if the device is moving 75 // Minimum gyro amplitude to detect if the device is moving
75 f32 gyro_threshold = 0.0f; 76 f32 gyro_threshold = 0.0f;