diff options
author | german77 <juangerman-13@hotmail.com> | 2021-09-20 23:29:43 +0200 |
---|---|---|
committer | Narr the Reg <juangerman-13@hotmail.com> | 2021-11-25 03:30:22 +0100 |
commit | 449576df93f6beb70cff0e009ccb2dd8bce1e085 (patch) | |
tree | fae04e0d292da6128a074cbe046de6169019774c /src/core/hid/motion_input.h | |
parent | core/hid: Move input_interpreter to hid (diff) | |
download | yuzu-449576df93f6beb70cff0e009ccb2dd8bce1e085.tar yuzu-449576df93f6beb70cff0e009ccb2dd8bce1e085.tar.gz yuzu-449576df93f6beb70cff0e009ccb2dd8bce1e085.tar.bz2 yuzu-449576df93f6beb70cff0e009ccb2dd8bce1e085.tar.lz yuzu-449576df93f6beb70cff0e009ccb2dd8bce1e085.tar.xz yuzu-449576df93f6beb70cff0e009ccb2dd8bce1e085.tar.zst yuzu-449576df93f6beb70cff0e009ccb2dd8bce1e085.zip |
Diffstat (limited to '')
-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 @@ +// Copyright 2020 yuzu Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included + +#pragma once + +#include "common/common_types.h" +#include "common/quaternion.h" +#include "common/vector_math.h" + +namespace Core::HID { + +class MotionInput { +public: + explicit MotionInput(); + + MotionInput(const MotionInput&) = default; + MotionInput& operator=(const MotionInput&) = default; + + MotionInput(MotionInput&&) = default; + MotionInput& operator=(MotionInput&&) = default; + + void SetPID(f32 new_kp, f32 new_ki, f32 new_kd); + void SetAcceleration(const Common::Vec3f& acceleration); + void SetGyroscope(const Common::Vec3f& gyroscope); + 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); + + [[nodiscard]] std::array<Common::Vec3f, 3> GetOrientation() const; + [[nodiscard]] Common::Vec3f GetAcceleration() const; + [[nodiscard]] Common::Vec3f GetGyroscope() const; + [[nodiscard]] Common::Vec3f GetRotations() const; + [[nodiscard]] Common::Quaternion<f32> GetQuaternion() const; + + [[nodiscard]] bool IsMoving(f32 sensitivity) const; + [[nodiscard]] bool IsCalibrated(f32 sensitivity) const; + +private: + void ResetOrientation(); + void SetOrientationFromAccelerometer(); + + // PID constants + f32 kp; + f32 ki; + f32 kd; + + // PID errors + Common::Vec3f real_error; + Common::Vec3f integral_error; + Common::Vec3f derivative_error; + + Common::Quaternion<f32> quat{{0.0f, 0.0f, -1.0f}, 0.0f}; + 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; + bool only_accelerometer = true; +}; + +} // namespace Core::HID |