diff options
Diffstat (limited to 'src/input_common/motion_input.h')
| -rw-r--r-- | src/input_common/motion_input.h | 73 |
1 files changed, 73 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..abb957f04 --- /dev/null +++ b/src/input_common/motion_input.h | |||
| @@ -0,0 +1,73 @@ | |||
| 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 | #include "core/frontend/input.h" | ||
| 11 | |||
| 12 | namespace InputCommon { | ||
| 13 | |||
| 14 | class MotionInput { | ||
| 15 | public: | ||
| 16 | MotionInput(f32 new_kp, f32 new_ki, f32 new_kd); | ||
| 17 | |||
| 18 | MotionInput(const MotionInput&) = default; | ||
| 19 | MotionInput& operator=(const MotionInput&) = default; | ||
| 20 | |||
| 21 | MotionInput(MotionInput&&) = default; | ||
| 22 | MotionInput& operator=(MotionInput&&) = default; | ||
| 23 | |||
| 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 | std::array<Common::Vec3f, 3> GetOrientation() const; | ||
| 37 | Common::Vec3f GetAcceleration() const; | ||
| 38 | Common::Vec3f GetGyroscope() const; | ||
| 39 | Common::Vec3f GetRotations() const; | ||
| 40 | Common::Quaternion<f32> GetQuaternion() const; | ||
| 41 | Input::MotionStatus GetMotion() const; | ||
| 42 | Input::MotionStatus GetRandomMotion(int accel_magnitude, int gyro_magnitude) const; | ||
| 43 | |||
| 44 | bool IsMoving(f32 sensitivity) const; | ||
| 45 | bool IsCalibrated(f32 sensitivity) const; | ||
| 46 | |||
| 47 | private: | ||
| 48 | void ResetOrientation(); | ||
| 49 | void SetOrientationFromAccelerometer(); | ||
| 50 | |||
| 51 | // PID constants | ||
| 52 | f32 kp; | ||
| 53 | f32 ki; | ||
| 54 | f32 kd; | ||
| 55 | |||
| 56 | // PID errors | ||
| 57 | Common::Vec3f real_error; | ||
| 58 | Common::Vec3f integral_error; | ||
| 59 | Common::Vec3f derivative_error; | ||
| 60 | |||
| 61 | Common::Quaternion<f32> quat{{0.0f, 0.0f, -1.0f}, 0.0f}; | ||
| 62 | Common::Vec3f rotations; | ||
| 63 | Common::Vec3f accel; | ||
| 64 | Common::Vec3f gyro; | ||
| 65 | Common::Vec3f gyro_drift; | ||
| 66 | |||
| 67 | f32 gyro_threshold = 0.0f; | ||
| 68 | u32 reset_counter = 0; | ||
| 69 | bool reset_enabled = true; | ||
| 70 | bool only_accelerometer = true; | ||
| 71 | }; | ||
| 72 | |||
| 73 | } // namespace InputCommon | ||