Welcome! Log In Create A New Profile

Advanced

Ir resolution shifted off screen?

Posted by noob 
Ir resolution shifted off screen?
March 15, 2009 07:49AM
Greetings,

I'm making a basic pointer app using devkitpro and grrlib, but I have a problem.

My ir resolution is shifted right and down and goes off the screen. Anyone have a way to fix this?

(its the same if I just give it a set resoluton such as 640 x 480)

#include "GRRLIB.h"

#include 
#include 

#include "GFX/pointer.h"
#include "GFX/background.h"
#include "GFX/font3.h"

ir_t ir;
orient_t orient;

static u32 *xfb;
static GXRModeObj *rmode;

Mtx GXmodelView2D;

int main() {

	u32 pressed;
	
	GRRLIB_Init();
	WPAD_Init();
	
	rmode = VIDEO_GetPreferredMode(NULL);
	xfb = MEM_K0_TO_K1(SYS_AllocateFramebuffer(rmode));
	WPAD_SetVRes(WPAD_CHAN_ALL, rmode->fbWidth, rmode->xfbHeight);
	
	WPAD_SetDataFormat(WPAD_CHAN_ALL, WPAD_FMT_BTNS_ACC_IR);
	
	GRRLIB_texImg tex_bg = GRRLIB_LoadTexture(background);	
	GRRLIB_texImg tex_pointer = GRRLIB_LoadTexture(pointer);
	
	GRRLIB_texImg tex_font3 = GRRLIB_LoadTexture(font3);
	GRRLIB_InitTileSet(&tex_font3, 32, 32, 32);
	
	int centered = tex_pointer.w/2;
	int right = rmode->fbWidth-(7*32);
	
	while(1) {
		
		//Wiimote
		WPAD_ScanPads();
		pressed = WPAD_ButtonsDown(WPAD_CHAN_0);
		
		//Background
		GRRLIB_FillScreen(0x000000FF);
		GRRLIB_DrawImg(0, 0, tex_bg, 0, 1, 1, 0xFFFFFFFF);
		
		//Wiimote IR
		WPAD_IR(WPAD_CHAN_0, &ir);
		if(ir.valid){
			GRRLIB_Printf(right, 68, tex_font3, 0xFFFFFFFF, 1, "X:%d", (int)ir.x);
			GRRLIB_Printf(right, 100, tex_font3, 0xFFFFFFFF, 1, "Y:%d", (int)ir.y);
		}
		
		//Wiimote Rotation
		WPAD_Orientation(WPAD_CHAN_0, &orient);
		GRRLIB_Printf(right, 34, tex_font3, 0xFFFFFFFF, 1, "R:%d", (int)orient.roll);

		//Draw Pointer
		GRRLIB_DrawImg(ir.sx-centered, ir.sy-centered, tex_pointer, orient.roll, 1, 1, 0xFFFFFFFF);
		
		//Render
		GRRLIB_Render();
		
		//Exit to loader
		if (pressed & WPAD_BUTTON_HOME) {
			exit(0);
		}
						
	}

	GRRLIB_Exit();
	free(tex_pointer.data);
	free(tex_bg.data);
	free(tex_font3.data);
	return 0;
}



Edited 3 time(s). Last edit at 03/15/2009 09:21AM by noob.
Re: Ir resolution shifted off screen?
March 15, 2009 10:08AM
ir.sx-200, ir.sy-250

That should give you good values.

There is also a way to set the ir range with
unsigned int vres[2];
int offset[2];

so you could do
int vres[2];
vres[0] = 640;
vres[1] = 480;
ir.vres =vres;

And adjust offset the same way.
Re: Ir resolution shifted off screen?
March 16, 2009 02:48PM
I once had a similar issue, had to implement ir correction, etc. The end solution is not to use ir.sx/sy and rather just use ir.x/y. Works fine.



Edited 1 time(s). Last edit at 03/16/2009 02:49PM by teknecal.
Sorry, only registered users may post in this forum.

Click here to login