You are not logged in.

#1 2009-07-12 20:05:53

michelinok
Member

[RESOLVED] Problem using wiimote...

I've a strange problem...i cannot go with the cursor to the top of my tv using the wiimote...it stop 10cm. after the top, and very often the "motion" is not very clear (stops for some milliseconds...). here's my code:

Code:

#include "../../../GRRLIB/GRRLIB/GRRLIB.h"
#include <stdlib.h>
#include <wiiuse/wpad.h>
#include <gcmodplay.h>
#include "gfx/background.h"
#include "gfx/icona_mail.h"
#include "gfx/pointer.h"
#include "sound/elysium.h"

Mtx GXmodelView2D;

GRRLIB_texImg tex_background;
GRRLIB_texImg tex_pointer;
GRRLIB_texImg img_btn_mail;

MODPlay main_music;

int i;

void load_textures() {
    tex_background=GRRLIB_LoadTexture(background);
    tex_pointer=GRRLIB_LoadTexture(pointer);
    img_btn_mail=GRRLIB_LoadTexture(icona_mail);
}

void load_music() {
    MODPlay_Init(&main_music);
    MODPlay_SetMOD(&main_music, elysium);
    MODPlay_Start(&main_music);    
}


void draw_fadein_background() {
    for(i=0;i<=0xff;i+=2){
    GRRLIB_FillScreen(0x000000FF);
    GRRLIB_DrawImg(0, 0, tex_background, 0, 1, 1, 0xFFFFFF00|i);
    GRRLIB_Render();
    }

}

int main() {
    u32 wpaddown;
    ir_t ir;

    load_textures();
    GRRLIB_Init();    
    WPAD_Init();
    WPAD_SetDataFormat(WPAD_CHAN_0, WPAD_FMT_BTNS_ACC_IR);
    WPAD_SetVRes(0, 640, 480);
    
    load_music();    
    draw_fadein_background();
    

    while(1) {
        WPAD_ScanPads();
        wpaddown = WPAD_ButtonsDown(0);
        WPAD_IR(WPAD_CHAN_0, &ir);
        
        //Display the image
        GRRLIB_DrawImg(0, 0, tex_background, 0, 1, 1, 0xFFFFFFFF);
        GRRLIB_DrawImg(-70,-70, img_btn_mail, 0, 0.2, 0.2, 0x00FFFFFF);
        GRRLIB_DrawImg(ir.sx, ir.sy, tex_pointer, 0, 1, 1, 0xFFFFFFFF);
        GRRLIB_Render();
        VIDEO_WaitVSync();
        if(wpaddown & WPAD_BUTTON_HOME) {
            exit(0);
        }
    }

    // Be a good boy, clear the memory allocated by GRRLIB
    GRRLIB_Exit(); 
    free(tex_background.data);
    free(img_btn_mail.data);
    free(tex_pointer.data);
    MODPlay_Stop(&main_music);    
    
    
    return 0;
}

Any ideas?



I've the same problem with "lesson7"

Last edited by michelinok (2009-07-12 22:20:43)

Offline

 

#2 2009-07-13 02:06:26

Crayon
Bad Mother Fucker

Re: [RESOLVED] Problem using wiimote...

Hi, try to use ir.x and ir.y instead of ir.sx and ir.sy

Maybe this code could be helpful:

Code:

    if(ir.valid)
    {
        GRRLIB_DrawImg(ir.x, ir.y, tex_pointer, 0, 1, 1, 0xFFFFFFFF);
    }
    else
    {
         // Hide cursor
    }

Offline

 

#3 2009-07-13 08:18:39

michelinok
Member

Re: [RESOLVED] Problem using wiimote...

Crayon wrote:

Hi, try to use ir.x and ir.y instead of ir.sx and ir.sy

Maybe this code could be helpful:

Code:

    if(ir.valid)
    {
        GRRLIB_DrawImg(ir.x, ir.y, tex_pointer, 0, 1, 1, 0xFFFFFFFF);
    }
    else
    {
         // Hide cursor
    }

Same problem as befeore, plus the cursor is moving very "tremors" way...sometime vanishing for some milliseconds...

Offline

 

#4 2009-07-13 17:21:02

Crayon
Bad Mother Fucker

Re: [RESOLVED] Problem using wiimote...

Try this instead (might need some tweeking, it's not tested):

Code:

    if(ir.valid)
    {
        float XX = (ir.ir.x / 640 * (640 + tex_pointer.w * 2)) - tex_pointer.w;
        float YY = (ir.ir.y / 480 * (480 + tex_pointer.h * 2)) - tex_pointer.h;
        GRRLIB_DrawImg(XX, YY, tex_pointer, 0, 1, 1, 0xFFFFFFFF);
    }
    else
    {
         // Hide cursor
    }

In GRRLIB_DrawImg for the angle you might want to use ir.orient.roll

To set an hotpoint to your poiter try something like this

Code:

    tex_pointer=GRRLIB_LoadTexture(pointer);
    tex_pointer.offsetx = 48; // This value needs to change
    tex_pointer.offsety = 48; // This value needs to change
    GRRLIB_SetHandle(tex_pointer, tex_pointer.offsetx, tex_pointer.offsety);

Offline

 

#5 2009-07-13 19:53:17

michelinok
Member

Re: [RESOLVED] Problem using wiimote...

Crayon wrote:

Try this instead (might need some tweeking, it's not tested):

Code:

    if(ir.valid)
    {
        float XX = (ir.ir.x / 640 * (640 + tex_pointer.w * 2)) - tex_pointer.w;
        float YY = (ir.ir.y / 480 * (480 + tex_pointer.h * 2)) - tex_pointer.h;
        GRRLIB_DrawImg(XX, YY, tex_pointer, 0, 1, 1, 0xFFFFFFFF);
    }
    else
    {
         // Hide cursor
    }

In GRRLIB_DrawImg for the angle you might want to use ir.orient.roll

To set an hotpoint to your poiter try something like this

Code:

    tex_pointer=GRRLIB_LoadTexture(pointer);
    tex_pointer.offsetx = 48; // This value needs to change
    tex_pointer.offsety = 48; // This value needs to change
    GRRLIB_SetHandle(tex_pointer, tex_pointer.offsetx, tex_pointer.offsety);

Great!,just implemented the first portion of code and works perfectly!
Just one more question... why if i enable the vsync in my code, the pointer is not very accurate during the movements?
Can you explain the story about "hotpoint"? It's a little cryptic for me smile

PS: Sorry for my english!

Offline

 

#6 2009-07-13 20:38:50

Crayon
Bad Mother Fucker

Re: [RESOLVED] Problem using wiimote...

michelinok wrote:

Can you explain the story about "hotpoint"? It's a little cryptic for me smile

The hot spot of a cursor is the point to which the screen refers in tracking the cursor's position. By default, the hot spot is set to the upper-left corner of the cursor (coordinates 0,0).
So let say you are using the famous finger pointer, you need to set the hot spot at the top of the finger. So open your image file and check the coordinates of the finger (in pixel) and set offsetx & offsety to that offset.

If you don't understand what I'm saying, maybe this link would help: http://msdn.microsoft.com/en-us/library … e_Hot_Spot

Offline

 

Board footer

Powered by FluxBB