Few minor fixes for multitouch steering:

- don't update a button that is already not pressed
- use full axis range, which means higher sensitivity in the center
- make sure that we don't divide by 0
This commit is contained in:
Deve 2016-11-18 01:12:09 +01:00
parent b6c1a45918
commit 952bed5672
3 changed files with 28 additions and 17 deletions

View File

@ -400,13 +400,13 @@ namespace UserConfigParams
"Enable multitouch support.") );
PARAM_PREFIX FloatUserConfigParam m_multitouch_deadzone_center
PARAM_DEFAULT( FloatUserConfigParam(0.15f, "multitouch_deadzone_center",
PARAM_DEFAULT( FloatUserConfigParam(0.1f, "multitouch_deadzone_center",
&m_multitouch_group,
"A parameter in range [0, 0.5] that determines the zone that is "
"considered as centered in steering button."));
PARAM_PREFIX FloatUserConfigParam m_multitouch_deadzone_edge
PARAM_DEFAULT( FloatUserConfigParam(0.15f, "multitouch_deadzone_edge",
PARAM_DEFAULT( FloatUserConfigParam(0.25f, "multitouch_deadzone_edge",
&m_multitouch_group,
"A parameter in range [0, 0.5] that determines the zone that is "
"considered as max value in steering button."));

View File

@ -182,7 +182,6 @@ void MultitouchDevice::updateDeviceState(unsigned int event_id)
button->event_id = 0;
button->axis_x = 0.0f;
button->axis_y = 0.0f;
update_controls = true;
}
}
else
@ -211,10 +210,11 @@ void MultitouchDevice::updateDeviceState(unsigned int event_id)
update_controls = true;
}
}
else if (prev_button_state != button->pressed)
{
update_controls = true;
}
}
if (prev_button_state != button->pressed)
{
update_controls = true;
}
if (update_controls)
@ -225,6 +225,21 @@ void MultitouchDevice::updateDeviceState(unsigned int event_id)
}
} // updateDeviceState
// ----------------------------------------------------------------------------
/** Helper function that returns a steering factor for steering button.
* \param value The axis value from 0 to 1.
*/
float MultitouchDevice::getSteeringFactor(float value)
{
if (m_deadzone_edge + m_deadzone_center >= 1.0f)
return 1.0f;
assert(m_deadzone_edge + m_deadzone_center != 1.0f);
return std::min((value - m_deadzone_center) / (1.0f - m_deadzone_edge -
m_deadzone_center), 1.0f);
}
// ----------------------------------------------------------------------------
/** Sends proper action for player controller depending on the button type
* and state.
@ -255,18 +270,14 @@ void MultitouchDevice::handleControls(MultitouchButton* button)
if (button->type == MultitouchButtonType::BUTTON_STEERING)
{
assert(m_deadzone_edge != 1.0f);
if (button->axis_y < -m_deadzone_center)
{
float factor = std::min(std::abs(button->axis_y) / (1 -
m_deadzone_edge), 1.0f);
float factor = getSteeringFactor(std::abs(button->axis_y));
controller->action(PA_ACCEL, factor * Input::MAX_VALUE);
}
else if (button->axis_y > m_deadzone_center)
{
float factor = std::min(std::abs(button->axis_y) / (1 -
m_deadzone_edge), 1.0f);
float factor = getSteeringFactor(std::abs(button->axis_y));
controller->action(PA_BRAKE, factor * Input::MAX_VALUE);
}
else
@ -277,14 +288,12 @@ void MultitouchDevice::handleControls(MultitouchButton* button)
if (button->axis_x < -m_deadzone_center)
{
float factor = std::min(std::abs(button->axis_x) / (1 -
m_deadzone_edge), 1.0f);
float factor = getSteeringFactor(std::abs(button->axis_x));
controller->action(PA_STEER_LEFT, factor * Input::MAX_VALUE);
}
else if (button->axis_x > m_deadzone_center)
{
float factor = std::min(std::abs(button->axis_x) / (1 -
m_deadzone_edge), 1.0f);
float factor = getSteeringFactor(std::abs(button->axis_x));
controller->action(PA_STEER_RIGHT, factor * Input::MAX_VALUE);
}
else

View File

@ -77,6 +77,8 @@ private:
/** The parameter that is used for steering button and determines dead area
* at the edge of button */
float m_deadzone_edge;
float getSteeringFactor(float value);
public:
/** The array that contains data for all multitouch input events */