simplify logic for controller analog sticks

This commit is contained in:
Daryl Borth 2018-08-30 16:09:31 -06:00
parent c64e7a2f70
commit 53cf729fa8

View File

@ -12,7 +12,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <ogcsys.h>
#include <unistd.h>
#include <wiiuse/wpad.h>
@ -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)
if (pad_y > ANALOG_SENSITIVITY)
J |= VBA_UP;
else if(sin(angle) < -THRES)
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)
if (wm_ay > ANALOG_SENSITIVITY)
J |= VBA_UP;
else if(sin(angle) < -THRES)
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;
}