Welcome! Log In Create A New Profile

Advanced

Updating png image based on Wiimote IR x y position

Posted by pcmantinker 
Updating png image based on Wiimote IR x y position
January 20, 2009 04:29AM
Hi,

I recently started wii programming and have some general knowledge of C++. I am trying to draw a cursor and update its x/y position with the wiimote IR x/y position. I followed the CodeMii tutorial on how to draw a point on the screen at the wiimote's position. The next thing I tried was implementing the GRRLib into my application so that I could load a cursor and display it at the wiimote's position. However, the program does not read the IR data at all. Here is my code which is a modified version of the GRRLib Day 5 tutorial:

/*===========================================
        GRRLIB (GX version) 3.0.1 alpha
        Code     : NoNameNo
        GX hints : RedShade

        [grrlib.santo.fr]
        Tutorial : Day 5 (Display an Image)
 ============================================*/

#include "GRRLIB/GRRLIB.h"

#include "gfx/logo.h"
#include "gfx/generic_point.h"

#include "GRRLIB/fonts/GRRLIB_font1.h"

Mtx GXmodelView2D;
ir_t ir;

int main(){
   u8 *tex_logo=GRRLIB_LoadTexture(logo);
   u8 *genpointer=GRRLIB_LoadTexture(generic_point);
   u8 *tex_font1=GRRLIB_LoadTexture(GRRLIB_font1);
   float rot=0;
   float alpha=255;
   float x=144;
   float y=176;
   

    VIDEO_Init();
    WPAD_Init();

    GRRLIB_InitVideo();
    GRRLIB_Start();


    while(1){
        WPAD_ScanPads();
		
	WPAD_IR(0, &ir);  
		
        u32 wpaddown = WPAD_ButtonsDown(0);
        u32 wpadheld = WPAD_ButtonsHeld(0);

        GRRLIB_FillScreen(0xFF000000);

        GRRLIB_DrawImg(x, y, 352, 128, tex_logo, rot, 1, 1, alpha );
		
	GRRLIB_Printf(50,50,tex_font1,0xFFFFFFFF,1,"x : %f n/ y: %f",ir.x, ir.y);
		
	GRRLIB_DrawImg(ir.x, ir.y, 96, 96, genpointer, 0, 1, 1, 255);
	
        GRRLIB_Plot(ir.x, ir.y,0xFFFFFFFF);

        GRRLIB_Render();

        if (wpaddown & WPAD_BUTTON_HOME) exit(0);
        if (wpadheld & WPAD_BUTTON_RIGHT) x+=2;//rot+=2;
        if (wpadheld & WPAD_BUTTON_LEFT) x-=2;//rot-=2;
		if (wpadheld & WPAD_BUTTON_UP) y-=2;
		if (wpadheld & WPAD_BUTTON_DOWN) y+=2;
        if (wpadheld & WPAD_BUTTON_MINUS) if((alpha-=3)<0) alpha=0;
        if (wpadheld & WPAD_BUTTON_PLUS) if((alpha+=3)>255) alpha=255;

    }
    return 0;
}

The standard includes are also there, but weren't displaying properly in the forum code tags. I made a debug GRRLib_Printf function to display the x and y position of the wiimote, but it doesn't update. I think that the program isn't reading the IR data. I tried displaying a point and also an image at the x/y position and it doesn't move when I move the wiimote. Any suggestions greatly appreciated.
Re: Updating png image based on Wiimote IR x y position
January 20, 2009 04:31AM
Do you intend to write a C application and use GRRLIB, or to write a C++ application and use libwiisprite?
Re: Updating png image based on Wiimote IR x y position
January 20, 2009 04:59AM
After WPAD_Init(), add these two lines:
WPAD_SetDataFormat(0, WPAD_FMT_BTNS_ACC_IR);
WPAD_SetVRes(0, 640, 480);
Those setup and configure the device to send IR data.
Re: Updating png image based on Wiimote IR x y position
January 20, 2009 05:12AM
Well, I would like to write a C++ application but I didn't know that GRRLIB wasn't compatible with C++. I will try libwiisprite and see what I can do with that.
Re: Updating png image based on Wiimote IR x y position
January 20, 2009 05:24AM
GRRLIB works with C++. Just include the GRRLIB.h like so:

extern "C" {
#include "GRRLIB.h"
}
Re: Updating png image based on Wiimote IR x y position
January 20, 2009 05:45AM
Thanks for the quick replies everyone. It's now working. The only question I have is broadening the range of the screen so that the cursor may be moved to the edges of the screen. Should I change the screen resolution or is 640x480 the standard Wii resolution?

Edit: It looks as though there is an offset. I will see about figuring that out. Or has someone already determined the offset?



Edited 1 time(s). Last edit at 01/20/2009 05:47AM by pcmantinker.
Re: Updating png image based on Wiimote IR x y position
January 21, 2009 10:02PM
I responsed in your other topic. Btw, 640*480 is the best resolution, try putting in your own offsets for getting the cursor completely offscreen.



Edited 1 time(s). Last edit at 01/28/2009 05:41PM by Dykam.
Re: Updating png image based on Wiimote IR x y position
January 22, 2009 07:09PM
in the article at [wiibrew.org]) he handles this more portably. To wit:

static GXRModeObj *rmode = NULL;
rmode = VIDEO_GetPreferredMode(NULL);
WPAD_SetVRes(0, rmode->fbWidth, rmode->xfbHeight);

This pulls the resolution from the Wii's internal settings, and will work on NTSC or PAL Wiis. arbitrarily setting it to 640x480 will make your program behave differently on PAL Wiis. Or perhaps it might not work at all, I don't have a PAL Wii to test with.
Re: Updating png image based on Wiimote IR x y position
January 24, 2009 05:41AM
That code seems to work much better. I am glad that my apps video settings can be compatible with any region Wii now. Thanks for the tip.



Edited 1 time(s). Last edit at 01/24/2009 05:42AM by pcmantinker.
Sorry, only registered users may post in this forum.

Click here to login