diff options
Diffstat (limited to 'src/input_common/motion_input.h')
| -rw-r--r-- | src/input_common/motion_input.h | 68 |
1 files changed, 68 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..445798a54 --- /dev/null +++ b/src/input_common/motion_input.h | |||
| @@ -0,0 +1,68 @@ | |||
| 1 | // Copyright 2014 Dolphin Emulator Project | ||
| 2 | // Licensed under GPLv2+ | ||
| 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 InputCommon { | ||
| 12 | |||
| 13 | class MotionInput { | ||
| 14 | public: | ||
| 15 | MotionInput(f32 new_kp, f32 new_ki, f32 new_kd); | ||
| 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 SetAcceleration(const Common::Vec3f& acceleration); | ||
| 24 | void SetGyroscope(const Common::Vec3f& acceleration); | ||
| 25 | void SetQuaternion(const Common::Quaternion<f32>& quaternion); | ||
| 26 | void SetGyroDrift(const Common::Vec3f& drift); | ||
| 27 | void SetGyroThreshold(f32 threshold); | ||
| 28 | |||
| 29 | void EnableReset(bool reset); | ||
| 30 | void ResetRotations(); | ||
| 31 | |||
| 32 | void UpdateRotation(u64 elapsed_time); | ||
| 33 | void UpdateOrientation(u64 elapsed_time); | ||
| 34 | |||
| 35 | std::array<Common::Vec3f, 3> GetOrientation() const; | ||
| 36 | Common::Vec3f GetAcceleration() const; | ||
| 37 | Common::Vec3f GetGyroscope() const; | ||
| 38 | Common::Vec3f GetRotations() const; | ||
| 39 | Common::Quaternion<f32> GetQuaternion() const; | ||
| 40 | |||
| 41 | bool IsMoving(f32 sensitivity) const; | ||
| 42 | bool IsCalibrated(f32 sensitivity) const; | ||
| 43 | |||
| 44 | private: | ||
| 45 | void ResetOrientation(); | ||
| 46 | |||
| 47 | // PID constants | ||
| 48 | const f32 kp; | ||
| 49 | const f32 ki; | ||
| 50 | const f32 kd; | ||
| 51 | |||
| 52 | // PID errors | ||
| 53 | Common::Vec3f real_error; | ||
| 54 | Common::Vec3f integral_error; | ||
| 55 | Common::Vec3f derivative_error; | ||
| 56 | |||
| 57 | Common::Quaternion<f32> quat; | ||
| 58 | Common::Vec3f rotations; | ||
| 59 | Common::Vec3f accel; | ||
| 60 | Common::Vec3f gyro; | ||
| 61 | Common::Vec3f gyro_drift; | ||
| 62 | |||
| 63 | f32 gyro_threshold = 0.0f; | ||
| 64 | u32 reset_counter = 0; | ||
| 65 | bool reset_enabled = true; | ||
| 66 | }; | ||
| 67 | |||
| 68 | } // namespace InputCommon | ||