fix joystick calculations

This commit is contained in:
Daryl Borth 2018-08-16 14:00:36 -06:00
parent 0628025164
commit 6857a8a9e5

View File

@ -94,53 +94,54 @@ void GuiTrigger::SetButtonOnlyInFocusTrigger(s32 ch, u32 wiibtns, u16 gcbtns)
s8 GuiTrigger::WPAD_Stick(u8 stick, int axis) s8 GuiTrigger::WPAD_Stick(u8 stick, int axis)
{ {
#ifdef HW_RVL #ifdef HW_RVL
struct joystick_t* js = NULL;
float mag = 0.0; switch (wpad->exp.type) {
float ang = 0.0;
switch (wpad->exp.type)
{
case WPAD_EXP_NUNCHUK: case WPAD_EXP_NUNCHUK:
case WPAD_EXP_GUITARHERO3: js = stick ? NULL : &wpad->exp.nunchuk.js;
if (stick == 0)
{
mag = wpad->exp.nunchuk.js.mag;
ang = wpad->exp.nunchuk.js.ang;
}
break; break;
case WPAD_EXP_CLASSIC: case WPAD_EXP_CLASSIC:
if (stick == 0) js = stick ? &wpad->exp.classic.rjs : &wpad->exp.classic.ljs;
{
mag = wpad->exp.classic.ljs.mag;
ang = wpad->exp.classic.ljs.ang;
}
else
{
mag = wpad->exp.classic.rjs.mag;
ang = wpad->exp.classic.rjs.ang;
}
break; break;
default: default:
break; break;
} }
/* calculate x/y value (angle need to be converted into radian) */ if (js) {
if (mag > 1.0) mag = 1.0; int pos;
else if (mag < -1.0) mag = -1.0; int min;
double val; int max;
int center;
if(axis == 0) // x-axis if(axis == 1) {
val = mag * sin((PI * ang)/180.0f); pos = js->pos.y;
else // y-axis min = js->min.y;
val = mag * cos((PI * ang)/180.0f); max = js->max.y;
center = js->center.y;
}
else {
pos = js->pos.x;
min = js->min.x;
max = js->max.x;
center = js->center.x;
}
return (s8)(val * 128.0f); if (pos > max) return 127;
if (pos < min) return -128;
#else pos -= center;
return 0;
if (pos > 0) {
return (s8)(127.0 * ((float)pos / (float)(max - center)));
}
else {
return (s8)(128.0 * ((float)pos / (float)(center - min)));
}
}
#endif #endif
return 0;
} }
s8 GuiTrigger::WPAD_StickX(u8 stick) s8 GuiTrigger::WPAD_StickX(u8 stick)