diff options
Diffstat (limited to 'src/input_common/motion_input.h')
| -rw-r--r-- | src/input_common/motion_input.h | 32 |
1 files changed, 19 insertions, 13 deletions
diff --git a/src/input_common/motion_input.h b/src/input_common/motion_input.h index 54b4439d9..efe74cf19 100644 --- a/src/input_common/motion_input.h +++ b/src/input_common/motion_input.h | |||
| @@ -7,12 +7,13 @@ | |||
| 7 | #include "common/common_types.h" | 7 | #include "common/common_types.h" |
| 8 | #include "common/quaternion.h" | 8 | #include "common/quaternion.h" |
| 9 | #include "common/vector_math.h" | 9 | #include "common/vector_math.h" |
| 10 | #include "core/frontend/input.h" | ||
| 10 | 11 | ||
| 11 | namespace InputCommon { | 12 | namespace InputCommon { |
| 12 | 13 | ||
| 13 | class MotionInput { | 14 | class MotionInput { |
| 14 | public: | 15 | public: |
| 15 | MotionInput(f32 new_kp, f32 new_ki, f32 new_kd); | 16 | explicit MotionInput(f32 new_kp, f32 new_ki, f32 new_kd); |
| 16 | 17 | ||
| 17 | MotionInput(const MotionInput&) = default; | 18 | MotionInput(const MotionInput&) = default; |
| 18 | MotionInput& operator=(const MotionInput&) = default; | 19 | MotionInput& operator=(const MotionInput&) = default; |
| @@ -21,7 +22,7 @@ public: | |||
| 21 | MotionInput& operator=(MotionInput&&) = default; | 22 | MotionInput& operator=(MotionInput&&) = default; |
| 22 | 23 | ||
| 23 | void SetAcceleration(const Common::Vec3f& acceleration); | 24 | void SetAcceleration(const Common::Vec3f& acceleration); |
| 24 | void SetGyroscope(const Common::Vec3f& acceleration); | 25 | void SetGyroscope(const Common::Vec3f& gyroscope); |
| 25 | void SetQuaternion(const Common::Quaternion<f32>& quaternion); | 26 | void SetQuaternion(const Common::Quaternion<f32>& quaternion); |
| 26 | void SetGyroDrift(const Common::Vec3f& drift); | 27 | void SetGyroDrift(const Common::Vec3f& drift); |
| 27 | void SetGyroThreshold(f32 threshold); | 28 | void SetGyroThreshold(f32 threshold); |
| @@ -32,29 +33,33 @@ public: | |||
| 32 | void UpdateRotation(u64 elapsed_time); | 33 | void UpdateRotation(u64 elapsed_time); |
| 33 | void UpdateOrientation(u64 elapsed_time); | 34 | void UpdateOrientation(u64 elapsed_time); |
| 34 | 35 | ||
| 35 | std::array<Common::Vec3f, 3> GetOrientation() const; | 36 | [[nodiscard]] std::array<Common::Vec3f, 3> GetOrientation() const; |
| 36 | Common::Vec3f GetAcceleration() const; | 37 | [[nodiscard]] Common::Vec3f GetAcceleration() const; |
| 37 | Common::Vec3f GetGyroscope() const; | 38 | [[nodiscard]] Common::Vec3f GetGyroscope() const; |
| 38 | Common::Vec3f GetRotations() const; | 39 | [[nodiscard]] Common::Vec3f GetRotations() const; |
| 39 | Common::Quaternion<f32> GetQuaternion() const; | 40 | [[nodiscard]] Common::Quaternion<f32> GetQuaternion() const; |
| 41 | [[nodiscard]] Input::MotionStatus GetMotion() const; | ||
| 42 | [[nodiscard]] Input::MotionStatus GetRandomMotion(int accel_magnitude, | ||
| 43 | int gyro_magnitude) const; | ||
| 40 | 44 | ||
| 41 | bool IsMoving(f32 sensitivity) const; | 45 | [[nodiscard]] bool IsMoving(f32 sensitivity) const; |
| 42 | bool IsCalibrated(f32 sensitivity) const; | 46 | [[nodiscard]] bool IsCalibrated(f32 sensitivity) const; |
| 43 | 47 | ||
| 44 | private: | 48 | private: |
| 45 | void ResetOrientation(); | 49 | void ResetOrientation(); |
| 50 | void SetOrientationFromAccelerometer(); | ||
| 46 | 51 | ||
| 47 | // PID constants | 52 | // PID constants |
| 48 | const f32 kp; | 53 | f32 kp; |
| 49 | const f32 ki; | 54 | f32 ki; |
| 50 | const f32 kd; | 55 | f32 kd; |
| 51 | 56 | ||
| 52 | // PID errors | 57 | // PID errors |
| 53 | Common::Vec3f real_error; | 58 | Common::Vec3f real_error; |
| 54 | Common::Vec3f integral_error; | 59 | Common::Vec3f integral_error; |
| 55 | Common::Vec3f derivative_error; | 60 | Common::Vec3f derivative_error; |
| 56 | 61 | ||
| 57 | Common::Quaternion<f32> quat; | 62 | Common::Quaternion<f32> quat{{0.0f, 0.0f, -1.0f}, 0.0f}; |
| 58 | Common::Vec3f rotations; | 63 | Common::Vec3f rotations; |
| 59 | Common::Vec3f accel; | 64 | Common::Vec3f accel; |
| 60 | Common::Vec3f gyro; | 65 | Common::Vec3f gyro; |
| @@ -63,6 +68,7 @@ private: | |||
| 63 | f32 gyro_threshold = 0.0f; | 68 | f32 gyro_threshold = 0.0f; |
| 64 | u32 reset_counter = 0; | 69 | u32 reset_counter = 0; |
| 65 | bool reset_enabled = true; | 70 | bool reset_enabled = true; |
| 71 | bool only_accelerometer = true; | ||
| 66 | }; | 72 | }; |
| 67 | 73 | ||
| 68 | } // namespace InputCommon | 74 | } // namespace InputCommon |