diff options
author | bunnei <bunneidev@gmail.com> | 2020-10-16 05:59:34 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-10-16 05:59:34 +0200 |
commit | 64f967fd4958abb5a02191a81e91fc8b33bcf4c5 (patch) | |
tree | 97a73da4871f006b39eafca3a881ae2ea42f206a /src/input_common/motion_input.cpp | |
parent | Merge pull request #4784 from bunnei/cancelbuffer (diff) | |
parent | input_common/CMakeLists: Make some warnings errors (diff) | |
download | yuzu-64f967fd4958abb5a02191a81e91fc8b33bcf4c5.tar yuzu-64f967fd4958abb5a02191a81e91fc8b33bcf4c5.tar.gz yuzu-64f967fd4958abb5a02191a81e91fc8b33bcf4c5.tar.bz2 yuzu-64f967fd4958abb5a02191a81e91fc8b33bcf4c5.tar.lz yuzu-64f967fd4958abb5a02191a81e91fc8b33bcf4c5.tar.xz yuzu-64f967fd4958abb5a02191a81e91fc8b33bcf4c5.tar.zst yuzu-64f967fd4958abb5a02191a81e91fc8b33bcf4c5.zip |
Diffstat (limited to 'src/input_common/motion_input.cpp')
-rw-r--r-- | src/input_common/motion_input.cpp | 38 |
1 files changed, 17 insertions, 21 deletions
diff --git a/src/input_common/motion_input.cpp b/src/input_common/motion_input.cpp index e89019723..f77ba535d 100644 --- a/src/input_common/motion_input.cpp +++ b/src/input_common/motion_input.cpp @@ -8,8 +8,7 @@ namespace InputCommon { -MotionInput::MotionInput(f32 new_kp, f32 new_ki, f32 new_kd) - : kp(new_kp), ki(new_ki), kd(new_kd), quat{{0, 0, -1}, 0} {} +MotionInput::MotionInput(f32 new_kp, f32 new_ki, f32 new_kd) : kp(new_kp), ki(new_ki), kd(new_kd) {} void MotionInput::SetAcceleration(const Common::Vec3f& acceleration) { accel = acceleration; @@ -59,7 +58,7 @@ bool MotionInput::IsCalibrated(f32 sensitivity) const { } void MotionInput::UpdateRotation(u64 elapsed_time) { - const f32 sample_period = elapsed_time / 1000000.0f; + const auto sample_period = static_cast<f32>(elapsed_time) / 1000000.0f; if (sample_period > 0.1f) { return; } @@ -75,7 +74,7 @@ void MotionInput::UpdateOrientation(u64 elapsed_time) { f32 q2 = quat.xyz[0]; f32 q3 = quat.xyz[1]; f32 q4 = quat.xyz[2]; - const f32 sample_period = elapsed_time / 1000000.0f; + const auto sample_period = static_cast<f32>(elapsed_time) / 1000000.0f; // Ignore invalid elapsed time if (sample_period > 0.1f) { @@ -203,21 +202,21 @@ Input::MotionStatus MotionInput::GetRandomMotion(int accel_magnitude, int gyro_m std::random_device device; std::mt19937 gen(device()); std::uniform_int_distribution<s16> distribution(-1000, 1000); - const Common::Vec3f gyroscope = { - distribution(gen) * 0.001f, - distribution(gen) * 0.001f, - distribution(gen) * 0.001f, + const Common::Vec3f gyroscope{ + static_cast<f32>(distribution(gen)) * 0.001f, + static_cast<f32>(distribution(gen)) * 0.001f, + static_cast<f32>(distribution(gen)) * 0.001f, }; - const Common::Vec3f accelerometer = { - distribution(gen) * 0.001f, - distribution(gen) * 0.001f, - distribution(gen) * 0.001f, + const Common::Vec3f accelerometer{ + static_cast<f32>(distribution(gen)) * 0.001f, + static_cast<f32>(distribution(gen)) * 0.001f, + static_cast<f32>(distribution(gen)) * 0.001f, }; - const Common::Vec3f rotation = {}; - const std::array<Common::Vec3f, 3> orientation = { - Common::Vec3f{1.0f, 0, 0}, - Common::Vec3f{0, 1.0f, 0}, - Common::Vec3f{0, 0, 1.0f}, + constexpr Common::Vec3f rotation; + constexpr std::array orientation{ + Common::Vec3f{1.0f, 0.0f, 0.0f}, + Common::Vec3f{0.0f, 1.0f, 0.0f}, + Common::Vec3f{0.0f, 0.0f, 1.0f}, }; return {accelerometer * accel_magnitude, gyroscope * gyro_magnitude, rotation, orientation}; } @@ -247,9 +246,6 @@ void MotionInput::SetOrientationFromAccelerometer() { const f32 sample_period = 0.015f; const auto normal_accel = accel.Normalized(); - const f32 ax = -normal_accel.x; - const f32 ay = normal_accel.y; - const f32 az = -normal_accel.z; while (!IsCalibrated(0.01f) && ++iterations < 100) { // Short name local variable for readability @@ -258,7 +254,7 @@ void MotionInput::SetOrientationFromAccelerometer() { f32 q3 = quat.xyz[1]; f32 q4 = quat.xyz[2]; - Common::Vec3f rad_gyro = {}; + Common::Vec3f rad_gyro; const f32 ax = -normal_accel.x; const f32 ay = normal_accel.y; const f32 az = -normal_accel.z; |