Welcome! Log In Create A New Profile

Advanced

Reading ir input / multiple wiimotes

Posted by melw 
Reading ir input / multiple wiimotes
November 16, 2008 10:40PM
Ok, I've been banging my head against the wall for the whole day, been going through libogc headers, searching for code examples and using wiibrew/google to find some answers but I still didn't get this working:

So, how to read ir input properly for 2nd, 3rd and 4th wiimote? While scanning for buttons seems to work I can get a ir reading for second wiimote at all. Current code for reading the wiimote input follows:

WPAD_ReadPending(WPAD_CHAN_ALL, countevs);
u32 type;
for(int i=0;i<4;i++)
{
	int res = WPAD_Probe(i, &type);

	if(res == WPAD_ERR_NONE)
	{
		wd = WPAD_Data(i);
		if(wd->btns_h & WPAD_BUTTON_1) doreload=1;
		// other button handling here like above, works as should
		// ...
		
		// ir works only for wiimote 1
		if(wd->ir.valid)
		{
			// draw test dot straight to texture
			float theta = wd->ir.angle / 180.0 * 3.1415;
			drawdot((u8*)texture, vmode, vmode->fbWidth, vmode->xfbHeight, wd->ir.x, wd->ir.y, RGBToColor(255, 0, 0));
			drawdot((u8*)texture, vmode, vmode->fbWidth, vmode->xfbHeight, wd->ir.x + 10*sinf(theta), wd->ir.y - 10*cosf(theta), RGBToColor(0, 0, 255));
		}
	}
}

Any help and/or tips are welcome. Thanks!
Re: Reading ir input / multiple wiimotes
November 16, 2008 10:45PM
Make sure you've done this
WPAD_SetDataFormat(WPAD_CHAN_0, WPAD_FMT_BTNS_ACC_IR);
WPAD_SetDataFormat(WPAD_CHAN_1, WPAD_FMT_BTNS_ACC_IR);
WPAD_SetDataFormat(WPAD_CHAN_2, WPAD_FMT_BTNS_ACC_IR);
WPAD_SetDataFormat(WPAD_CHAN_3, WPAD_FMT_BTNS_ACC_IR);

to initialise IR mode on all 4 wiimotes

Then I do this to get the data
		WPAD_ScanPads();
		WPAD_IR(WPAD_CHAN_0, ¤tCursorLocation);
		[snip - wiimote 1 IR]
		WPAD_IR(WPAD_CHAN_1, ¤tCursorLocation);
		[snip - wiimote 2 IR]
		WPAD_IR(WPAD_CHAN_2, ¤tCursorLocation);
		[snip - wiimote 3 IR]
		WPAD_IR(WPAD_CHAN_3, ¤tCursorLocation);
		[snip - wiimote 4 IR]
Re: Reading ir input / multiple wiimotes
November 16, 2008 11:32PM
Alternatively I do this for 2 wiimotes, but it works the same if you add more:

I do this outside the main loop:
	WPAD_SetDataFormat(WPAD_CHAN_ALL, WPAD_FMT_BTNS_ACC_IR);

	WPAD_SetVRes(WPAD_CHAN_ALL, rmode->fbWidth, rmode->xfbHeight);

Then this inside the main loop:-
		WPAD_ScanPads();
		u32 wpad_one_down = WPAD_ButtonsDown(0);
		u32 wpad_two_down = WPAD_ButtonsDown(1);

		u32 type;
		WPADData *wd_one, *wd_two;
		WPAD_ReadPending(WPAD_CHAN_ALL, countevs);
		WPAD_Probe(WPAD_CHAN_ALL, &type);

		wd_one = WPAD_Data(0);
		wd_two = WPAD_Data(1);

Then you can do the likes of:
		if(wd_one->ir.valid) {
			GRRLIB_DrawColImg(wd_one->ir.x - 9,wd_one->ir.y - 7,68,80,tex_ptrone,0,1,1,0xEEFFFFFF);
		}

		if(wd_two->ir.valid) {
			GRRLIB_DrawColImg(wd_two->ir.x - 9,wd_two->ir.y - 7,68,80,tex_ptrtwo,0,1,1,0xEEFFFFFF);
		}
Re: Reading ir input / multiple wiimotes
November 17, 2008 09:23AM
I had WPAD_SetDataFormat() only for WPAD_CHAN_0, after changing the init as following everything started working:

WPAD_SetDataFormat(WPAD_CHAN_ALL, WPAD_FMT_BTNS_ACC_IR);
WPAD_SetVRes(WPAD_CHAN_ALL, rmode->fbWidth, rmode->xfbHeight);

Thanks for the help, guys. Now I can enjoy full wiimote support. :)
Sorry, only registered users may post in this forum.

Click here to login