Make sensitivity independent of deadzone for touch device

This commit is contained in:
Deve 2018-11-03 00:06:17 +01:00
parent f05172b93f
commit b7856d4991
4 changed files with 18 additions and 19 deletions

View File

@ -61,7 +61,7 @@
<label proportion="1" align="center" text_align="right" I18N="In the multitouch settings screen" text="Sensitivity X"/>
<div proportion="1" align="center" height="fit" layout="horizontal-row" >
<spacer width="40" height="10" />
<gauge id="sensitivity_x" proportion="1" min_value="0" max_value="50"/>
<gauge id="sensitivity_x" proportion="1" min_value="0" max_value="100"/>
</div>
</div>
@ -69,7 +69,7 @@
<label proportion="1" align="center" text_align="right" I18N="In the multitouch settings screen" text="Sensitivity Y"/>
<div proportion="1" align="center" height="fit" layout="horizontal-row" >
<spacer width="40" height="10" />
<gauge id="sensitivity_y" proportion="1" min_value="0" max_value="50"/>
<gauge id="sensitivity_y" proportion="1" min_value="0" max_value="100"/>
</div>
</div>

View File

@ -507,14 +507,12 @@ namespace UserConfigParams
PARAM_PREFIX FloatUserConfigParam m_multitouch_sensitivity_x
PARAM_DEFAULT( FloatUserConfigParam(0.1f, "multitouch_sensitivity_x",
&m_multitouch_group,
"A parameter in range [0, 0.5] that determines the zone for y axis "
"that is considered as max value in steering button."));
"A parameter in range [0, 1.0] that determines the sensitivity for x axis."));
PARAM_PREFIX FloatUserConfigParam m_multitouch_sensitivity_y
PARAM_DEFAULT( FloatUserConfigParam(0.5f, "multitouch_sensitivity_y",
PARAM_DEFAULT( FloatUserConfigParam(0.65f, "multitouch_sensitivity_y",
&m_multitouch_group,
"A parameter in range [0, 0.5] that determines the zone for y axis "
"that is considered as max value in steering button."));
"A parameter in range [0, 1.0] that determines the sensitivity for y axis."));
PARAM_PREFIX FloatUserConfigParam m_multitouch_tilt_factor
PARAM_DEFAULT( FloatUserConfigParam(4.0f, "multitouch_tilt_factor",

View File

@ -356,26 +356,29 @@ void MultitouchDevice::updateConfigParams()
m_deadzone = std::min(std::max(m_deadzone, 0.0f), 0.5f);
m_sensitivity_x = UserConfigParams::m_multitouch_sensitivity_x;
m_sensitivity_x = std::min(std::max(m_sensitivity_x, 0.0f), 0.5f);
m_sensitivity_x = std::min(std::max(m_sensitivity_x, 0.0f), 1.0f);
m_sensitivity_y = UserConfigParams::m_multitouch_sensitivity_y;
m_sensitivity_y = std::min(std::max(m_sensitivity_y, 0.0f), 0.5f);
m_sensitivity_y = std::min(std::max(m_sensitivity_y, 0.0f), 1.0f);
} // updateConfigParams
// ----------------------------------------------------------------------------
/** Helper function that returns a steering factor for steering button.
* \param value The axis value from 0 to 1.
* \param sensitivity Value from 0 to 0.5.
* \param sensitivity Value from 0 to 1.0.
*/
float MultitouchDevice::getSteeringFactor(float value, float sensitivity)
{
if (sensitivity + m_deadzone >= 1.0f)
if (m_deadzone >= 1.0f)
return 0.0f;
if (sensitivity >= 1.0f)
return 1.0f;
assert(sensitivity + m_deadzone != 1.0f);
return std::min((value - m_deadzone) / (1.0f - sensitivity -
m_deadzone), 1.0f);
float factor = (value - m_deadzone) / (1.0f - m_deadzone);
factor *= 1.0f / (1.0f - sensitivity);
return std::min(factor, 1.0f);
}
// ----------------------------------------------------------------------------

View File

@ -83,12 +83,10 @@ private:
* in a center of button */
float m_deadzone;
/** A parameter that determines the zone for x axis that is considered as
* max value in steering button. */
/** A parameter in range that determines the sensitivity for x axis. */
float m_sensitivity_x;
/** A parameter that determines the zone for y axis that is considered as
* max value in steering button. */
/** A parameter in range that determines the sensitivity for y axis. */
float m_sensitivity_y;
float m_orientation;