diff options
| author | mageven <62494521+mageven@users.noreply.github.com> | 2021-01-19 05:26:53 +0530 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-01-19 00:56:53 +0100 |
| commit | 5e1a839eaa7349342fc34a7adf4d901222b2343b (patch) | |
| tree | ad3e1f77fbb58a7e9c85440b41e66b9ae1f6f818 | |
| parent | 4da674286148d804be6bddb9011d3d28924caf0e (diff) | |
Emulate a circular zone for keyboard analog sticks (#1906)
| -rw-r--r-- | Ryujinx/Ui/KeyboardController.cs | 29 |
1 files changed, 18 insertions, 11 deletions
diff --git a/Ryujinx/Ui/KeyboardController.cs b/Ryujinx/Ui/KeyboardController.cs index f52642e3..f201c283 100644 --- a/Ryujinx/Ui/KeyboardController.cs +++ b/Ryujinx/Ui/KeyboardController.cs @@ -1,4 +1,5 @@ using System; +using OpenTK; using OpenTK.Input; using Ryujinx.Common.Configuration.Hid; using Ryujinx.Configuration; @@ -68,13 +69,16 @@ namespace Ryujinx.Ui short dx = 0; short dy = 0; - - if (keyboard[(Key)_config.LeftJoycon.StickUp]) dy = short.MaxValue; - if (keyboard[(Key)_config.LeftJoycon.StickDown]) dy = -short.MaxValue; - if (keyboard[(Key)_config.LeftJoycon.StickLeft]) dx = -short.MaxValue; - if (keyboard[(Key)_config.LeftJoycon.StickRight]) dx = short.MaxValue; - return (dx, dy); + if (keyboard[(Key)_config.LeftJoycon.StickUp]) dy += 1; + if (keyboard[(Key)_config.LeftJoycon.StickDown]) dy += -1; + if (keyboard[(Key)_config.LeftJoycon.StickLeft]) dx += -1; + if (keyboard[(Key)_config.LeftJoycon.StickRight]) dx += 1; + + Vector2 stick = new Vector2(dx, dy); + stick.NormalizeFast(); + + return ((short)(stick.X * short.MaxValue), (short)(stick.Y * short.MaxValue)); } public (short, short) GetRightStick() @@ -84,12 +88,15 @@ namespace Ryujinx.Ui short dx = 0; short dy = 0; - if (keyboard[(Key)_config.RightJoycon.StickUp]) dy = short.MaxValue; - if (keyboard[(Key)_config.RightJoycon.StickDown]) dy = -short.MaxValue; - if (keyboard[(Key)_config.RightJoycon.StickLeft]) dx = -short.MaxValue; - if (keyboard[(Key)_config.RightJoycon.StickRight]) dx = short.MaxValue; + if (keyboard[(Key)_config.RightJoycon.StickUp]) dy += 1; + if (keyboard[(Key)_config.RightJoycon.StickDown]) dy += -1; + if (keyboard[(Key)_config.RightJoycon.StickLeft]) dx += -1; + if (keyboard[(Key)_config.RightJoycon.StickRight]) dx += 1; + + Vector2 stick = new Vector2(dx, dy); + stick.NormalizeFast(); - return (dx, dy); + return ((short)(stick.X * short.MaxValue), (short)(stick.Y * short.MaxValue)); } public static HotkeyButtons GetHotkeyButtons(KeyboardState keyboard) |
