IR Cursor Problems
June 17, 2009 05:01AM
Hello. I'm trying to get a cursor to display with GRRLIB and I'm having a problem with the DramImg to place the cursor the in the right spot (based off the IR). The pointer displays in the game, but at 0,0 while not moving to the Wiimote's IR data. Everything in the loop works correctly except for the pointer. Thanks for any help in advance.

//DECALRED EARLIER BEFORE LOOP.
WPAD_Init();
//THE LOOP GIVING ME THE PROBLEM.
while(1) 
	{
		WPAD_ScanPads();
		
		    //Wiimote 1
		u32 pressed1  = WPAD_ButtonsDown(0);  //For pressed buttons.
		u32 held1     = WPAD_ButtonsHeld(0);  //For held buttons.
		u32 released1 = WPAD_ButtonsUp(0);    //For realeased buttons.
       
			//Wiimote 2
		u32 pressed2  = WPAD_ButtonsDown(1);  //For pressed buttons.
		u32 held2     = WPAD_ButtonsHeld(1);  //For held buttons.
		u32 released2 = WPAD_ButtonsUp(1);    //For realeased buttons.
		
		GRRLIB_FillScreen(0xFFFFFFFF);
        
        GRRLIB_DrawImg( 0, 0, tex_menu, 0, 1, 1, 0xFFFFFFFF);
		
		    //IR Movement
		ir_t ir1, ir2;	
	
		WPAD_SetDataFormat(WPAD_CHAN_0, WPAD_FMT_BTNS_ACC_IR);
		WPAD_SetDataFormat(WPAD_CHAN_1, WPAD_FMT_BTNS_ACC_IR);
		
		WPAD_SetVRes(0, 640, 480);
		
		WPAD_IR(0, &ir1);           //For Wiimote 1 IR.
		WPAD_IR(1, &ir2);           //For Wiimote 2 IR.
		
		GRRLIB_DrawImg(ir1.x - 48, ir1.y - 45, tex_pointer1, 0, 1, 1, 0xFFFFFFFF);//<=========================
//		GRRLIB_DrawImg(ir2.x - 48, ir2.y - 45, tex_pointer2, 0, 1, 1, 0xFFFFFFFF);

        GRRLIB_Render();
		
		if ( ( (ir1.x >= 392) & (ir1.x <= 640) ) & ( (ir1.y >= 0) & (ir1.y <= 96) ) )
		{
			GRRLIB_DrawImg(392, 0, tex_menu_selection_1, 0, 1, 1, 0xFFFFFFFF);
			GRRLIB_Render();
		}

        if(pressed1 & WPAD_BUTTON_HOME) 
		{exit(0);}
    }
Re: IR Cursor Problems
June 17, 2009 05:57AM
why did you subtract by 48 and 45?
Re: IR Cursor Problems
June 17, 2009 03:43PM
Take a look there ;)
[forum.wiibrew.org]
Re: IR Cursor Problems
June 18, 2009 02:26AM
Quote
speewave
why did you subtract by 48 and 45?

To center the image on the tip of the finger and not the center of the image.

--

Also I already looked at that thread and I'm doing the same thing that person was doing, but the pointer doesn't move at all. I think the IR is not responding. But you also might be right, so I'll mess with it and see if I can get something going.



Edited 1 time(s). Last edit at 06/18/2009 02:37AM by TPAINROXX.
Re: IR Cursor Problems
June 18, 2009 03:52PM
You're resetting your wpad data format every frame. If you change that, you'll probably fix your problem.

You're resetting your data format after you call WPAD_ScanPads but before you call WPAD_IR() so I'm guessing that it's voiding out any IR data received.

Anyway, try taking


WPAD_SetDataFormat(WPAD_CHAN_0, WPAD_FMT_BTNS_ACC_IR);
WPAD_SetDataFormat(WPAD_CHAN_1, WPAD_FMT_BTNS_ACC_IR);
WPAD_SetVRes(0, 640, 480);

out of your while loop.



Edited 1 time(s). Last edit at 06/18/2009 05:50PM by MrPeanut.
Re: IR Cursor Problems
June 19, 2009 01:50AM
Well this is sorta odd..., but if I add a "debug mode" for the IR the cursor works right.

This is basically the debug.
while(1)
	{
		cout<<"ir1.x: "<<ir1.x<<"/tir1.y: "<<ir1.y<<"\n";
		
		GRRLIB_FillScreen(0x0000000F);
		
		WPAD_ScanPads();
		
		u32 held1_debug = WPAD_ButtonsHeld(0);
		
		if (held1_debug & WPAD_BUTTON_PLUS)
		{break;}
	}


It doesn't work for some reason, but it first displays my menu all messed up then the program does the intro correctly and displays the menu with the pointer working correctly. It's all very odd...
Sorry, only registered users may post in this forum.

Click here to login