views:

23

answers:

2

I am currently working on a tool that will allow Wiimote to be used as computer mouse and am stuck in a problem. The wiimote returns x and y co-ordinates which are very small as compared to screen resolution of my pc and I am looking for a way to map these small values to my large resolution values.

For example, pc least x value is 0 and most x value is 1300 and I also know wiimote least x value is 0 but don't know most value.

I just want the wiimote to move mouse pointer on screen without crossing the screen co-ordinates.

+2  A: 

Large Maximum / Small Maximum * Small Value = Large Value

James Hulse
I need to try this.
Umair Ashraf
From what I can tell it is a simple ratio. You're large value ranges from 0 - 1300 and the small one may be 0 - 100. So say you want to find where in the large value the small value 50 lies you would do:1300 / 100 * 50 = 650
James Hulse
This works only if you know the upper bounds of both systems. Umair Ashraf told that he doesn't know the max value for the wiimote
Johann Blais
A: 

Your problem is actually different than what you think it is. I don't actually have a Wiimote (such a screwy name..) but I'd assume it returns distance as opposed to position. So what you have to do is have a cursor position:

Point pt=new Point(Width/2, Height/2);
// initialized in the center of the screen

and every time you receive an update event, you add the distance to your point:

// say you get the distance in dx and dy
pt.x=Math.Max(0,Math.Min(Width,pt.x+dx*sx));  // clamped on screen
pt.y=Math.Max(0,Math.Min(Height,pt.y+dy*sy)); // clamped on screen
// and update your UI acordingly

where sx and sy are scaling values for the X and Y coordonates. Start with 1.0 for each and play around until you get the movement rate you want.

Blindy
I think I failed to convey the problem. Say for example I have two rectangles, one of size (200,200) an other of size (400,400) now what wiimote returns is for size (400,400) but my screen is (200,200) and if wiimote returns 379 which is under the size of rectangle (400,400) but outside (200,200), here I need a mechanism to convert values from large to small rectangles or vice versa.
Umair Ashraf