diff options
Diffstat (limited to 'src/core/hid/motion_input.h')
| -rw-r--r-- | src/core/hid/motion_input.h | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/src/core/hid/motion_input.h b/src/core/hid/motion_input.h new file mode 100644 index 000000000..3deef5ac3 --- /dev/null +++ b/src/core/hid/motion_input.h | |||
| @@ -0,0 +1,71 @@ | |||
| 1 | // Copyright 2020 yuzu Emulator Project | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included | ||
| 4 | |||
| 5 | #pragma once | ||
| 6 | |||
| 7 | #include "common/common_types.h" | ||
| 8 | #include "common/quaternion.h" | ||
| 9 | #include "common/vector_math.h" | ||
| 10 | |||
| 11 | namespace Core::HID { | ||
| 12 | |||
| 13 | class MotionInput { | ||
| 14 | public: | ||
| 15 | explicit MotionInput(); | ||
| 16 | |||
| 17 | MotionInput(const MotionInput&) = default; | ||
| 18 | MotionInput& operator=(const MotionInput&) = default; | ||
| 19 | |||
| 20 | MotionInput(MotionInput&&) = default; | ||
| 21 | MotionInput& operator=(MotionInput&&) = default; | ||
| 22 | |||
| 23 | void SetPID(f32 new_kp, f32 new_ki, f32 new_kd); | ||
| 24 | void SetAcceleration(const Common::Vec3f& acceleration); | ||
| 25 | void SetGyroscope(const Common::Vec3f& gyroscope); | ||
| 26 | void SetQuaternion(const Common::Quaternion<f32>& quaternion); | ||
| 27 | void SetGyroDrift(const Common::Vec3f& drift); | ||
| 28 | void SetGyroThreshold(f32 threshold); | ||
| 29 | |||
| 30 | void EnableReset(bool reset); | ||
| 31 | void ResetRotations(); | ||
| 32 | |||
| 33 | void UpdateRotation(u64 elapsed_time); | ||
| 34 | void UpdateOrientation(u64 elapsed_time); | ||
| 35 | |||
| 36 | [[nodiscard]] std::array<Common::Vec3f, 3> GetOrientation() const; | ||
| 37 | [[nodiscard]] Common::Vec3f GetAcceleration() const; | ||
| 38 | [[nodiscard]] Common::Vec3f GetGyroscope() const; | ||
| 39 | [[nodiscard]] Common::Vec3f GetRotations() const; | ||
| 40 | [[nodiscard]] Common::Quaternion<f32> GetQuaternion() const; | ||
| 41 | |||
| 42 | [[nodiscard]] bool IsMoving(f32 sensitivity) const; | ||
| 43 | [[nodiscard]] bool IsCalibrated(f32 sensitivity) const; | ||
| 44 | |||
| 45 | private: | ||
| 46 | void ResetOrientation(); | ||
| 47 | void SetOrientationFromAccelerometer(); | ||
| 48 | |||
| 49 | // PID constants | ||
| 50 | f32 kp; | ||
| 51 | f32 ki; | ||
| 52 | f32 kd; | ||
| 53 | |||
| 54 | // PID errors | ||
| 55 | Common::Vec3f real_error; | ||
| 56 | Common::Vec3f integral_error; | ||
| 57 | Common::Vec3f derivative_error; | ||
| 58 | |||
| 59 | Common::Quaternion<f32> quat{{0.0f, 0.0f, -1.0f}, 0.0f}; | ||
| 60 | Common::Vec3f rotations; | ||
| 61 | Common::Vec3f accel; | ||
| 62 | Common::Vec3f gyro; | ||
| 63 | Common::Vec3f gyro_drift; | ||
| 64 | |||
| 65 | f32 gyro_threshold = 0.0f; | ||
| 66 | u32 reset_counter = 0; | ||
| 67 | bool reset_enabled = true; | ||
| 68 | bool only_accelerometer = true; | ||
| 69 | }; | ||
| 70 | |||
| 71 | } // namespace Core::HID | ||