From 3f6925dc8a41ce065e31d08d93ffd07328d5dc1b Mon Sep 17 00:00:00 2001 From: ekeeke31 Date: Tue, 21 Apr 2009 15:20:15 +0000 Subject: [PATCH] + improved Mouse emulation (fixed buttons, use Wiimote orientation to calculate absolute quantity of movement) + fixed menu pointer orientation --- source/gen_input.c | 4 ++-- source/gx/gui/filesel.c | 13 +++++++---- source/gx/gui/menu.c | 8 +++++-- source/gx/gx_input.c | 52 +++++++++++++++++++++++++---------------- source/gx/gx_input.h | 3 --- 5 files changed, 48 insertions(+), 32 deletions(-) diff --git a/source/gen_input.c b/source/gen_input.c index 409c86a..3098cd5 100644 --- a/source/gen_input.c +++ b/source/gen_input.c @@ -211,8 +211,8 @@ uint32 mouse_read() case 5: /* Buttons state */ if (input.pad[mouse.Port] & INPUT_A) temp |= 0x01; - if (input.pad[mouse.Port] & INPUT_B) temp |= 0x02; - if (input.pad[mouse.Port] & INPUT_C) temp |= 0x04; + if (input.pad[mouse.Port] & INPUT_C) temp |= 0x02; + if (input.pad[mouse.Port] & INPUT_B) temp |= 0x04; if (input.pad[mouse.Port] & INPUT_START) temp |= 0x08; break; diff --git a/source/gx/gui/filesel.c b/source/gx/gui/filesel.c index 32b8ac4..e54a57e 100644 --- a/source/gx/gui/filesel.c +++ b/source/gx/gui/filesel.c @@ -162,10 +162,6 @@ int FileSortCallback(const void *f1, const void *f2) ****************************************************************************/ int FileSelector(unsigned char *buffer) { -#ifdef HW_RVL - int x,y; - gui_butn *button; -#endif short p; int ret,i,yoffset,string_offset; int go_up = 0; @@ -174,6 +170,12 @@ int FileSelector(unsigned char *buffer) char fname[MAXPATHLEN]; FILE *xml,*snap; +#ifdef HW_RVL + int x,y; + gui_butn *button; + struct orient_t orient; +#endif + /* Initialize Menu */ gui_menu *m = &menu_browser; GUI_InitMenu(m); @@ -295,7 +297,8 @@ int FileSelector(unsigned char *buffer) y = m_input.ir.y; /* draw wiimote pointer */ - gxResetAngle(m_input.ir.angle); + WPAD_Orientation(0,&orient); + gxResetAngle(orient.roll); gxDrawTexture(w_pointer, x-w_pointer->width/2, y-w_pointer->height/2, w_pointer->width, w_pointer->height,255); gxResetAngle(0.0); diff --git a/source/gx/gui/menu.c b/source/gx/gui/menu.c index 13f185b..226ea93 100644 --- a/source/gx/gui/menu.c +++ b/source/gx/gui/menu.c @@ -714,6 +714,7 @@ int GUI_WindowPrompt(gui_menu *parent, char *title, char *items[], u8 nb_items) #ifdef HW_RVL int x,y; + struct orient_t orient; #endif /* initialize data */ @@ -817,7 +818,8 @@ int GUI_WindowPrompt(gui_menu *parent, char *title, char *items[], u8 nb_items) y = m_input.ir.y; /* draw wiimote pointer */ - gxResetAngle(m_input.ir.angle); + WPAD_Orientation(0,&orient); + gxResetAngle(orient.roll); gxDrawTexture(w_pointer,x-w_pointer->width/2,y-w_pointer->height/2,w_pointer->width,w_pointer->height,255); gxResetAngle(0.0); @@ -943,6 +945,7 @@ int GUI_RunMenu(gui_menu *menu) #ifdef HW_RVL int i,x,y; + struct orient_t orient; #endif @@ -966,7 +969,8 @@ int GUI_RunMenu(gui_menu *menu) y = m_input.ir.y; /* draw wiimote pointer */ - gxResetAngle(m_input.ir.angle); + WPAD_Orientation(0,&orient); + gxResetAngle(orient.roll); gxDrawTexture(w_pointer, x-w_pointer->width/2, y-w_pointer->height/2, w_pointer->width, w_pointer->height,255); gxResetAngle(0.0); diff --git a/source/gx/gx_input.c b/source/gx/gx_input.c index c7cc2dd..4a2a049 100644 --- a/source/gx/gx_input.c +++ b/source/gx/gx_input.c @@ -242,9 +242,7 @@ static void pad_update(s8 num, u8 i) *******************************/ #ifdef HW_RVL -#define PI 3.14159265f - -s8 WPAD_StickX(u8 chan,u8 right) +static s8 WPAD_StickX(u8 chan,u8 right) { float mag = 0.0; float ang = 0.0; @@ -281,13 +279,13 @@ s8 WPAD_StickX(u8 chan,u8 right) /* calculate X value (angle need to be converted into radian) */ if (mag > 1.0) mag = 1.0; else if (mag < -1.0) mag = -1.0; - double val = mag * sin(PI * ang/180.0f); + double val = mag * sin(M_PI * ang/180.0f); return (s8)(val * 128.0f); } -s8 WPAD_StickY(u8 chan, u8 right) +static s8 WPAD_StickY(u8 chan, u8 right) { float mag = 0.0; float ang = 0.0; @@ -324,7 +322,7 @@ s8 WPAD_StickY(u8 chan, u8 right) /* calculate X value (angle need to be converted into radian) */ if (mag > 1.0) mag = 1.0; else if (mag < -1.0) mag = -1.0; - double val = mag * cos(PI * ang/180.0f); + double val = mag * cos(M_PI * ang/180.0f); return (s8)(val * 128.0f); } @@ -394,8 +392,8 @@ static void wpad_config(u8 num, u8 exp, u8 padtype) } } -float old_x = 0.0; -float old_y = 0.0; +/*float old_x = 0.0; +float old_y = 0.0;*/ static void wpad_update(s8 num, u8 i, u32 exp) { @@ -412,6 +410,9 @@ static void wpad_update(s8 num, u8 i, u32 exp) y = WPAD_StickY(num,0); } + /* IR structure */ + struct ir_t ir; + /* retrieve current key mapping */ u32 *wpad_keymap = config.wpad_keymap[exp + (3 * num)]; @@ -446,7 +447,6 @@ static void wpad_update(s8 num, u8 i, u32 exp) if (exp != WPAD_EXP_CLASSIC) { /* wiimote IR */ - struct ir_t ir; WPAD_IR(num, &ir); if (ir.valid) { @@ -474,7 +474,6 @@ static void wpad_update(s8 num, u8 i, u32 exp) if (exp != WPAD_EXP_CLASSIC) { /* wiimote IR */ - struct ir_t ir; WPAD_IR(num, &ir); if (ir.valid) { @@ -485,21 +484,30 @@ static void wpad_update(s8 num, u8 i, u32 exp) } } - /* MOUSE quantity of movement (-256,256) */ + /* MOUSE quantity of movement (-255,255) */ else if (input.dev[i] == DEVICE_MOUSE) { - /* analog stick */ - input.analog[2][0] = x * 2 / sensitivity; - input.analog[2][1] = 0 - y * 2 / sensitivity; + /* by default, use analog stick values */ + input.analog[2][0] = (x * 2) / sensitivity; + input.analog[2][1] = - (y * 2) / sensitivity; if (exp != WPAD_EXP_CLASSIC) { /* wiimote IR */ - struct ir_t ir; WPAD_IR(num, &ir); if (ir.valid) { - input.analog[2][0] = ir.x - old_x; + /* get wiimote orientation */ + struct orient_t orient; + WPAD_Orientation(num,&orient); + + /* horizontal axis (yaw is between -180 and 180 degrees) */ + input.analog[2][0] = ((int)orient.yaw * 255) / 90; + + /* vertical axis (pitch is between -180 and 180 degrees) */ + input.analog[2][1] = ((int)orient.pitch * 255) / 90; + + /*input.analog[2][0] = ir.x - old_x; if (input.analog[2][0] > 256) { input.analog[2][0] = 256; @@ -529,19 +537,23 @@ static void wpad_update(s8 num, u8 i, u32 exp) else { old_y = ir.y; - } + }*/ if (p & WPAD_BUTTON_B) input.pad[i] |= INPUT_B; } - else +/* else { old_x += input.analog[2][0]; old_y += input.analog[2][1]; } +*/ } - if (!config.invert_mouse) input.analog[2][1] = 0 - input.analog[2][1]; - + /* Invert Y coordinate */ + if (!config.invert_mouse) + { + input.analog[2][1] = -input.analog[2][1]; + } } /* GAMEPAD directional buttons */ diff --git a/source/gx/gx_input.h b/source/gx/gx_input.h index 7706deb..f4be9bf 100644 --- a/source/gx/gx_input.h +++ b/source/gx/gx_input.h @@ -52,7 +52,4 @@ extern void gx_input_config(u8 num, u8 type, u8 padtype); extern void gx_input_updateEmu(void); extern void gx_input_updateMenu(u32 cnt); -extern s8 WPAD_StickX(u8 chan,u8 right); -extern s8 WPAD_StickY(u8 chan,u8 right); - #endif