diff options
author | bunnei <bunneidev@gmail.com> | 2020-09-02 11:09:18 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-09-02 11:09:18 -0400 |
commit | f64917a85222bc98cd6363a6d97b9ccb5bd54a09 (patch) | |
tree | 24fa5a10cca1d88f97ff49b7372dfe03956c5f70 /src/input_common/motion_input.h | |
parent | e11a77d2c6162e53dea11bd70fb74bb3a0b23a04 (diff) | |
parent | 1be18dc110e1c7193930c62542855c91179d179b (diff) |
Merge pull request #4570 from german77/motionInput
input_common: Add a basic class for motion devices
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 @@ +// 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); + + MotionInput(const MotionInput&) = default; + MotionInput& operator=(const MotionInput&) = default; + + MotionInput(MotionInput&&) = default; + MotionInput& operator=(MotionInput&&) = default; + + void SetAcceleration(const Common::Vec3f& acceleration); + void SetGyroscope(const Common::Vec3f& acceleration); + void SetQuaternion(const Common::Quaternion<f32>& quaternion); + void SetGyroDrift(const 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() const; + Common::Vec3f GetAcceleration() const; + Common::Vec3f GetGyroscope() const; + Common::Vec3f GetRotations() const; + Common::Quaternion<f32> GetQuaternion() const; + + bool IsMoving(f32 sensitivity) const; + bool IsCalibrated(f32 sensitivity) const; + +private: + void ResetOrientation(); + + // PID constants + const f32 kp; + const f32 ki; + const f32 kd; + + // 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 = 0.0f; + u32 reset_counter = 0; + bool reset_enabled = true; +}; + +} // namespace InputCommon |