From a2626365908ded901fa5aef9ecf4d3dacbd03f47 Mon Sep 17 00:00:00 2001 From: binary1248 Date: Sun, 29 Nov 2020 13:39:33 +0100 Subject: [PATCH] Fixed joystick POV values not being set properly for devices that are accessed via DirectInput. --- src/SFML/Window/Win32/JoystickImpl.cpp | 46 ++++++-------------------- 1 file changed, 10 insertions(+), 36 deletions(-) diff --git a/src/SFML/Window/Win32/JoystickImpl.cpp b/src/SFML/Window/Win32/JoystickImpl.cpp index 49f85da3a..ab22446b1 100644 --- a/src/SFML/Window/Win32/JoystickImpl.cpp +++ b/src/SFML/Window/Win32/JoystickImpl.cpp @@ -907,7 +907,7 @@ JoystickState JoystickImpl::updateDInputBuffered() { if (m_axes[j] == events[i].dwOfs) { - if (j == Joystick::PovX) + if ((j == Joystick::PovX) || (j == Joystick::PovY)) { unsigned short value = LOWORD(events[i].dwData); @@ -915,26 +915,13 @@ JoystickState JoystickImpl::updateDInputBuffered() { float angle = (static_cast(value)) * 3.141592654f / DI_DEGREES / 180.f; - m_state.axes[j] = std::sin(angle) * 100.f; + m_state.axes[Joystick::PovX] = std::sin(angle) * 100.f; + m_state.axes[Joystick::PovY] = std::cos(angle) * 100.f; } else { - m_state.axes[j] = 0; - } - } - else if (j == Joystick::PovY) - { - unsigned short value = LOWORD(events[i].dwData); - - if (value != 0xFFFF) - { - float angle = (static_cast(value)) * 3.141592654f / DI_DEGREES / 180.f; - - m_state.axes[j] = std::cos(angle) * 100.f; - } - else - { - m_state.axes[j] = 0.f; + m_state.axes[Joystick::PovX] = 0.f; + m_state.axes[Joystick::PovY] = 0.f; } } else @@ -1009,7 +996,7 @@ JoystickState JoystickImpl::updateDInputPolled() { if (m_axes[i] != -1) { - if (i == Joystick::PovX) + if ((i == Joystick::PovX) || (i == Joystick::PovY)) { unsigned short value = LOWORD(*reinterpret_cast(reinterpret_cast(&joystate) + m_axes[i])); @@ -1017,26 +1004,13 @@ JoystickState JoystickImpl::updateDInputPolled() { float angle = (static_cast(value)) * 3.141592654f / DI_DEGREES / 180.f; - state.axes[i] = std::sin(angle) * 100.f; + state.axes[Joystick::PovX] = std::sin(angle) * 100.f; + state.axes[Joystick::PovY] = std::cos(angle) * 100.f; } else { - state.axes[i] = 0; - } - } - else if (i == Joystick::PovY) - { - unsigned short value = LOWORD(*reinterpret_cast(reinterpret_cast(&joystate) + m_axes[i])); - - if (value != 0xFFFF) - { - float angle = (static_cast(value)) * 3.141592654f / DI_DEGREES / 180.f; - - state.axes[i] = std::cos(angle) * 100.f; - } - else - { - state.axes[i] = 0.f; + state.axes[Joystick::PovX] = 0.f; + state.axes[Joystick::PovY] = 0.f; } } else