2020-09-02 16:58:15 +01:00
|
|
|
// Copyright 2020 yuzu Emulator Project
|
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included
|
2020-08-24 01:26:47 +01:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "common/common_types.h"
|
|
|
|
#include "common/quaternion.h"
|
|
|
|
#include "common/vector_math.h"
|
2020-09-18 02:26:34 +01:00
|
|
|
#include "core/frontend/input.h"
|
2020-08-24 01:26:47 +01:00
|
|
|
|
|
|
|
namespace InputCommon {
|
|
|
|
|
|
|
|
class MotionInput {
|
|
|
|
public:
|
2020-11-15 19:20:41 +00:00
|
|
|
explicit MotionInput(f32 new_kp, f32 new_ki, f32 new_kd);
|
2020-08-24 01:26:47 +01:00
|
|
|
|
2020-08-24 02:41:59 +01:00
|
|
|
MotionInput(const MotionInput&) = default;
|
|
|
|
MotionInput& operator=(const MotionInput&) = default;
|
|
|
|
|
|
|
|
MotionInput(MotionInput&&) = default;
|
|
|
|
MotionInput& operator=(MotionInput&&) = default;
|
|
|
|
|
|
|
|
void SetAcceleration(const Common::Vec3f& acceleration);
|
2020-10-14 07:51:14 +01:00
|
|
|
void SetGyroscope(const Common::Vec3f& gyroscope);
|
2020-08-24 02:41:59 +01:00
|
|
|
void SetQuaternion(const Common::Quaternion<f32>& quaternion);
|
|
|
|
void SetGyroDrift(const Common::Vec3f& drift);
|
2020-08-24 01:26:47 +01:00
|
|
|
void SetGyroThreshold(f32 threshold);
|
|
|
|
|
|
|
|
void EnableReset(bool reset);
|
|
|
|
void ResetRotations();
|
|
|
|
|
|
|
|
void UpdateRotation(u64 elapsed_time);
|
|
|
|
void UpdateOrientation(u64 elapsed_time);
|
|
|
|
|
2020-11-15 19:18:09 +00:00
|
|
|
[[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]] Input::MotionStatus GetMotion() const;
|
|
|
|
[[nodiscard]] Input::MotionStatus GetRandomMotion(int accel_magnitude,
|
|
|
|
int gyro_magnitude) const;
|
|
|
|
|
|
|
|
[[nodiscard]] bool IsMoving(f32 sensitivity) const;
|
|
|
|
[[nodiscard]] bool IsCalibrated(f32 sensitivity) const;
|
2020-08-24 01:26:47 +01:00
|
|
|
|
2020-08-24 02:41:59 +01:00
|
|
|
private:
|
|
|
|
void ResetOrientation();
|
2020-10-04 04:22:01 +01:00
|
|
|
void SetOrientationFromAccelerometer();
|
2020-08-24 01:26:47 +01:00
|
|
|
|
|
|
|
// PID constants
|
2020-10-14 07:51:14 +01:00
|
|
|
f32 kp;
|
|
|
|
f32 ki;
|
|
|
|
f32 kd;
|
2020-08-24 01:26:47 +01:00
|
|
|
|
|
|
|
// PID errors
|
|
|
|
Common::Vec3f real_error;
|
|
|
|
Common::Vec3f integral_error;
|
|
|
|
Common::Vec3f derivative_error;
|
|
|
|
|
2020-10-14 07:51:14 +01:00
|
|
|
Common::Quaternion<f32> quat{{0.0f, 0.0f, -1.0f}, 0.0f};
|
2020-08-24 01:26:47 +01:00
|
|
|
Common::Vec3f rotations;
|
|
|
|
Common::Vec3f accel;
|
|
|
|
Common::Vec3f gyro;
|
|
|
|
Common::Vec3f gyro_drift;
|
|
|
|
|
2020-08-24 02:41:59 +01:00
|
|
|
f32 gyro_threshold = 0.0f;
|
2020-08-26 22:49:24 +01:00
|
|
|
u32 reset_counter = 0;
|
2020-08-24 02:41:59 +01:00
|
|
|
bool reset_enabled = true;
|
2020-10-04 04:22:01 +01:00
|
|
|
bool only_accelerometer = true;
|
2020-08-24 01:26:47 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace InputCommon
|