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: WPF