mirror of
https://github.com/dborth/vbagx.git
synced 2024-11-29 05:54:17 +01:00
simplify logic for controller analog sticks
This commit is contained in:
parent
c64e7a2f70
commit
53cf729fa8
@ -12,7 +12,6 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <math.h>
|
|
||||||
#include <ogcsys.h>
|
#include <ogcsys.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <wiiuse/wpad.h>
|
#include <wiiuse/wpad.h>
|
||||||
@ -32,6 +31,8 @@
|
|||||||
#include "vba/gba/bios.h"
|
#include "vba/gba/bios.h"
|
||||||
#include "vba/gba/GBAinline.h"
|
#include "vba/gba/GBAinline.h"
|
||||||
|
|
||||||
|
#define ANALOG_SENSITIVITY 30
|
||||||
|
|
||||||
int rumbleRequest[4] = {0,0,0,0};
|
int rumbleRequest[4] = {0,0,0,0};
|
||||||
GuiTrigger userInput[4];
|
GuiTrigger userInput[4];
|
||||||
|
|
||||||
@ -318,8 +319,6 @@ void systemGameRumbleOnlyFor(int OnlyRumbleForFrames) {
|
|||||||
u32 StandardMovement(unsigned short chan)
|
u32 StandardMovement(unsigned short chan)
|
||||||
{
|
{
|
||||||
u32 J = 0;
|
u32 J = 0;
|
||||||
double angle;
|
|
||||||
static const double THRES = 0.38268343236508984; // cos(67.5)
|
|
||||||
|
|
||||||
s8 pad_x = userInput[chan].pad.stickX;
|
s8 pad_x = userInput[chan].pad.stickX;
|
||||||
s8 pad_y = userInput[chan].pad.stickY;
|
s8 pad_y = userInput[chan].pad.stickY;
|
||||||
@ -331,37 +330,26 @@ u32 StandardMovement(unsigned short chan)
|
|||||||
/***
|
/***
|
||||||
Gamecube Joystick input, same as normal
|
Gamecube Joystick input, same as normal
|
||||||
***/
|
***/
|
||||||
// Is XY inside the "zone"?
|
if (pad_y > ANALOG_SENSITIVITY)
|
||||||
if (pad_x * pad_x + pad_y * pad_y > PADCAL * PADCAL)
|
J |= VBA_UP;
|
||||||
{
|
else if (pad_y < -ANALOG_SENSITIVITY)
|
||||||
angle = atan2(pad_y, pad_x);
|
J |= VBA_DOWN;
|
||||||
|
if (pad_x < -ANALOG_SENSITIVITY)
|
||||||
if(cos(angle) > THRES)
|
J |= VBA_LEFT;
|
||||||
J |= VBA_RIGHT;
|
else if (pad_x > ANALOG_SENSITIVITY)
|
||||||
else if(cos(angle) < -THRES)
|
J |= VBA_RIGHT;
|
||||||
J |= VBA_LEFT;
|
|
||||||
if(sin(angle) > THRES)
|
|
||||||
J |= VBA_UP;
|
|
||||||
else if(sin(angle) < -THRES)
|
|
||||||
J |= VBA_DOWN;
|
|
||||||
}
|
|
||||||
#ifdef HW_RVL
|
#ifdef HW_RVL
|
||||||
/***
|
/***
|
||||||
Wii Joystick (classic, nunchuk) input
|
Wii Joystick (classic, nunchuk) input
|
||||||
***/
|
***/
|
||||||
// Is XY inside the "zone"?
|
if (wm_ay > ANALOG_SENSITIVITY)
|
||||||
if (wm_ax * wm_ax + wm_ay * wm_ay > PADCAL * PADCAL)
|
J |= VBA_UP;
|
||||||
{
|
else if (wm_ay < -ANALOG_SENSITIVITY)
|
||||||
angle = atan2(wm_ay, wm_ax);
|
J |= VBA_DOWN;
|
||||||
if(cos(angle) > THRES)
|
if (wm_ax < -ANALOG_SENSITIVITY)
|
||||||
J |= VBA_RIGHT;
|
J |= VBA_LEFT;
|
||||||
else if(cos(angle) < -THRES)
|
else if (wm_ax > ANALOG_SENSITIVITY)
|
||||||
J |= VBA_LEFT;
|
J |= VBA_RIGHT;
|
||||||
if(sin(angle) > THRES)
|
|
||||||
J |= VBA_UP;
|
|
||||||
else if(sin(angle) < -THRES)
|
|
||||||
J |= VBA_DOWN;
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
return J;
|
return J;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user