summaryrefslogtreecommitdiffstats
path: root/src/input_common/motion_input.h
diff options
context:
space:
mode:
authorgerman <german@thesoftwareartisans.com>2020-08-24 02:26:47 +0200
committergerman <german@thesoftwareartisans.com>2020-08-28 00:19:21 +0200
commit2d207ec609d1280bbfcdb822cceb8adc42afac3a (patch)
tree2990f7f63b3f6847636c85d6e00aac323f6856de /src/input_common/motion_input.h
parentMerge pull request #4530 from Morph1984/mjolnir-p1 (diff)
downloadyuzu-2d207ec609d1280bbfcdb822cceb8adc42afac3a.tar
yuzu-2d207ec609d1280bbfcdb822cceb8adc42afac3a.tar.gz
yuzu-2d207ec609d1280bbfcdb822cceb8adc42afac3a.tar.bz2
yuzu-2d207ec609d1280bbfcdb822cceb8adc42afac3a.tar.lz
yuzu-2d207ec609d1280bbfcdb822cceb8adc42afac3a.tar.xz
yuzu-2d207ec609d1280bbfcdb822cceb8adc42afac3a.tar.zst
yuzu-2d207ec609d1280bbfcdb822cceb8adc42afac3a.zip
Diffstat (limited to 'src/input_common/motion_input.h')
-rw-r--r--src/input_common/motion_input.h62
1 files changed, 62 insertions, 0 deletions
diff --git a/src/input_common/motion_input.h b/src/input_common/motion_input.h
new file mode 100644
index 000000000..4b8093d8c
--- /dev/null
+++ b/src/input_common/motion_input.h
@@ -0,0 +1,62 @@
+// Copyright 2014 Dolphin Emulator Project
+// Licensed under GPLv2+
+// Refer to the license.txt file included.
+
+#pragma once
+
+#include "common/common_types.h"
+#include "common/quaternion.h"
+#include "common/vector_math.h"
+
+namespace InputCommon {
+
+class MotionInput {
+public:
+ MotionInput(f32 new_kp, f32 new_ki, f32 new_kd);
+
+ void SetAcceleration(Common::Vec3f acceleration);
+ void SetGyroscope(Common::Vec3f acceleration);
+ void SetQuaternion(Common::Quaternion<f32> quaternion);
+ void SetGyroDrift(Common::Vec3f drift);
+ void SetGyroThreshold(f32 threshold);
+
+ void EnableReset(bool reset);
+ void ResetRotations();
+
+ void UpdateRotation(u64 elapsed_time);
+ void UpdateOrientation(u64 elapsed_time);
+
+ std::array<Common::Vec3f, 3> GetOrientation();
+ Common::Vec3f GetAcceleration();
+ Common::Vec3f GetGyroscope();
+ Common::Vec3f GetRotations();
+ Common::Quaternion<f32> GetQuaternion();
+
+ bool IsMoving(f32 sensitivity);
+ bool IsCalibrated(f32 sensitivity);
+
+ // PID constants
+ const f32 kp;
+ const f32 ki;
+ const f32 kd;
+
+private:
+ void resetOrientation();
+
+ // PID errors
+ Common::Vec3f real_error;
+ Common::Vec3f integral_error;
+ Common::Vec3f derivative_error;
+
+ Common::Quaternion<f32> quat;
+ Common::Vec3f rotations;
+ Common::Vec3f accel;
+ Common::Vec3f gyro;
+ Common::Vec3f gyro_drift;
+
+ f32 gyro_threshold;
+ f32 reset_counter;
+ bool reset_enabled;
+};
+
+} // namespace InputCommon