summaryrefslogtreecommitdiff
path: root/src/input_common/motion_input.h
diff options
context:
space:
mode:
authorGravatar german2020-08-23 19:26:47 -0500
committerGravatar german2020-08-27 17:19:21 -0500
commit2d207ec609d1280bbfcdb822cceb8adc42afac3a (patch)
tree2990f7f63b3f6847636c85d6e00aac323f6856de /src/input_common/motion_input.h
parentMerge pull request #4530 from Morph1984/mjolnir-p1 (diff)
downloadyuzu-2d207ec609d1280bbfcdb822cceb8adc42afac3a.tar.gz
yuzu-2d207ec609d1280bbfcdb822cceb8adc42afac3a.tar.xz
yuzu-2d207ec609d1280bbfcdb822cceb8adc42afac3a.zip
Implement a basic class for motion devices
Diffstat (limited to 'src/input_common/motion_input.h')
-rw-r--r--src/input_common/motion_input.h62
1 files changed, 62 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..4b8093d8c
--- /dev/null
+++ b/src/input_common/motion_input.h
@@ -0,0 +1,62 @@
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
11namespace InputCommon {
12
13class MotionInput {
14public:
15 MotionInput(f32 new_kp, f32 new_ki, f32 new_kd);
16
17 void SetAcceleration(Common::Vec3f acceleration);
18 void SetGyroscope(Common::Vec3f acceleration);
19 void SetQuaternion(Common::Quaternion<f32> quaternion);
20 void SetGyroDrift(Common::Vec3f drift);
21 void SetGyroThreshold(f32 threshold);
22
23 void EnableReset(bool reset);
24 void ResetRotations();
25
26 void UpdateRotation(u64 elapsed_time);
27 void UpdateOrientation(u64 elapsed_time);
28
29 std::array<Common::Vec3f, 3> GetOrientation();
30 Common::Vec3f GetAcceleration();
31 Common::Vec3f GetGyroscope();
32 Common::Vec3f GetRotations();
33 Common::Quaternion<f32> GetQuaternion();
34
35 bool IsMoving(f32 sensitivity);
36 bool IsCalibrated(f32 sensitivity);
37
38 // PID constants
39 const f32 kp;
40 const f32 ki;
41 const f32 kd;
42
43private:
44 void resetOrientation();
45
46 // PID errors
47 Common::Vec3f real_error;
48 Common::Vec3f integral_error;
49 Common::Vec3f derivative_error;
50
51 Common::Quaternion<f32> quat;
52 Common::Vec3f rotations;
53 Common::Vec3f accel;
54 Common::Vec3f gyro;
55 Common::Vec3f gyro_drift;
56
57 f32 gyro_threshold;
58 f32 reset_counter;
59 bool reset_enabled;
60};
61
62} // namespace InputCommon