Clamp the circle pad more correctly
This commit is contained in:
parent
317689a790
commit
a268b6b77e
@ -139,9 +139,16 @@ public final class InputOverlayDrawableJoystick {
|
|||||||
maxY -= getVirtBounds().centerY();
|
maxY -= getVirtBounds().centerY();
|
||||||
final float AxisX = touchX / maxX;
|
final float AxisX = touchX / maxX;
|
||||||
final float AxisY = touchY / maxY;
|
final float AxisY = touchY / maxY;
|
||||||
axises[0] = AxisX;
|
|
||||||
axises[1] = AxisY;
|
|
||||||
|
|
||||||
|
// Clamp the circle pad input to a circle
|
||||||
|
final float angle = (float) Math.atan2(AxisY, AxisX);
|
||||||
|
float radius = (float) Math.sqrt(AxisX * AxisX + AxisY * AxisY);
|
||||||
|
if(radius > 1.0f)
|
||||||
|
{
|
||||||
|
radius = 1.0f;
|
||||||
|
}
|
||||||
|
axises[0] = ((float)Math.cos(angle) * radius);
|
||||||
|
axises[1] = ((float)Math.sin(angle) * radius);
|
||||||
SetInnerBounds();
|
SetInnerBounds();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -332,6 +332,14 @@ jboolean Java_org_citra_citra_1emu_NativeLibrary_onGamePadMoveEvent(JNIEnv* env,
|
|||||||
// Citra uses an inverted y axis sent by the frontend
|
// Citra uses an inverted y axis sent by the frontend
|
||||||
x = std::clamp(x, -1.f, 1.f);
|
x = std::clamp(x, -1.f, 1.f);
|
||||||
y = std::clamp(-y, -1.f, 1.f);
|
y = std::clamp(-y, -1.f, 1.f);
|
||||||
|
|
||||||
|
// Clamp the input to a circle (while touch input is already clamped in the frontend, gamepad is unknown)
|
||||||
|
float r = x * x + y * y;
|
||||||
|
if (r > 1.0f) {
|
||||||
|
r = std::sqrt(r);
|
||||||
|
x /= r;
|
||||||
|
y /= r;
|
||||||
|
}
|
||||||
return static_cast<jboolean>(InputManager::AnalogHandler()->MoveJoystick(axis, x, y));
|
return static_cast<jboolean>(InputManager::AnalogHandler()->MoveJoystick(axis, x, y));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user