Having more fun with the Wii - Rudi Grobler
Thursday, February 14, 2008 1:41 PM rudi

Having more fun with the Wii

After my first attempt to connect the Wii and WPF I started working on improving it!

My infrared light was working but I needed something better so I opened 2 more remotes and removed their IR lights (Thy are also noticeably larger than my first IR light). I added a 120ohm resistor (To increase the brightness) for each led and reconnected it to my battery pack. Now I have 2 supper bright IR leds. To test if it work, use a standard video camera and turn off the light. You should then see them shine!

Here is a simple schematic of my lights

 

PS. please don't laugh at my over simplified schematic!

Next up is some code improvements. Because I am not doing multi touch, I decided to try and move my actual cursor. This all happens with the magic of P/Invoke!

[DllImport("user32.dll")]
static extern bool SetCursorPos(int x, int y);

The only time we can call SetCursorPos is from within the callback that the WiimoteLib does when something changes.

void wm_WiimoteChanged(object sender, WiimoteChangedEventArgs args)
{
    SetCursorPos((int)(ActualWidth-(wm.WiimoteState.IRState.X1 * ActualWidth)), (int)(wm.WiimoteState.IRState.Y1 * ActualHeight));
}

One last thing to notice is that the Y axis works normally but the X axis gets inverted! This just ensures that when you move the remote to your right the mouse pointer moves to the correct side! I also created a inverted NormalizedXYConverter to ensure that the horizontal bar also moves in the correct direction!

Now that my Wii remote moves the cursor I can make buttons animate by checking if the cursor moves over them although it gets controlled by the Wii remote!

Very cool...

 [UPDATE] If you want to see a very cool use of the Wii remote, have a look at the following Coding4Fun post about using the Wii remote as drum sticks!!!

Filed under:

Comments

# Having more fun with the Wii

Thursday, February 14, 2008 2:06 PM by DotNetKicks.com

You've been kicked (a good thing) - Trackback from DotNetKicks.com

# re: Having more fun with the Wii

Friday, February 15, 2008 5:53 PM by Craig Nicholson

I like where you are going with this. How about you design us a new presentation pointer for talks? ;)

# re: Having more fun with the Wii

Monday, February 18, 2008 2:37 PM by Matthias Shapiro

A note for those of us who are a little slow on these things...You need to add the following reference (if you're working in C#):

using System.Runtime.InteropServices;

# re: Having more fun with the Wii

Monday, February 18, 2008 2:44 PM by rudi

Yes, sorry!

the mouse move stuff relies on P/Invoke and thus you need the Interop stuff!!

Regards,

Rudi Grobler

# Having a Wii bit of fun... - Rudi Grobler

Tuesday, February 19, 2008 1:28 PM by Having a Wii bit of fun... - Rudi Grobler

Pingback from  Having a Wii bit of fun... - Rudi Grobler