Calibrating offset for wiimote cursor January 21, 2009 09:18PM | Registered: 15 years ago Posts: 31 |
#include#include #include #include #include #include #include #include #include #include "GRRLIB/GRRLIB.h" #include "gfx/logo.h" #include "gfx/player1_point.h" #include "gfx/player1_grab.h" #include "gfx/player1_openhand.h" #include "GRRLIB/fonts/GRRLIB_font1.h" #define screenwidth (640) #define screenheight (480) void displayCursor(); void WiiResetPressed(); void WiiPowerPressed(); void WiimotePowerPressed(s32 chan); Mtx GXmodelView2D; GXRModeObj *rmode = NULL; bool displaypointer = true; bool displaygrab = false; bool displayopenhand = false; int fullOFFSET = 104; ir_t ir1; u8 HWButton = 0; int main(){ u8 *tex_logo=GRRLIB_LoadTexture(logo); u8 *p1pointer=GRRLIB_LoadTexture(player1_point); u8 *p1grab=GRRLIB_LoadTexture(player1_grab); u8 *p1openhand=GRRLIB_LoadTexture(player1_openhand); u8 *tex_font1=GRRLIB_LoadTexture(GRRLIB_font1); float rot=0; float alpha=255; int x=0; int y=0; int X_OFFSET = 0; int Y_OFFSET = 0; // Init video layer VIDEO_Init(); // Init wiimote layer WPAD_Init(); WPAD_SetIdleTimeout(120); // Wiimote is shutdown after 2 minutes of innactivity. WPAD_SetDataFormat(0, WPAD_FMT_BTNS_ACC_IR); // enable accelerometers and IR WPAD_SetVRes(0, 640, 480); // Obtain the preferred video mode from the system // This will correspond to the settings in the Wii menu rmode = VIDEO_GetPreferredMode(NULL); // Set up the video registers with the chosen mode VIDEO_Configure(rmode); //Make the display visible VIDEO_SetBlack(FALSE); // Flush the video register changes to the hardware VIDEO_Flush(); WPAD_Init(); GRRLIB_InitVideo(); GRRLIB_Start(); while(1){ WPAD_ScanPads(); WPAD_IR(0, &ir1); x=ir1.x; y=ir1.y; u32 wpaddown = WPAD_ButtonsDown(0); u32 wpadheld = WPAD_ButtonsHeld(0); u32 wpadup = WPAD_ButtonsUp(0); SYS_SetResetCallback(WiiResetPressed); SYS_SetPowerCallback(WiiPowerPressed); GRRLIB_FillScreen(0xFF000000); GRRLIB_DrawImg(144, 176, 352, 128, tex_logo, rot, 1, 1, alpha ); if(x==0) { X_OFFSET = -82; } if(x<=screenwidth && x>=screenwidth - 5) { X_OFFSET = -22; } if(y==0) { Y_OFFSET = -82; } if(y<=screenheight && y>=screenheight - 5) { Y_OFFSET = -48; } GRRLIB_Printf(50,30,tex_font1,0xFFFFFFFF,1,"x oset: i% y oset: %1", X_OFFSET, Y_OFFSET); GRRLIB_Printf(50,50,tex_font1,0xFFFFFFFF,1,"wii x : %i wii y: %i", x, y); GRRLIB_Printf(50,70,tex_font1,0xFFFFFFFF,1,"scrn x : %i scrn y: %i", x + X_OFFSET, y + Y_OFFSET); // check icon display states if (displaypointer) { GRRLIB_DrawImg(x + X_OFFSET, y + Y_OFFSET, 96, 96, p1pointer, ir1.angle, 1, 1, 255 ); } if (displaygrab) { GRRLIB_DrawImg(x + X_OFFSET, y + Y_OFFSET, 96, 96, p1grab, ir1.angle, 1, 1, 255 ); } if (displayopenhand) { GRRLIB_DrawImg(x+ X_OFFSET, y + Y_OFFSET, 96, 96, p1openhand, ir1.angle, 1, 1, 255 ); } GRRLIB_Render(); if (wpadup & WPAD_BUTTON_A) { displaypointer = true; displayopenhand = false; displaygrab = false; } if (wpadup & WPAD_BUTTON_B) { displaypointer = true; displayopenhand = false; displaygrab = false; } if (wpaddown & WPAD_BUTTON_A) { displaypointer = false; displayopenhand = false; displaygrab = true; } if (wpaddown & WPAD_BUTTON_B) { displaypointer = false; displayopenhand = true; displaygrab = false; } if (wpaddown & WPAD_BUTTON_HOME) exit(0); if (wpaddown & WPAD_BUTTON_RIGHT) X_OFFSET+=2;//rot+=2; if (wpaddown & WPAD_BUTTON_LEFT) X_OFFSET-=2;//rot-=2; if (wpaddown & WPAD_BUTTON_UP) Y_OFFSET-=2; if (wpaddown & WPAD_BUTTON_DOWN) Y_OFFSET+=2; if (wpadheld & WPAD_BUTTON_MINUS) if((alpha-=3)<0) alpha=0; if (wpadheld & WPAD_BUTTON_PLUS) if((alpha+=3)>255) alpha=255; if(HWButton) break; } if(HWButton) { SYS_ResetSystem(HWButton, 0, 0); } return 0; } /** * Callback for the reset button on the Wii. */ void WiiResetPressed() { HWButton = SYS_RETURNTOMENU; } /** * Callback for the power button on the Wii. */ void WiiPowerPressed() { HWButton = SYS_POWEROFF; } /** * Callback for the power button on the Wiimote. * @param[in] chan The Wiimote that pressed the button */ void WiimotePowerPressed(s32 chan) { HWButton = SYS_POWEROFF; }
Re: Calibrating offset for wiimote cursor January 21, 2009 09:58PM | Registered: 15 years ago Posts: 109 |
Re: Calibrating offset for wiimote cursor January 22, 2009 12:50AM | Registered: 15 years ago Posts: 31 |