@ -198,7 +198,12 @@ void JoystickInput::run()
@@ -198,7 +198,12 @@ void JoystickInput::run()
axisValue = ( axisValue - calibrationPositive [ i ] ) / ( calibrationNegative [ i ] - calibrationPositive [ i ] ) ;
}
axisValue = 1.0f - axisValue ;
axisValue = axisValue * 2.0f - 1.0f ;
// If the joystick isn't limited to [0:1.0], map it into [-1.0:1.0].
if ( ! joystickAxesRangeLimited [ i ] )
{
axisValue = axisValue * 2.0f - 1.0f ;
}
// Bound rounding errors
if ( axisValue > 1.0f ) axisValue = 1.0f ;
@ -276,6 +281,7 @@ void JoystickInput::setActiveJoystick(int id)
@@ -276,6 +281,7 @@ void JoystickInput::setActiveJoystick(int id)
// Update cached joystick values
joystickAxes . clear ( ) ;
joystickAxesInverted . clear ( ) ;
joystickAxesRangeLimited . clear ( ) ;
for ( int i = 0 ; i < joystickNumAxes ; i + + )
{
int axisValue = SDL_JoystickGetAxis ( joystick , i ) ;
@ -283,6 +289,7 @@ void JoystickInput::setActiveJoystick(int id)
@@ -283,6 +289,7 @@ void JoystickInput::setActiveJoystick(int id)
emit axisValueChanged ( i , axisValue ) ;
joystickAxesInverted . append ( false ) ;
joystickAxesRangeLimited . append ( false ) ;
}
joystickButtons = 0 ;
for ( int i = 0 ; i < joystickNumButtons ; i + + )
@ -348,6 +355,14 @@ void JoystickInput::setAxisInversion(int axis, bool inverted)
@@ -348,6 +355,14 @@ void JoystickInput::setAxisInversion(int axis, bool inverted)
}
}
void JoystickInput : : setAxisRangeLimit ( int axis , bool rangeLimited )
{
if ( axis < joystickAxesRangeLimited . size ( ) )
{
joystickAxesRangeLimited [ axis ] = rangeLimited ;
}
}
float JoystickInput : : getCurrentValueForAxis ( int axis )
{
if ( axis < joystickAxes . size ( ) )