diff options
| author | Jordan Woyak <jordan.woyak@gmail.com> | 2020-10-18 15:16:08 -0500 |
|---|---|---|
| committer | Jordan Woyak <jordan.woyak@gmail.com> | 2020-12-14 20:02:49 -0600 |
| commit | 4bb0a885d0e61b069f4129f8358dcbe3a4db34b1 (patch) | |
| tree | a9a02c37089a76d88288a2de821dff2899cdecf5 /Source/Core/DolphinQt/Config/Mapping/MappingIndicator.cpp | |
| parent | fffd005178a59877a0072be6c1f4ed50f1e888a7 (diff) | |
WiimoteEmu/DolphinQt: Fix tilt indicator for wrapped around angles.
Diffstat (limited to 'Source/Core/DolphinQt/Config/Mapping/MappingIndicator.cpp')
| -rw-r--r-- | Source/Core/DolphinQt/Config/Mapping/MappingIndicator.cpp | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/Source/Core/DolphinQt/Config/Mapping/MappingIndicator.cpp b/Source/Core/DolphinQt/Config/Mapping/MappingIndicator.cpp index fa47c36630..b44c8c803e 100644 --- a/Source/Core/DolphinQt/Config/Mapping/MappingIndicator.cpp +++ b/Source/Core/DolphinQt/Config/Mapping/MappingIndicator.cpp @@ -415,8 +415,18 @@ void TiltIndicator::Draw() { WiimoteEmu::EmulateTilt(&m_motion_state, &m_group, 1.f / INDICATOR_UPDATE_FREQ); - const auto adj_coord = - Common::DVec2{-m_motion_state.angle.y, m_motion_state.angle.x} / MathUtil::PI; + auto adj_coord = Common::DVec2{-m_motion_state.angle.y, m_motion_state.angle.x} / MathUtil::PI; + + // Angle values after dividing by pi. + constexpr auto norm_180_deg = 1; + constexpr auto norm_360_deg = 2; + + // Angle may extend beyond 180 degrees when wrapping around. + // Apply modulo to draw within the indicator. + // Scale down the value a bit so +1 does not become -1. + adj_coord *= 0.9999f; + adj_coord.x = std::fmod(adj_coord.x + norm_360_deg + norm_180_deg, norm_360_deg) - norm_180_deg; + adj_coord.y = std::fmod(adj_coord.y + norm_360_deg + norm_180_deg, norm_360_deg) - norm_180_deg; DrawReshapableInput(m_group, TILT_GATE_COLOR, (adj_coord.x || adj_coord.y) ? std::make_optional(adj_coord) : std::nullopt); |
