On Thu, Aug 7, 2008 at 2:39 AM, flx <[EMAIL PROTECTED]> wrote: > I'm trying to make a foosball [1] game wth pygame, using the wiimote > to control the bars. > > I've managed to control the rotation using the accelerometers, but i > can't get the sliding part right. I've been asked to use the ir > sensors for the sliding movement, but I just can't get it right.
I think you have two separate questions here: * how to get IR working on the wiimote and get IR data * once IR is working, how to interpret the data to make the paddle slide around correctly For the first part: which Wiimote library are you using? Does it support IR? Is it buggy with your particular Wiimote/bluetooth combination? What operating system are you using? For the second part: I recommend making a simple program that just displays squares at the reported IR positions, setting the screen to 1024x768. Then try moving the Wiimote around and take notes about where the squares go. Where do they go when you slide left? What about when you point downwards? Rotate clockwise? Then use those notes to write code to control the paddle directly. You might need some calculations here (argh, math!). Once you've got this down you will have control of the paddle but it will be jerky and flickery. Also when you move too far to the edge of the screen the paddle will stop moving (one IR dot goes off screen). To fix the jerkiness, a first step is averaging several values over time. A better but harder approach is a Kalman filter. To fix the flickery problem: if there are 0 dots reported, use the most recent positions. That stops the input from disappearing for a frame. If there are too many dots (3 or more), then you want to pick the 2 dots closest to the last reported IR positions. To fix the edge-of-the-screen problem, a good approach I've used is to guess where the missing IR dot should be. I assume that the dot off the edge of the screen moves just like the one that remains on the screen. This won't be strictly true if the wiimote is rotating or changing distance to the sensor bar, but it will keep the paddle responding to input rather than stopping abruptly at the edge of the screen. FYI: I'm working on a pygame library that supports the wiimote on all platforms, it will be done Real Soon Now. -- Nathan Whitehead