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:
parent
cbee33e764
commit
b9a2d3a8f4
@ -28,13 +28,6 @@
|
|||||||
#include <SFML/Window/Joystick.hpp>
|
#include <SFML/Window/Joystick.hpp>
|
||||||
#include <sstream>
|
#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
|
namespace sf
|
||||||
{
|
{
|
||||||
@ -78,12 +71,12 @@ void Joystick::Initialize(unsigned int Index)
|
|||||||
myNbButtons = Joy::ButtonCount;
|
myNbButtons = Joy::ButtonCount;
|
||||||
|
|
||||||
// Get the supported axes
|
// Get the supported axes
|
||||||
char NbAxes, Axes[ABS_MAX + 1];
|
char NbAxes;
|
||||||
ioctl(myDescriptor, JSIOCGAXES, &NbAxes);
|
ioctl(myDescriptor, JSIOCGAXES, &NbAxes);
|
||||||
ioctl(myDescriptor, JSIOCGAXMAP, Axes);
|
ioctl(myDescriptor, JSIOCGAXMAP, myAxesMapping);
|
||||||
for (int i = 0; i < NbAxes; ++i)
|
for (int i = 0; i < NbAxes; ++i)
|
||||||
{
|
{
|
||||||
switch (Axes[i])
|
switch (myAxesMapping[i])
|
||||||
{
|
{
|
||||||
case ABS_X : myAxes[Joy::AxisX] = true; break;
|
case ABS_X : myAxes[Joy::AxisX] = true; break;
|
||||||
case ABS_Y : myAxes[Joy::AxisY] = true; break;
|
case ABS_Y : myAxes[Joy::AxisY] = true; break;
|
||||||
@ -114,7 +107,7 @@ JoystickState Joystick::UpdateState()
|
|||||||
// An axis has been moved
|
// An axis has been moved
|
||||||
case JS_EVENT_AXIS :
|
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_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;
|
case ABS_Y : myState.Axis[Joy::AxisY] = JoyState.value * 100.f / 32767.f; break;
|
||||||
|
@ -28,6 +28,12 @@
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
// Headers
|
// 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
|
namespace sf
|
||||||
@ -86,6 +92,7 @@ private :
|
|||||||
JoystickState myState; ///< Current state of the joystick
|
JoystickState myState; ///< Current state of the joystick
|
||||||
int myPovX; ///< Last X position of the POV
|
int myPovX; ///< Last X position of the POV
|
||||||
int myPovY; ///< Last Y position of the POV
|
int myPovY; ///< Last Y position of the POV
|
||||||
|
char myAxesMapping[ABS_MAX + 1]; ///< Axes mapping (index --> axis id)
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace priv
|
} // namespace priv
|
||||||
|
Loading…
Reference in New Issue
Block a user