From 5eaec85d87ce5a8f820cfa1ac00d58752dc89bce Mon Sep 17 00:00:00 2001 From: LaurentGom Date: Wed, 6 Jan 2010 08:51:25 +0000 Subject: [PATCH] Added a special value of -1 for centered joystick POV position git-svn-id: https://sfml.svn.sourceforge.net/svnroot/sfml/trunk@1329 4e206d99-4929-0410-ac5d-dfc041789085 --- src/SFML/Window/Joystick.hpp | 12 ++++++++++++ src/SFML/Window/Linux/Joystick.cpp | 2 +- src/SFML/Window/Win32/Joystick.cpp | 5 ++++- 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/SFML/Window/Joystick.hpp b/src/SFML/Window/Joystick.hpp index 33e684e1..6dd1b6e2 100644 --- a/src/SFML/Window/Joystick.hpp +++ b/src/SFML/Window/Joystick.hpp @@ -41,6 +41,18 @@ namespace priv //////////////////////////////////////////////////////////// struct JoystickState { + JoystickState() + { + // Default value for axes + for (int i = 0; i < Joy::AxisCount; ++i) + Axis[i] = 0.f; + Axis[Joy::AxisPOV] = -1.f; + + // Default value for buttons + for (int i = 0; i < Joy::ButtonCount; ++i) + Buttons[i] = false; + } + float Axis[Joy::AxisCount]; ///< Position on each axis in range [-100, 100] (except POV which is [0, 360]) bool Buttons[Joy::ButtonCount]; ///< Status of each button (true = pressed) }; diff --git a/src/SFML/Window/Linux/Joystick.cpp b/src/SFML/Window/Linux/Joystick.cpp index b14a292b..e8267d48 100644 --- a/src/SFML/Window/Linux/Joystick.cpp +++ b/src/SFML/Window/Linux/Joystick.cpp @@ -145,7 +145,7 @@ JoystickState Joystick::UpdateState() { if (myPovY == 1) myState.Axis[Joy::AxisPOV] = 270.f; else if (myPovY == -1) myState.Axis[Joy::AxisPOV] = 90.f; - else myState.Axis[Joy::AxisPOV] = 0.f; // what is it supposed to be?? + else myState.Axis[Joy::AxisPOV] = -1.f; } } diff --git a/src/SFML/Window/Win32/Joystick.cpp b/src/SFML/Window/Win32/Joystick.cpp index 486bbb40..5d37e4c7 100644 --- a/src/SFML/Window/Win32/Joystick.cpp +++ b/src/SFML/Window/Win32/Joystick.cpp @@ -118,7 +118,10 @@ JoystickState Joystick::UpdateState() State.Axis[Joy::AxisV] = (Pos.dwVpos - (Caps.wVmax + Caps.wVmin) / 2.f) * 200.f / (Caps.wVmax - Caps.wVmin); // POV - State.Axis[Joy::AxisPOV] = Pos.dwPOV / 100.f; + if (Pos.dwPOV != 0xFFFF) + State.Axis[Joy::AxisPOV] = Pos.dwPOV / 100.f; + else + State.Axis[Joy::AxisPOV] = -1.f; // Buttons for (unsigned int i = 0; i < GetButtonsCount(); ++i)