summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorgerman <german@thesoftwareartisans.com>2020-10-05 01:15:53 +0200
committergerman <german@thesoftwareartisans.com>2020-10-05 01:15:53 +0200
commita54aee290ff8f94d1fefc70121512dbc46f6c190 (patch)
tree0665dffce32f00c2267f5f55a5353c9da648192f
parentAdd compatibility with only accelerometer and auto calibrate for drift (diff)
downloadyuzu-a54aee290ff8f94d1fefc70121512dbc46f6c190.tar
yuzu-a54aee290ff8f94d1fefc70121512dbc46f6c190.tar.gz
yuzu-a54aee290ff8f94d1fefc70121512dbc46f6c190.tar.bz2
yuzu-a54aee290ff8f94d1fefc70121512dbc46f6c190.tar.lz
yuzu-a54aee290ff8f94d1fefc70121512dbc46f6c190.tar.xz
yuzu-a54aee290ff8f94d1fefc70121512dbc46f6c190.tar.zst
yuzu-a54aee290ff8f94d1fefc70121512dbc46f6c190.zip
-rw-r--r--src/input_common/motion_input.cpp76
-rw-r--r--src/input_common/motion_input.h4
2 files changed, 40 insertions, 40 deletions
diff --git a/src/input_common/motion_input.cpp b/src/input_common/motion_input.cpp
index d3e736044..182a2869a 100644
--- a/src/input_common/motion_input.cpp
+++ b/src/input_common/motion_input.cpp
@@ -57,7 +57,7 @@ bool MotionInput::IsCalibrated(f32 sensitivity) const {
return real_error.Length() < sensitivity;
}
-void MotionInput::UpdateRotation(const u64 elapsed_time) {
+void MotionInput::UpdateRotation(u64 elapsed_time) {
const f32 sample_period = elapsed_time / 1000000.0f;
if (sample_period > 0.1f) {
return;
@@ -65,7 +65,7 @@ void MotionInput::UpdateRotation(const u64 elapsed_time) {
rotations += gyro * sample_period;
}
-void MotionInput::UpdateOrientation(const u64 elapsed_time) {
+void MotionInput::UpdateOrientation(u64 elapsed_time) {
if (!IsCalibrated(0.1f)) {
ResetOrientation();
}
@@ -174,6 +174,42 @@ std::array<Common::Vec3f, 3> MotionInput::GetOrientation() const {
Common::Vec3f(-matrix4x4[8], -matrix4x4[9], matrix4x4[10])};
}
+Common::Vec3f MotionInput::GetAcceleration() const {
+ return accel;
+}
+
+Common::Vec3f MotionInput::GetGyroscope() const {
+ return gyro;
+}
+
+Common::Quaternion<f32> MotionInput::GetQuaternion() const {
+ return quat;
+}
+
+Common::Vec3f MotionInput::GetRotations() const {
+ return rotations;
+}
+
+void MotionInput::ResetOrientation() {
+ if (!reset_enabled || only_accelerometer) {
+ return;
+ }
+ if (!IsMoving(0.5f) && accel.z <= -0.9f) {
+ ++reset_counter;
+ if (reset_counter > 900) {
+ quat.w = 0;
+ quat.xyz[0] = 0;
+ quat.xyz[1] = 0;
+ quat.xyz[2] = -1;
+ SetOrientationFromAccelerometer();
+ integral_error = {};
+ reset_counter = 0;
+ }
+ } else {
+ reset_counter = 0;
+ }
+}
+
void MotionInput::SetOrientationFromAccelerometer() {
int iterations = 0;
const f32 sample_period = 0.015f;
@@ -234,40 +270,4 @@ void MotionInput::SetOrientationFromAccelerometer() {
quat = quat.Normalized();
}
}
-
-Common::Vec3f MotionInput::GetAcceleration() const {
- return accel;
-}
-
-Common::Vec3f MotionInput::GetGyroscope() const {
- return gyro;
-}
-
-Common::Quaternion<f32> MotionInput::GetQuaternion() const {
- return quat;
-}
-
-Common::Vec3f MotionInput::GetRotations() const {
- return rotations;
-}
-
-void MotionInput::ResetOrientation() {
- if (!reset_enabled || only_accelerometer) {
- return;
- }
- if (!IsMoving(0.5f) && accel.z <= -0.9f) {
- ++reset_counter;
- if (reset_counter > 900) {
- quat.w = 0;
- quat.xyz[0] = 0;
- quat.xyz[1] = 0;
- quat.xyz[2] = -1;
- SetOrientationFromAccelerometer();
- integral_error = {};
- reset_counter = 0;
- }
- } else {
- reset_counter = 0;
- }
-}
} // namespace InputCommon
diff --git a/src/input_common/motion_input.h b/src/input_common/motion_input.h
index f6c1fece7..c90ee64e5 100644
--- a/src/input_common/motion_input.h
+++ b/src/input_common/motion_input.h
@@ -29,8 +29,8 @@ public:
void EnableReset(bool reset);
void ResetRotations();
- void UpdateRotation(const u64 elapsed_time);
- void UpdateOrientation(const u64 elapsed_time);
+ void UpdateRotation(u64 elapsed_time);
+ void UpdateOrientation(u64 elapsed_time);
std::array<Common::Vec3f, 3> GetOrientation() const;
Common::Vec3f GetAcceleration() const;