diff options
| author | 2020-10-15 20:59:34 -0700 | |
|---|---|---|
| committer | 2020-10-15 20:59:34 -0700 | |
| 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.gz yuzu-64f967fd4958abb5a02191a81e91fc8b33bcf4c5.tar.xz yuzu-64f967fd4958abb5a02191a81e91fc8b33bcf4c5.zip | |
Merge pull request #4790 from lioncash/input-common
input_common/CMakeLists: Make some warnings errors
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 @@ | |||
| 8 | 8 | ||
| 9 | namespace InputCommon { | 9 | namespace InputCommon { |
| 10 | 10 | ||
| 11 | MotionInput::MotionInput(f32 new_kp, f32 new_ki, f32 new_kd) | 11 | MotionInput::MotionInput(f32 new_kp, f32 new_ki, f32 new_kd) : kp(new_kp), ki(new_ki), kd(new_kd) {} |
| 12 | : kp(new_kp), ki(new_ki), kd(new_kd), quat{{0, 0, -1}, 0} {} | ||
| 13 | 12 | ||
| 14 | void MotionInput::SetAcceleration(const Common::Vec3f& acceleration) { | 13 | void MotionInput::SetAcceleration(const Common::Vec3f& acceleration) { |
| 15 | accel = acceleration; | 14 | accel = acceleration; |
| @@ -59,7 +58,7 @@ bool MotionInput::IsCalibrated(f32 sensitivity) const { | |||
| 59 | } | 58 | } |
| 60 | 59 | ||
| 61 | void MotionInput::UpdateRotation(u64 elapsed_time) { | 60 | void MotionInput::UpdateRotation(u64 elapsed_time) { |
| 62 | const f32 sample_period = elapsed_time / 1000000.0f; | 61 | const auto sample_period = static_cast<f32>(elapsed_time) / 1000000.0f; |
| 63 | if (sample_period > 0.1f) { | 62 | if (sample_period > 0.1f) { |
| 64 | return; | 63 | return; |
| 65 | } | 64 | } |
| @@ -75,7 +74,7 @@ void MotionInput::UpdateOrientation(u64 elapsed_time) { | |||
| 75 | f32 q2 = quat.xyz[0]; | 74 | f32 q2 = quat.xyz[0]; |
| 76 | f32 q3 = quat.xyz[1]; | 75 | f32 q3 = quat.xyz[1]; |
| 77 | f32 q4 = quat.xyz[2]; | 76 | f32 q4 = quat.xyz[2]; |
| 78 | const f32 sample_period = elapsed_time / 1000000.0f; | 77 | const auto sample_period = static_cast<f32>(elapsed_time) / 1000000.0f; |
| 79 | 78 | ||
| 80 | // Ignore invalid elapsed time | 79 | // Ignore invalid elapsed time |
| 81 | if (sample_period > 0.1f) { | 80 | if (sample_period > 0.1f) { |
| @@ -203,21 +202,21 @@ Input::MotionStatus MotionInput::GetRandomMotion(int accel_magnitude, int gyro_m | |||
| 203 | std::random_device device; | 202 | std::random_device device; |
| 204 | std::mt19937 gen(device()); | 203 | std::mt19937 gen(device()); |
| 205 | std::uniform_int_distribution<s16> distribution(-1000, 1000); | 204 | std::uniform_int_distribution<s16> distribution(-1000, 1000); |
| 206 | const Common::Vec3f gyroscope = { | 205 | const Common::Vec3f gyroscope{ |
| 207 | distribution(gen) * 0.001f, | 206 | static_cast<f32>(distribution(gen)) * 0.001f, |
| 208 | distribution(gen) * 0.001f, | 207 | static_cast<f32>(distribution(gen)) * 0.001f, |
| 209 | distribution(gen) * 0.001f, | 208 | static_cast<f32>(distribution(gen)) * 0.001f, |
| 210 | }; | 209 | }; |
| 211 | const Common::Vec3f accelerometer = { | 210 | const Common::Vec3f accelerometer{ |
| 212 | distribution(gen) * 0.001f, | 211 | static_cast<f32>(distribution(gen)) * 0.001f, |
| 213 | distribution(gen) * 0.001f, | 212 | static_cast<f32>(distribution(gen)) * 0.001f, |
| 214 | distribution(gen) * 0.001f, | 213 | static_cast<f32>(distribution(gen)) * 0.001f, |
| 215 | }; | 214 | }; |
| 216 | const Common::Vec3f rotation = {}; | 215 | constexpr Common::Vec3f rotation; |
| 217 | const std::array<Common::Vec3f, 3> orientation = { | 216 | constexpr std::array orientation{ |
| 218 | Common::Vec3f{1.0f, 0, 0}, | 217 | Common::Vec3f{1.0f, 0.0f, 0.0f}, |
| 219 | Common::Vec3f{0, 1.0f, 0}, | 218 | Common::Vec3f{0.0f, 1.0f, 0.0f}, |
| 220 | Common::Vec3f{0, 0, 1.0f}, | 219 | Common::Vec3f{0.0f, 0.0f, 1.0f}, |
| 221 | }; | 220 | }; |
| 222 | return {accelerometer * accel_magnitude, gyroscope * gyro_magnitude, rotation, orientation}; | 221 | return {accelerometer * accel_magnitude, gyroscope * gyro_magnitude, rotation, orientation}; |
| 223 | } | 222 | } |
| @@ -247,9 +246,6 @@ void MotionInput::SetOrientationFromAccelerometer() { | |||
| 247 | const f32 sample_period = 0.015f; | 246 | const f32 sample_period = 0.015f; |
| 248 | 247 | ||
| 249 | const auto normal_accel = accel.Normalized(); | 248 | const auto normal_accel = accel.Normalized(); |
| 250 | const f32 ax = -normal_accel.x; | ||
| 251 | const f32 ay = normal_accel.y; | ||
| 252 | const f32 az = -normal_accel.z; | ||
| 253 | 249 | ||
| 254 | while (!IsCalibrated(0.01f) && ++iterations < 100) { | 250 | while (!IsCalibrated(0.01f) && ++iterations < 100) { |
| 255 | // Short name local variable for readability | 251 | // Short name local variable for readability |
| @@ -258,7 +254,7 @@ void MotionInput::SetOrientationFromAccelerometer() { | |||
| 258 | f32 q3 = quat.xyz[1]; | 254 | f32 q3 = quat.xyz[1]; |
| 259 | f32 q4 = quat.xyz[2]; | 255 | f32 q4 = quat.xyz[2]; |
| 260 | 256 | ||
| 261 | Common::Vec3f rad_gyro = {}; | 257 | Common::Vec3f rad_gyro; |
| 262 | const f32 ax = -normal_accel.x; | 258 | const f32 ax = -normal_accel.x; |
| 263 | const f32 ay = normal_accel.y; | 259 | const f32 ay = normal_accel.y; |
| 264 | const f32 az = -normal_accel.z; | 260 | const f32 az = -normal_accel.z; |