mirror of
https://github.com/libretro/RetroArch
synced 2025-02-04 21:40:02 +00:00
Overlays: Improve Analog Recentering (#17505)
- Use closest point on zone perimeter if first touch is outside zone
This commit is contained in:
parent
089a51f674
commit
05f75b83c1
@ -2371,27 +2371,31 @@ static void input_overlay_get_analog_state(
|
|||||||
|
|
||||||
if (first_touch)
|
if (first_touch)
|
||||||
{
|
{
|
||||||
unsigned recenter_zone =
|
unsigned recenter_zone = /* [0,100] */
|
||||||
config_get_ptr()->uints.input_overlay_analog_recenter_zone;
|
config_get_ptr()->uints.input_overlay_analog_recenter_zone;
|
||||||
|
|
||||||
/* Reset analog center */
|
|
||||||
x_center[b] = desc->x_shift;
|
|
||||||
y_center[b] = desc->y_shift;
|
|
||||||
|
|
||||||
if (recenter_zone != 0)
|
if (recenter_zone != 0)
|
||||||
{
|
{
|
||||||
/* Get analog state without adjusting center or saturation */
|
float touch_dist, w;
|
||||||
x_val = (x - desc->x_shift) / desc->range_x;
|
|
||||||
y_val = (y - desc->y_shift) / desc->range_y;
|
|
||||||
|
|
||||||
/* Recenter if within zone */
|
x_val = (x - desc->x_shift) / desc->range_x;
|
||||||
if ( (x_val * x_val + y_val * y_val) * 1e4
|
y_val = (y - desc->y_shift) / desc->range_y;
|
||||||
< (recenter_zone * recenter_zone)
|
touch_dist = sqrt((x_val * x_val + y_val * y_val) * 1e4);
|
||||||
|| recenter_zone >= 100)
|
|
||||||
{
|
/* Inside zone, recenter to first touch.
|
||||||
x_center[b] = x;
|
* Outside zone, recenter to zone perimeter. */
|
||||||
y_center[b] = y;
|
if (touch_dist <= recenter_zone || recenter_zone >= 100)
|
||||||
}
|
w = 0.0f;
|
||||||
|
else
|
||||||
|
w = (touch_dist - recenter_zone) / touch_dist;
|
||||||
|
|
||||||
|
x_center[b] = x * (1.0f - w) + desc->x_shift * w;
|
||||||
|
y_center[b] = y * (1.0f - w) + desc->y_shift * w;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
x_center[b] = desc->x_shift;
|
||||||
|
y_center[b] = desc->y_shift;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user