public void warp(float srcX, float srcY, ref float dstX, ref float dstY) { if (dirty) { computeWarp(); } Warper.warp(warpMat, srcX, srcY, ref dstX, ref dstY); }
public void warp(PointF src, ref PointF dst) { if (dirty) { computeWarp(); } Warper.warp(warpMat, src, ref dst); }
void wm_OnWiimoteChanged(object sender, WiimoteChangedEventArgs args) { mut.WaitOne(); //extract the wiimote state WiimoteState ws = args.WiimoteState; if (ws.IRState.Found1) { int x = ws.IRState.RawX1; int y = ws.IRState.RawY1; float warpedX = x; float warpedY = y; warper.warp(x, y, ref warpedX, ref warpedY); smoothingBuffer[smoothingBufferIndex % smoothingBufferSize].X = warpedX; smoothingBuffer[smoothingBufferIndex % smoothingBufferSize].Y = warpedY; smoothingBufferIndex++; if (!lastWiiState.IRState.Found1)//mouse down { lastWiiState.IRState.Found1 = ws.IRState.Found1; smoothingBufferIndex = 0;//resets the count if (cursorControl) { INPUT[] buffer = new INPUT[2]; buffer[0].type = INPUT_MOUSE; buffer[0].mi.dx = (int)(warpedX * 65535.0f / screenWidth); buffer[0].mi.dy = (int)(warpedY * 65535.0f / screenHeight); buffer[0].mi.mouseData = 0; buffer[0].mi.dwFlags = MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_MOVE; buffer[0].mi.time = 0; buffer[0].mi.dwExtraInfo = (IntPtr)0; buffer[1].type = INPUT_MOUSE; buffer[1].mi.dx = 0; buffer[1].mi.dy = 0; buffer[1].mi.mouseData = 0; buffer[1].mi.dwFlags = MOUSEEVENTF_LEFTDOWN; buffer[1].mi.time = 1; buffer[1].mi.dwExtraInfo = (IntPtr)0; SendInput(2, buffer, Marshal.SizeOf(buffer[0])); }//cusor control switch (calibrationState) { case 1: srcX[calibrationState - 1] = x; srcY[calibrationState - 1] = y; calibrationState = 2; doCalibration(); break; case 2: srcX[calibrationState - 1] = x; srcY[calibrationState - 1] = y; calibrationState = 3; doCalibration(); break; case 3: srcX[calibrationState - 1] = x; srcY[calibrationState - 1] = y; calibrationState = 4; doCalibration(); break; case 4: srcX[calibrationState - 1] = x; srcY[calibrationState - 1] = y; calibrationState = 5; doCalibration(); break; default: break; } //calibtation state } //mouse down else { if (cursorControl)//dragging { INPUT[] buffer = new INPUT[1]; buffer[0].type = INPUT_MOUSE; if (enableSmoothing) { PointF s = getSmoothedCursor(smoothingAmount); buffer[0].mi.dx = (int)(s.X * 65535.0f / screenWidth); buffer[0].mi.dy = (int)(s.Y * 65535.0f / screenHeight); } else { buffer[0].mi.dx = (int)(warpedX * 65535.0f / screenWidth); buffer[0].mi.dy = (int)(warpedY * 65535.0f / screenHeight); } buffer[0].mi.mouseData = 0; buffer[0].mi.dwFlags = MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_MOVE; buffer[0].mi.time = 0; buffer[0].mi.dwExtraInfo = (IntPtr)0; SendInput(1, buffer, Marshal.SizeOf(buffer[0])); } } }//ir visible else { if (lastWiiState.IRState.Found1)//mouse up { lastWiiState.IRState.Found1 = ws.IRState.Found1; if (cursorControl) { INPUT[] buffer = new INPUT[2]; buffer[0].type = INPUT_MOUSE; buffer[0].mi.dx = 0; buffer[0].mi.dy = 0; buffer[0].mi.mouseData = 0; buffer[0].mi.dwFlags = MOUSEEVENTF_LEFTUP; buffer[0].mi.time = 0; buffer[0].mi.dwExtraInfo = (IntPtr)0; buffer[1].type = INPUT_MOUSE; buffer[1].mi.dx = 0; buffer[1].mi.dy = 0; buffer[1].mi.mouseData = 0; buffer[1].mi.dwFlags = MOUSEEVENTF_MOVE; buffer[1].mi.time = 0; buffer[1].mi.dwExtraInfo = (IntPtr)0; SendInput(2, buffer, Marshal.SizeOf(buffer[0])); } }//ir lost } if (!lastWiiState.ButtonState.A && ws.ButtonState.A) { BeginInvoke((MethodInvoker) delegate() { btnCalibrate.PerformClick(); }); } lastWiiState.ButtonState.A = ws.ButtonState.A; if (!lastWiiState.ButtonState.B && ws.ButtonState.B) { keybd_event(VK_SPACE, 0x45, 0, 0); } if (lastWiiState.ButtonState.B && !ws.ButtonState.B) { keybd_event(VK_SPACE, 0x45, KEYEVENTF_KEYUP, 0); } lastWiiState.ButtonState.B = ws.ButtonState.B; if (!lastWiiState.ButtonState.Up && ws.ButtonState.Up) { keybd_event(VK_UP, 0x45, 0, 0); } if (lastWiiState.ButtonState.Up && !ws.ButtonState.Up) { keybd_event(VK_UP, 0x45, KEYEVENTF_KEYUP, 0); } lastWiiState.ButtonState.Up = ws.ButtonState.Up; if (!lastWiiState.ButtonState.Down && ws.ButtonState.Down) { keybd_event(VK_DOWN, 0x45, 0, 0); } if (lastWiiState.ButtonState.Down && !ws.ButtonState.Down) { keybd_event(VK_DOWN, 0x45, KEYEVENTF_KEYUP, 0); } lastWiiState.ButtonState.Down = ws.ButtonState.Down; if (!lastWiiState.ButtonState.Left && ws.ButtonState.Left) { keybd_event(VK_LEFT, 0x45, 0, 0); } if (lastWiiState.ButtonState.Left && !ws.ButtonState.Left) { keybd_event(VK_LEFT, 0x45, KEYEVENTF_KEYUP, 0); } lastWiiState.ButtonState.Left = ws.ButtonState.Left; if (!lastWiiState.ButtonState.Right && ws.ButtonState.Right) { keybd_event(VK_RIGHT, 0x45, 0, 0); } if (lastWiiState.ButtonState.Right && !ws.ButtonState.Right) { keybd_event(VK_RIGHT, 0x45, KEYEVENTF_KEYUP, 0); } lastWiiState.ButtonState.Right = ws.ButtonState.Right; lastWiiState.IRState.Found1 = ws.IRState.Found1; lastWiiState.IRState.RawX1 = ws.IRState.RawX1; lastWiiState.IRState.RawY1 = ws.IRState.RawY1; lastWiiState.IRState.Found2 = ws.IRState.Found2; lastWiiState.IRState.RawX2 = ws.IRState.RawX2; lastWiiState.IRState.RawY2 = ws.IRState.RawY2; lastWiiState.IRState.Found3 = ws.IRState.Found3; lastWiiState.IRState.RawX3 = ws.IRState.RawX3; lastWiiState.IRState.RawY3 = ws.IRState.RawY3; lastWiiState.IRState.Found4 = ws.IRState.Found4; lastWiiState.IRState.RawX4 = ws.IRState.RawX4; lastWiiState.IRState.RawY4 = ws.IRState.RawY4; //draw battery value on GUI BeginInvoke((MethodInvoker) delegate() { pbBattery.Value = (ws.Battery > 0xc8 ? 0xc8 : (int)ws.Battery); }); float f = (((100.0f * 48.0f * (float)(ws.Battery / 48.0f))) / 192.0f); BeginInvoke((MethodInvoker) delegate() { lblBattery.Text = f.ToString("f0") + "%"; }); //check the GUI check boxes if the IR dots are visible String irstatus = "Visible IR dots: "; if (ws.IRState.Found1) { irstatus += "1 "; } if (ws.IRState.Found2) { irstatus += "2 "; } if (ws.IRState.Found3) { irstatus += "3 "; } if (ws.IRState.Found4) { irstatus += "4 "; } BeginInvoke((MethodInvoker) delegate() { lblIRvisible.Text = irstatus; }); mut.ReleaseMutex(); }
void wm_WiimoteChanged(object sender, WiimoteChangedEventArgs args) { lock (lockObj) { WiimoteLib.ButtonState bs = args.WiimoteState.ButtonState; //extract the wiimote state IRSensor ws = args.WiimoteState.IRState.IRSensors[0]; if (ws.Found) //move cursor { PointF position = new PointF(ws.RawPosition.X, ws.RawPosition.Y); PointF warpedPos = position; warper.warp(position, ref warpedPos); SmoothingBuffer[SmoothingBufferIndex % SMOOTHING_BUFFER_SIZE] = warpedPos; SmoothingBufferIndex++; if (!lastWiiState.Found) //mouse down { SmoothingBufferIndex = 0; //resets the count if (CursorEnabled) { InputCont.MoveMouse(warpedPos); //move the mouse to x,y InputCont.LeftMouseDown(); //left click down } else if (CalibrationState.State > 0) { ContinueCalibration(position); } } else if (CursorEnabled) //dragging { //if (((x != lastWiiState.RawPosition.X) || (y != lastWiiState.RawPosition.Y)) && cursorControl) if (SmoothingEnabled) { PointF s = GetSmoothedCursor(SmoothingAmount); InputCont.MoveMouse(s); //move the mouse to x,y } else { InputCont.MoveMouse(warpedPos); //move the mouse to x,y } } } else if (lastWiiState.Found && CursorEnabled) { //mouse up InputCont.LeftMouseUp(); InputCont.MoveMouse(new PointF(0, 0)); //move the mouse to x,y } if (!lastButtonState.A && bs.A) { Calibrate(); } lastButtonState = bs; lastWiiState = ws; if (StatusInfoChanged != null) { StatusInfoChanged(this, new EventArgs <WiimoteState>(args.WiimoteState)); } } }