Added option to 'desensitze' joysticks, i.e. make it less sensible

at values close to 0.
This commit is contained in:
hiker 2014-10-31 16:32:39 +11:00
parent 22441c1fd8
commit e9e5cab164
4 changed files with 34 additions and 7 deletions

View File

@ -105,6 +105,10 @@ public:
* will not be affected by time-full-steer delays. */
virtual bool isAnalog() const { return false;}
// ------------------------------------------------------------------------
/** Returns true if this device should desensitize its input at values
* close to 0 (to avoid 'oversteering'). */
virtual bool desensitize() const { return false;}
// ------------------------------------------------------------------------
/** Should only be called for gamepads, which has its own implementation.
* of this function. */
virtual int getNumberOfButtons() const

View File

@ -45,8 +45,9 @@ GamepadConfig::GamepadConfig( const std::string &name,
GamepadConfig::GamepadConfig() : DeviceConfig()
{
m_deadzone = 2000;
m_is_analog = true;
m_deadzone = 2000;
m_is_analog = true;
m_desensitize = false;
setDefaultBinds();
} // GamepadConfig
@ -57,8 +58,9 @@ GamepadConfig::GamepadConfig() : DeviceConfig()
*/
bool GamepadConfig::load(const XMLNode *config)
{
config->get("deadzone", &m_deadzone);
config->get("analog", &m_is_analog);
config->get("deadzone", &m_deadzone );
config->get("analog", &m_is_analog );
config->get("desensitize", &m_desensitize);
bool ok = DeviceConfig::load(config);
if(getName()=="")
@ -80,6 +82,7 @@ void GamepadConfig::save (std::ofstream& stream)
{
stream << "<gamepad name =\"" << getName()
<< "\" deadzone=\"" << m_deadzone
<< "\" desensitize=\"" << m_desensitize
<< "\" analog=\"" << m_is_analog<<"\"\n";
stream << " ";
DeviceConfig::save(stream);
@ -107,9 +110,7 @@ void GamepadConfig::setDefaultBinds ()
setBinding(PA_MENU_RIGHT, Input::IT_STICKMOTION, 0, Input::AD_POSITIVE);
setBinding(PA_MENU_SELECT, Input::IT_STICKBUTTON, 0);
setBinding(PA_MENU_CANCEL, Input::IT_STICKBUTTON, 3);
}
//------------------------------------------------------------------------------
} // setDefaultBinds
//------------------------------------------------------------------------------
/** Converts the configuration to a string.

View File

@ -49,6 +49,11 @@ private:
/** If this device has analog axis, steering etc. must be set immediately
* from the input values, not having a delayed time (time-full-steer). */
bool m_is_analog;
/** If set to true, map any analog axis from x in [0,1] to x^x --> at
* values close to 0 the joystick will react less sensitive. */
bool m_desensitize;
public:
GamepadConfig ();
@ -66,6 +71,11 @@ public:
/** Returns if this device uses analog axes. */
virtual bool isAnalog() const OVERRIDE { return m_is_analog; }
// ------------------------------------------------------------------------
/** Returns true if this device should desensitize its input at values
* close to 0 (to avoid 'oversteering'). */
virtual bool desensitize() const { return m_desensitize;}
// ------------------------------------------------------------------------
/** Returns the number of buttons in this configuration. */
virtual int getNumberOfButtons() const OVERRIDE { return m_button_count; }

View File

@ -172,6 +172,18 @@ bool GamePadDevice::processAndMapInput(Input::InputType type, const int id,
else if(*value==-32768)
*value = -32767;
}
// Desensitizing means to map an input in the range x in [0,1] to
// x^2. This results in changes close to 0 to have less impact
// (less sensitive).
if(m_configuration->desensitize())
{
// x/32767 is in [-1,1], (x/32767)^2 is in [0,1]. Take care of the
// sign and map this back to [0,32767] by multiplying by 32767.
// Which all in all results in:
*value = int( (*value / 32767) * fabsf(*value) );
}
bool success = false;
if(m_prev_axis_directions == NULL) return false; // device not open