Fixed joystick axes mapping (to be tested)

git-svn-id: https://sfml.svn.sourceforge.net/svnroot/sfml/trunk@1332 4e206d99-4929-0410-ac5d-dfc041789085
This commit is contained in:
LaurentGom 2010-01-06 14:28:20 +00:00
parent cbee33e764
commit b9a2d3a8f4
2 changed files with 19 additions and 19 deletions

View File

@ -28,13 +28,6 @@
#include <SFML/Window/Joystick.hpp>
#include <sstream>
#if defined(SFML_SYSTEM_LINUX)
#include <linux/joystick.h>
#include <fcntl.h>
#elif defined(SFML_SYSTEM_FREEBSD)
// #include <sys/joystick.h> ?
#endif
namespace sf
{
@ -78,12 +71,12 @@ void Joystick::Initialize(unsigned int Index)
myNbButtons = Joy::ButtonCount;
// Get the supported axes
char NbAxes, Axes[ABS_MAX + 1];
ioctl(myDescriptor, JSIOCGAXES, &NbAxes);
ioctl(myDescriptor, JSIOCGAXMAP, Axes);
char NbAxes;
ioctl(myDescriptor, JSIOCGAXES, &NbAxes);
ioctl(myDescriptor, JSIOCGAXMAP, myAxesMapping);
for (int i = 0; i < NbAxes; ++i)
{
switch (Axes[i])
switch (myAxesMapping[i])
{
case ABS_X : myAxes[Joy::AxisX] = true; break;
case ABS_Y : myAxes[Joy::AxisY] = true; break;
@ -114,7 +107,7 @@ JoystickState Joystick::UpdateState()
// An axis has been moved
case JS_EVENT_AXIS :
{
switch (JoyState.number)
switch (myAxesMapping[JoyState.number])
{
case ABS_X : myState.Axis[Joy::AxisX] = JoyState.value * 100.f / 32767.f; break;
case ABS_Y : myState.Axis[Joy::AxisY] = JoyState.value * 100.f / 32767.f; break;

View File

@ -28,6 +28,12 @@
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#if defined(SFML_SYSTEM_LINUX)
#include <linux/joystick.h>
#include <fcntl.h>
#elif defined(SFML_SYSTEM_FREEBSD)
// #include <sys/joystick.h> ?
#endif
namespace sf
@ -80,12 +86,13 @@ private :
////////////////////////////////////////////////////////////
// Member data
////////////////////////////////////////////////////////////
int myDescriptor; ///< Linux descriptor of the joystick
unsigned int myNbButtons; ///< Number of buttons supported by the joystick
bool myAxes[Joy::AxisCount]; ///< Supported axes
JoystickState myState; ///< Current state of the joystick
int myPovX; ///< Last X position of the POV
int myPovY; ///< Last Y position of the POV
int myDescriptor; ///< Linux descriptor of the joystick
unsigned int myNbButtons; ///< Number of buttons supported by the joystick
bool myAxes[Joy::AxisCount]; ///< Supported axes
JoystickState myState; ///< Current state of the joystick
int myPovX; ///< Last X position of the POV
int myPovY; ///< Last Y position of the POV
char myAxesMapping[ABS_MAX + 1]; ///< Axes mapping (index --> axis id)
};
} // namespace priv