mirror of
https://github.com/RetroDECK/Duckstation.git
synced 2024-11-30 01:25:51 +00:00
Android: Manually scale axis values instead of using motion range
This commit is contained in:
parent
d0667ba32a
commit
d4997c6fb9
|
@ -112,15 +112,7 @@ bool AndroidControllerInterface::HandleAxisEvent(u32 index, u32 axis, float valu
|
||||||
const AxisCallback& cb = m_controllers[index].axis_mapping[static_cast<u32>(axis)][AxisSide::Full];
|
const AxisCallback& cb = m_controllers[index].axis_mapping[static_cast<u32>(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 (axis == 4 && axis == 5)
|
|
||||||
{
|
|
||||||
cb((value * 2.0f) - 1.0f);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
cb(value);
|
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -208,6 +208,10 @@ public class EmulationSurfaceView extends SurfaceView {
|
||||||
return !isExternalKeyCode(keyCode);
|
return !isExternalKeyCode(keyCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private float clamp(float value, float min, float max) {
|
||||||
|
return (value < min) ? min : ((value > max) ? max : value);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onGenericMotionEvent(MotionEvent event) {
|
public boolean onGenericMotionEvent(MotionEvent event) {
|
||||||
final int source = event.getSource();
|
final int source = event.getSource();
|
||||||
|
@ -222,12 +226,21 @@ public class EmulationSurfaceView extends SurfaceView {
|
||||||
final float axisValue = event.getAxisValue(mapping.deviceAxisOrButton);
|
final float axisValue = event.getAxisValue(mapping.deviceAxisOrButton);
|
||||||
float emuValue;
|
float emuValue;
|
||||||
|
|
||||||
if (mapping.deviceMotionRange != null) {
|
switch (mapping.deviceAxisOrButton) {
|
||||||
final float transformedValue = (axisValue - mapping.deviceMotionRange.getMin()) / mapping.deviceMotionRange.getRange();
|
case MotionEvent.AXIS_BRAKE:
|
||||||
emuValue = (transformedValue * 2.0f) - 1.0f;
|
case MotionEvent.AXIS_GAS:
|
||||||
} else {
|
case MotionEvent.AXIS_LTRIGGER:
|
||||||
emuValue = axisValue;
|
case MotionEvent.AXIS_RTRIGGER:
|
||||||
|
// Scale 0..1 -> -1..1.
|
||||||
|
emuValue = (clamp(axisValue, 0.0f, 1.0f) * 2.0f) - 1.0f;
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
// Everything else should already by -1..1 as per Android documentation.
|
||||||
|
emuValue = clamp(axisValue, -1.0f, 1.0f);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
Log.d("EmulationSurfaceView", String.format("axis %d value %f emuvalue %f", mapping.deviceAxisOrButton, axisValue, emuValue));
|
Log.d("EmulationSurfaceView", String.format("axis %d value %f emuvalue %f", mapping.deviceAxisOrButton, axisValue, emuValue));
|
||||||
|
|
||||||
if (mapping.axisMapping >= 0) {
|
if (mapping.axisMapping >= 0) {
|
||||||
|
|
Loading…
Reference in a new issue