mirror of
https://github.com/dborth/vbagx.git
synced 2024-11-25 20:16:53 +01:00
new joystick math
This commit is contained in:
parent
9c933cf7df
commit
48961d6db0
@ -317,59 +317,33 @@ void systemGameRumbleOnlyFor(int OnlyRumbleForFrames) {
|
||||
u32 StandardMovement(unsigned short chan)
|
||||
{
|
||||
u32 J = 0;
|
||||
double angle;
|
||||
static const double THRES = 1.0 / sqrt(2.0);
|
||||
|
||||
s8 pad_x = userInput[chan].pad.stickX;
|
||||
s8 pad_y = userInput[chan].pad.stickY;
|
||||
#ifdef HW_RVL
|
||||
s8 wm_ax = userInput[0].WPAD_StickX(0);
|
||||
s8 wm_ay = userInput[0].WPAD_StickY(0);
|
||||
#endif
|
||||
|
||||
/***
|
||||
Gamecube Joystick input, same as normal
|
||||
***/
|
||||
// Is XY inside the "zone"?
|
||||
if (pad_x * pad_x + pad_y * pad_y > PADCAL * PADCAL)
|
||||
{
|
||||
if (pad_y == 0)
|
||||
{
|
||||
if(pad_x > 0)
|
||||
{
|
||||
J |= VBA_RIGHT;
|
||||
}
|
||||
else if(pad_x < 0)
|
||||
{
|
||||
J |= VBA_LEFT;
|
||||
}
|
||||
}
|
||||
if (pad_x == 0)
|
||||
{
|
||||
if(pad_y > 0)
|
||||
{
|
||||
J |= VBA_UP;
|
||||
}
|
||||
else if(pad_y < 0)
|
||||
{
|
||||
J |= VBA_DOWN;
|
||||
}
|
||||
}
|
||||
angle = atan2(pad_y, pad_x);
|
||||
|
||||
if ((pad_x|pad_y) != 0)
|
||||
{
|
||||
if ((fabs((double)(pad_y) / (double)(pad_x))) < 2.41421356237)
|
||||
{
|
||||
if (pad_x >= 0)
|
||||
if(cos(angle) > THRES)
|
||||
J |= VBA_RIGHT;
|
||||
else
|
||||
else if(cos(angle) < -THRES)
|
||||
J |= VBA_LEFT;
|
||||
}
|
||||
if ((fabs((double)(pad_x) / (double)(pad_y))) < 2.41421356237)
|
||||
{
|
||||
if (pad_y >= 0)
|
||||
if(sin(angle) > THRES)
|
||||
J |= VBA_UP;
|
||||
else
|
||||
else if(sin(angle) < -THRES)
|
||||
J |= VBA_DOWN;
|
||||
}
|
||||
}
|
||||
}
|
||||
#ifdef HW_RVL
|
||||
/***
|
||||
Wii Joystick (classic, nunchuk) input
|
||||
@ -377,48 +351,17 @@ u32 StandardMovement(unsigned short chan)
|
||||
// Is XY inside the "zone"?
|
||||
if (wm_ax * wm_ax + wm_ay * wm_ay > PADCAL * PADCAL)
|
||||
{
|
||||
/*** we don't want division by zero ***/
|
||||
if (wm_ay == 0)
|
||||
{
|
||||
if(wm_ax > 0)
|
||||
{
|
||||
J |= VBA_RIGHT;
|
||||
}
|
||||
else if(pad_x < 0)
|
||||
{
|
||||
J |= VBA_LEFT;
|
||||
}
|
||||
}
|
||||
if (wm_ax == 0)
|
||||
{
|
||||
if(wm_ay > 0)
|
||||
{
|
||||
J |= VBA_UP;
|
||||
}
|
||||
else if(pad_y < 0)
|
||||
{
|
||||
J |= VBA_DOWN;
|
||||
}
|
||||
}
|
||||
angle = atan2(wm_ay, wm_ax);
|
||||
|
||||
if (wm_ax != 0 && wm_ay != 0)
|
||||
{
|
||||
if ((fabs((double)(wm_ay) / (double)(wm_ax))) < 2.41421356237)
|
||||
{
|
||||
if (wm_ax >= 0)
|
||||
if(cos(angle) > THRES)
|
||||
J |= VBA_RIGHT;
|
||||
else
|
||||
else if(cos(angle) < -THRES)
|
||||
J |= VBA_LEFT;
|
||||
}
|
||||
if ((fabs((double)(wm_ax) / (double)(wm_ay))) < 2.41421356237)
|
||||
{
|
||||
if (wm_ay >= 0)
|
||||
if(sin(angle) > THRES)
|
||||
J |= VBA_UP;
|
||||
else
|
||||
else if(sin(angle) < -THRES)
|
||||
J |= VBA_DOWN;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
return J;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user