From 53cf729fa8a067536fcf324b90547fe6ac851b27 Mon Sep 17 00:00:00 2001 From: Daryl Borth Date: Thu, 30 Aug 2018 16:09:31 -0600 Subject: [PATCH] simplify logic for controller analog sticks --- source/input.cpp | 48 ++++++++++++++++++------------------------------ 1 file changed, 18 insertions(+), 30 deletions(-) diff --git a/source/input.cpp b/source/input.cpp index 0204959..41adff3 100644 --- a/source/input.cpp +++ b/source/input.cpp @@ -12,7 +12,6 @@ #include #include #include -#include #include #include #include @@ -32,6 +31,8 @@ #include "vba/gba/bios.h" #include "vba/gba/GBAinline.h" +#define ANALOG_SENSITIVITY 30 + int rumbleRequest[4] = {0,0,0,0}; GuiTrigger userInput[4]; @@ -318,8 +319,6 @@ void systemGameRumbleOnlyFor(int OnlyRumbleForFrames) { u32 StandardMovement(unsigned short chan) { u32 J = 0; - double angle; - static const double THRES = 0.38268343236508984; // cos(67.5) s8 pad_x = userInput[chan].pad.stickX; s8 pad_y = userInput[chan].pad.stickY; @@ -331,37 +330,26 @@ u32 StandardMovement(unsigned short chan) /*** Gamecube Joystick input, same as normal ***/ - // Is XY inside the "zone"? - if (pad_x * pad_x + pad_y * pad_y > PADCAL * PADCAL) - { - angle = atan2(pad_y, pad_x); - - if(cos(angle) > THRES) - J |= VBA_RIGHT; - else if(cos(angle) < -THRES) - J |= VBA_LEFT; - if(sin(angle) > THRES) - J |= VBA_UP; - else if(sin(angle) < -THRES) - J |= VBA_DOWN; - } + if (pad_y > ANALOG_SENSITIVITY) + J |= VBA_UP; + else if (pad_y < -ANALOG_SENSITIVITY) + J |= VBA_DOWN; + if (pad_x < -ANALOG_SENSITIVITY) + J |= VBA_LEFT; + else if (pad_x > ANALOG_SENSITIVITY) + J |= VBA_RIGHT; #ifdef HW_RVL /*** Wii Joystick (classic, nunchuk) input ***/ - // Is XY inside the "zone"? - if (wm_ax * wm_ax + wm_ay * wm_ay > PADCAL * PADCAL) - { - angle = atan2(wm_ay, wm_ax); - if(cos(angle) > THRES) - J |= VBA_RIGHT; - else if(cos(angle) < -THRES) - J |= VBA_LEFT; - if(sin(angle) > THRES) - J |= VBA_UP; - else if(sin(angle) < -THRES) - J |= VBA_DOWN; - } + if (wm_ay > ANALOG_SENSITIVITY) + J |= VBA_UP; + else if (wm_ay < -ANALOG_SENSITIVITY) + J |= VBA_DOWN; + if (wm_ax < -ANALOG_SENSITIVITY) + J |= VBA_LEFT; + else if (wm_ax > ANALOG_SENSITIVITY) + J |= VBA_RIGHT; #endif return J; }