SDLControllerInterface: Support half axis bindings
This commit is contained in:
parent
a51fc5a149
commit
0ceb0f7a4a
|
@ -376,8 +376,7 @@ bool SDLControllerInterface::HandleJoystickAxisEvent(const SDL_JoyAxisEvent* eve
|
||||||
const AxisCallback& hcb = it->axis_mapping[event->axis][AxisSide::Positive];
|
const AxisCallback& hcb = it->axis_mapping[event->axis][AxisSide::Positive];
|
||||||
if (hcb)
|
if (hcb)
|
||||||
{
|
{
|
||||||
// Expand 0..1 - -1..1
|
hcb(value);
|
||||||
hcb(value * 2.0f - 1.0f);
|
|
||||||
processed = true;
|
processed = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -386,8 +385,7 @@ bool SDLControllerInterface::HandleJoystickAxisEvent(const SDL_JoyAxisEvent* eve
|
||||||
const AxisCallback& hcb = it->axis_mapping[event->axis][AxisSide::Negative];
|
const AxisCallback& hcb = it->axis_mapping[event->axis][AxisSide::Negative];
|
||||||
if (hcb)
|
if (hcb)
|
||||||
{
|
{
|
||||||
// Expand 0..-1 - -1..1
|
hcb(value);
|
||||||
hcb(value * -2.0f - 1.0f);
|
|
||||||
processed = true;
|
processed = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -635,17 +633,23 @@ bool SDLControllerInterface::HandleControllerAxisEvent(const SDL_ControllerAxisE
|
||||||
const AxisCallback& cb = it->axis_mapping[ev->axis][AxisSide::Full];
|
const AxisCallback& cb = it->axis_mapping[ev->axis][AxisSide::Full];
|
||||||
if (cb)
|
if (cb)
|
||||||
{
|
{
|
||||||
// Extend triggers from a 0 - 1 range to a -1 - 1 range for consistency with other inputs
|
cb(value);
|
||||||
if (ev->axis == SDL_CONTROLLER_AXIS_TRIGGERLEFT || ev->axis == SDL_CONTROLLER_AXIS_TRIGGERRIGHT)
|
|
||||||
{
|
|
||||||
cb((value * 2.0f) - 1.0f);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
cb(value);
|
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
const AxisCallback& positive_cb = it->axis_mapping[ev->axis][AxisSide::Positive];
|
||||||
|
const AxisCallback& negative_cb = it->axis_mapping[ev->axis][AxisSide::Negative];
|
||||||
|
if (positive_cb || negative_cb)
|
||||||
|
{
|
||||||
|
if (positive_cb)
|
||||||
|
positive_cb((value < 0.0f) ? 0.0f : value);
|
||||||
|
if (negative_cb)
|
||||||
|
negative_cb((value >= 0.0f) ? 0.0f : -value);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// set the other direction to false so large movements don't leave the opposite on
|
// set the other direction to false so large movements don't leave the opposite on
|
||||||
const bool outside_deadzone = (std::abs(value) >= it->deadzone);
|
const bool outside_deadzone = (std::abs(value) >= it->deadzone);
|
||||||
|
|
Loading…
Reference in New Issue