From a54aee290ff8f94d1fefc70121512dbc46f6c190 Mon Sep 17 00:00:00 2001 From: german Date: Sun, 4 Oct 2020 18:15:53 -0500 Subject: [PATCH] Address comments --- src/input_common/motion_input.cpp | 76 +++++++++++++++---------------- src/input_common/motion_input.h | 4 +- 2 files changed, 40 insertions(+), 40 deletions(-) diff --git a/src/input_common/motion_input.cpp b/src/input_common/motion_input.cpp index d3e7360448..182a2869a0 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 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 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 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 f6c1fece7e..c90ee64e5b 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 GetOrientation() const; Common::Vec3f GetAcceleration() const;