void pWiiProvider_OnNewFrame(object sender, FrameEventArgs e) { List <WiiContact> lContacts = new List <WiiContact>(e.Contacts); if (lContacts.Count > 0) { // Get the contact. WiiContact pContact = lContacts[0]; // If it is a down contact. if (pContact.Type != ContactType.Start) { return; } // Reference the touch contact from the event. Vector vPoint = new Vector(pContact.Position.X, pContact.Position.Y); // Select what to do based on the calibration phase. switch (iCalibrationPhase) { case 1: // Get the point and update the rectangle, step the calibration phase over and then break out. pSourceRectangle.TopLeft = vPoint; iCalibrationPhase = 2; this.stepCalibration(); break; case 2: // Get the point and update the rectangle, step the calibration phase over and then break out. pSourceRectangle.TopRight = vPoint; iCalibrationPhase = 3; this.stepCalibration(); break; case 3: // Get the point and update the rectangle, step the calibration phase over and then break out. pSourceRectangle.BottomLeft = vPoint; iCalibrationPhase = 4; this.stepCalibration(); break; case 4: // Get the point and update the rectangle, step the calibration phase over and then break out. pSourceRectangle.BottomRight = vPoint; iCalibrationPhase = 5; this.stepCalibration(); break; default: throw new Exception("Unknown calibration phase '" + iCalibrationPhase + "' to handle this touch event!"); } } }
public void queueContact(WiiContact contact) { if (enabled) { contactQueue.Enqueue(contact); } }
/// <summary> /// Enqueue a new contact into the current list. /// </summary> /// <remarks>Yes I know it is horrible and iccky to do this here.. but yea.. I didn't want to expose too much of the HID stuff at this stage.</remarks> /// <param name="eState">The HidContactState of the contact.</param> /// <param name="pContact">The reference to the WiiContact generated by the provider.</param> public void enqueueContact(HidContactState eState, WiiContact pContact) { this.enqueueContact(new HidContactInfo(eState, pContact)); }
public void queueContact(WiiContact contact) { contactQueue.Enqueue(contact); }
public Queue<WiiContact> getFrame() { Queue<WiiContact> newFrame = new Queue<WiiContact>(1); //master if(masterPosition != null) { ContactType contactType; if (!this.masterReleased) { if (this.masterHovering) { contactType = ContactType.Start; this.masterHovering = false; } else { contactType = ContactType.Move; } if (this.isFirstMasterContact) { this.firstMasterContact = this.masterPosition; } else { if (this.masterHoldPosition) { if (Math.Abs(this.firstMasterContact.X - this.masterPosition.X) < TouchHoldThreshold && Math.Abs(this.firstMasterContact.Y - this.masterPosition.Y) < TouchHoldThreshold) { /*Console.WriteLine("DiffX: " + Math.Abs(this.firstMasterContact.X - this.masterPosition.X) + " DiffY: " + Math.Abs(this.firstMasterContact.Y - this.masterPosition.Y));*/ this.masterPosition = this.firstMasterContact; this.masterHoldPosition = true; } else { this.masterHoldPosition = false; } } //Helps to perform "edge swipe" guestures if (this.firstMasterContact.X < EdgeHelperMargins && this.masterPosition.X < EdgeHelperRelease) //Left { this.masterPosition.Y = (this.firstMasterContact.Y + this.firstMasterContact.Y + this.masterPosition.Y) / 3; } if (this.firstMasterContact.X > (this.screenBounds.Width - EdgeHelperMargins) && this.masterPosition.X > (this.screenBounds.Width - EdgeHelperRelease)) //Right { this.masterPosition.Y = (this.firstMasterContact.Y + this.firstMasterContact.Y + this.masterPosition.Y) / 3; } if (this.firstMasterContact.Y < EdgeHelperMargins && this.masterPosition.Y < EdgeHelperRelease) //Top { this.masterPosition.X = (this.firstMasterContact.X + this.firstMasterContact.X + this.masterPosition.X) / 3; } if (this.firstMasterContact.Y > (this.screenBounds.Height - EdgeHelperMargins) && this.masterPosition.Y > (this.screenBounds.Height - EdgeHelperRelease)) //Bottom { this.masterPosition.X = (this.firstMasterContact.X + this.firstMasterContact.X + this.masterPosition.X) / 3; } } smoothingBuffer.addValue(new System.Windows.Vector(masterPosition.X, masterPosition.Y)); System.Windows.Vector smoothedVec = smoothingBuffer.getSmoothedValue(); this.masterPosition.X = smoothedVec.X; this.masterPosition.Y = smoothedVec.Y; this.isFirstMasterContact = false; } else //Released = hovering { if (!this.masterHovering) //End the touch first { if (this.hoverDisabled) { contactType = ContactType.End; } else { contactType = ContactType.EndToHover; } this.masterPosition = lastMasterContact.Position; this.masterHovering = true; } else { contactType = ContactType.Hover; smoothingBuffer.addValue(new Vector(masterPosition.X, masterPosition.Y)); Vector smoothedVec = smoothingBuffer.getSmoothedValue(); this.masterPosition.X = smoothedVec.X; this.masterPosition.Y = smoothedVec.Y; } this.isFirstMasterContact = true; this.masterHoldPosition = true; } if (!(contactType == ContactType.Hover && this.hoverDisabled)) { if (this.stepIDs && contactType == ContactType.EndToHover) //If we release slave touch before we release master touch we want to make sure Windows treats master as the main touch point again { this.lastMasterContact = new WiiContact(this.masterID, ContactType.End, this.masterPosition, this.masterPriority, new Vector(this.screenBounds.Width,this.screenBounds.Height)); this.masterID = (this.masterID - this.startID + 2) % 4 + this.startID; this.slaveID = (this.slaveID - this.startID + 2) % 4 + this.startID; this.stepIDs = false; } else { this.lastMasterContact = new WiiContact(this.masterID, contactType, this.masterPosition, this.masterPriority, new Vector(this.screenBounds.Width, this.screenBounds.Height)); } newFrame.Enqueue(this.lastMasterContact); } } //slave if (slavePosition != null) { ContactType contactType; if (!this.slaveReleased) { if (this.slaveHovering) { contactType = ContactType.Start; this.slaveHovering = false; } else { contactType = ContactType.Move; } if (!this.masterReleased) { if (!this.usingMidpoint) { this.midpoint = calculateMidpoint(this.masterPosition, this.slavePosition); this.usingMidpoint = true; } this.slavePosition = reflectThroughMidpoint(this.masterPosition, this.midpoint); if (this.slavePosition.X < 0) { this.slavePosition.X = 0; } if (this.slavePosition.Y < 0) { this.slavePosition.Y = 0; } if (this.slavePosition.X > this.screenBounds.Width) { this.slavePosition.X = this.screenBounds.Width - 1; } if (this.slavePosition.Y > this.screenBounds.Height) { this.slavePosition.Y = this.screenBounds.Height - 1; } } else { this.usingMidpoint = false; } this.slaveEnded = false; this.stepIDs = false; } else { if (!this.slaveHovering) { contactType = ContactType.EndToHover; this.slavePosition = lastSlaveContact.Position; this.slaveHovering = true; } else { contactType = ContactType.EndFromHover; } } if (!this.slaveEnded) { this.lastSlaveContact = new WiiContact(this.slaveID, contactType, this.slavePosition,this.slavePriority, new Vector(this.screenBounds.Width, this.screenBounds.Height)); newFrame.Enqueue(this.lastSlaveContact); if (contactType == ContactType.EndFromHover) { this.slaveEnded = true; if (!this.masterReleased) //If we release slave before master { this.stepIDs = true; } else { this.masterID = (this.masterID - this.startID + 2) % 4 + this.startID; this.slaveID = (this.slaveID - this.startID + 2) % 4 + this.startID; this.stepIDs = false; } } } } return newFrame; }
public void queueContact(WiiContact contact) { throw new NotImplementedException(); }
public Queue <WiiContact> getFrame() { Queue <WiiContact> newFrame = new Queue <WiiContact>(1); //master if (masterPosition != null) { ContactType contactType; if (!this.masterReleased) { if (this.masterHovering) { contactType = ContactType.Start; this.masterHovering = false; } else { contactType = ContactType.Move; } if (this.isFirstMasterContact) { this.firstMasterContact = this.masterPosition; } else { if (this.masterHoldPosition) { if (Math.Abs(this.firstMasterContact.X - this.masterPosition.X) < TouchHoldThreshold && Math.Abs(this.firstMasterContact.Y - this.masterPosition.Y) < TouchHoldThreshold) { /*Console.WriteLine("DiffX: " + Math.Abs(this.firstMasterContact.X - this.masterPosition.X) + " DiffY: " + Math.Abs(this.firstMasterContact.Y - this.masterPosition.Y));*/ this.masterPosition = this.firstMasterContact; this.masterHoldPosition = true; } else { this.masterHoldPosition = false; } } //Helps to perform "edge swipe" guestures if (this.firstMasterContact.X < EdgeHelperMargins && this.masterPosition.X < EdgeHelperRelease) //Left { this.masterPosition.Y = (this.firstMasterContact.Y + this.firstMasterContact.Y + this.masterPosition.Y) / 3; } if (this.firstMasterContact.X > (this.screenBounds.Width - EdgeHelperMargins) && this.masterPosition.X > (this.screenBounds.Width - EdgeHelperRelease)) //Right { this.masterPosition.Y = (this.firstMasterContact.Y + this.firstMasterContact.Y + this.masterPosition.Y) / 3; } if (this.firstMasterContact.Y < EdgeHelperMargins && this.masterPosition.Y < EdgeHelperRelease) //Top { this.masterPosition.X = (this.firstMasterContact.X + this.firstMasterContact.X + this.masterPosition.X) / 3; } if (this.firstMasterContact.Y > (this.screenBounds.Height - EdgeHelperMargins) && this.masterPosition.Y > (this.screenBounds.Height - EdgeHelperRelease)) //Bottom { this.masterPosition.X = (this.firstMasterContact.X + this.firstMasterContact.X + this.masterPosition.X) / 3; } } smoothingBuffer.addValue(new System.Windows.Vector(masterPosition.X, masterPosition.Y)); System.Windows.Vector smoothedVec = smoothingBuffer.getSmoothedValue(); this.masterPosition.X = smoothedVec.X; this.masterPosition.Y = smoothedVec.Y; this.isFirstMasterContact = false; } else //Released = hovering { if (!this.masterHovering) //End the touch first { if (this.hoverDisabled) { contactType = ContactType.End; } else { contactType = ContactType.EndToHover; } this.masterPosition = lastMasterContact.Position; this.masterHovering = true; } else { contactType = ContactType.Hover; smoothingBuffer.addValue(new Vector(masterPosition.X, masterPosition.Y)); Vector smoothedVec = smoothingBuffer.getSmoothedValue(); this.masterPosition.X = smoothedVec.X; this.masterPosition.Y = smoothedVec.Y; } this.isFirstMasterContact = true; this.masterHoldPosition = true; } if (!(contactType == ContactType.Hover && this.hoverDisabled)) { if (this.stepIDs && contactType == ContactType.EndToHover) //If we release slave touch before we release master touch we want to make sure Windows treats master as the main touch point again { this.lastMasterContact = new WiiContact(this.masterID, ContactType.End, this.masterPosition, this.masterPriority, new Vector(this.screenBounds.Width, this.screenBounds.Height)); this.masterID = (this.masterID - this.startID + 2) % 4 + this.startID; this.slaveID = (this.slaveID - this.startID + 2) % 4 + this.startID; this.stepIDs = false; } else { this.lastMasterContact = new WiiContact(this.masterID, contactType, this.masterPosition, this.masterPriority, new Vector(this.screenBounds.Width, this.screenBounds.Height)); } newFrame.Enqueue(this.lastMasterContact); } } //slave if (slavePosition != null) { ContactType contactType; if (!this.slaveReleased) { if (this.slaveHovering) { contactType = ContactType.Start; this.slaveHovering = false; } else { contactType = ContactType.Move; } if (!this.masterReleased) { if (!this.usingMidpoint) { this.midpoint = calculateMidpoint(this.masterPosition, this.slavePosition); this.usingMidpoint = true; } this.slavePosition = reflectThroughMidpoint(this.masterPosition, this.midpoint); if (this.slavePosition.X < 0) { this.slavePosition.X = 0; } if (this.slavePosition.Y < 0) { this.slavePosition.Y = 0; } if (this.slavePosition.X > this.screenBounds.Width) { this.slavePosition.X = this.screenBounds.Width - 1; } if (this.slavePosition.Y > this.screenBounds.Height) { this.slavePosition.Y = this.screenBounds.Height - 1; } } else { this.usingMidpoint = false; } this.slaveEnded = false; this.stepIDs = false; } else { if (!this.slaveHovering) { contactType = ContactType.EndToHover; this.slavePosition = lastSlaveContact.Position; this.slaveHovering = true; } else { contactType = ContactType.EndFromHover; } } if (!this.slaveEnded) { this.lastSlaveContact = new WiiContact(this.slaveID, contactType, this.slavePosition, this.slavePriority, new Vector(this.screenBounds.Width, this.screenBounds.Height)); newFrame.Enqueue(this.lastSlaveContact); if (contactType == ContactType.EndFromHover) { this.slaveEnded = true; if (!this.masterReleased) //If we release slave before master { this.stepIDs = true; } else { this.masterID = (this.masterID - this.startID + 2) % 4 + this.startID; this.slaveID = (this.slaveID - this.startID + 2) % 4 + this.startID; this.stepIDs = false; } } } } return(newFrame); }
public bool handleWiimoteChanged(object sender, WiimoteChangedEventArgs e) { // Obtain mutual excluseion. WiimoteMutex.WaitOne(); bool significant = false; try { this.screenBounds = Util.ScreenBounds; this.duoTouch.screenBounds = Util.ScreenBounds; Queue <WiiContact> lFrame = new Queue <WiiContact>(1); // Store the state. WiimoteState pState = e.WiimoteState; this.Status.Battery = (pState.Battery > 0xc8 ? 0xc8 : (int)pState.Battery); bool pointerOutOfReach = false; CursorPos newpoint = lastpoint; newpoint = screenPositionCalculator.CalculateCursorPos(e); if (newpoint.X < 0 || newpoint.Y < 0) { newpoint = lastpoint; pointerOutOfReach = true; } WiimoteState ws = e.WiimoteState; if (keyMapper.processWiimoteState(ws)) { significant = true; this.lastWiimoteState = ws; } if (!pointerOutOfReach) { if (this.usingCursors() && !mouseMode && showPointer) { this.masterCursor.Show(); } significant = true; if (this.touchDownMaster) { duoTouch.setContactMaster(); } else { duoTouch.releaseContactMaster(); } duoTouch.setMasterPosition(new System.Windows.Point(newpoint.X, newpoint.Y)); if (this.touchDownSlave) { if (this.usingCursors() && !mouseMode && showPointer) { this.slaveCursor.Show(); } duoTouch.setSlavePosition(new System.Windows.Point(newpoint.X, newpoint.Y)); duoTouch.setContactSlave(); } else { duoTouch.releaseContactSlave(); if (this.usingCursors() && !mouseMode) { this.slaveCursor.Hide(); } } lastpoint = newpoint; lFrame = duoTouch.getFrame(); if (this.usingCursors() && !mouseMode) { WiiContact master = null; WiiContact slave = null; foreach (WiiContact contact in lFrame) { if (master == null) { master = contact; } else if (master.Priority > contact.Priority) { slave = master; master = contact; } else { slave = contact; } } if (master != null) { this.masterCursor.SetPosition(master.Position); this.masterCursor.SetRotation(newpoint.Rotation); } if (slave != null) { this.slaveCursor.SetPosition(slave.Position); this.slaveCursor.SetRotation(newpoint.Rotation); } } FrameEventArgs pFrame = new FrameEventArgs((ulong)Stopwatch.GetTimestamp(), lFrame); this.FrameQueue.Enqueue(pFrame); this.LastFrameEvent = pFrame; if (mouseMode && !this.touchDownMaster && !this.touchDownSlave && this.showPointer) //Mouse mode { if (gamingMouse) { double deltaX = (newpoint.X - ((double)this.screenBounds.Width / 2.0)) / (double)this.screenBounds.Width; double deltaY = (newpoint.Y - ((double)this.screenBounds.Height / 2.0)) / (double)this.screenBounds.Height; deltaX = Math.Sign(deltaX) * deltaX * deltaX * 50; deltaY = Math.Sign(deltaY) * deltaY * deltaY * 50 * ((double)this.screenBounds.Width / (double)this.screenBounds.Height); deltaXBuffer += deltaX % 1; deltaYBuffer += deltaY % 1; int roundDeltaX = (int)deltaX; int roundDeltaY = (int)deltaY; if (deltaXBuffer > 1 || deltaXBuffer < -1) { roundDeltaX += Math.Sign(deltaXBuffer); deltaXBuffer -= Math.Sign(deltaXBuffer); } if (deltaYBuffer > 1 || deltaYBuffer < -1) { roundDeltaY += Math.Sign(deltaYBuffer); deltaYBuffer -= Math.Sign(deltaYBuffer); } this.inputSimulator.Mouse.MoveMouseBy(roundDeltaX, roundDeltaY); } else { this.inputSimulator.Mouse.MoveMouseToPositionOnVirtualDesktop((65535 * newpoint.X) / this.screenBounds.Width, (65535 * newpoint.Y) / this.screenBounds.Height); } MouseSimulator.WakeCursor(); } } else //pointer out of reach { if (this.usingCursors() && !mouseMode) { this.masterCursor.Hide(); this.masterCursor.SetPosition(new System.Windows.Point(lastpoint.X, lastpoint.Y)); } } if (significant) { this.LastSignificantWiimoteEventTime = DateTime.Now; } } catch (Exception ex) { Console.WriteLine("Error handling Wiimote in WiimoteControl: " + ex.Message); return(significant); } //this.BatteryState = (pState.Battery > 0xc8 ? 0xc8 : (int)pState.Battery); // Release mutual exclusion. WiimoteMutex.ReleaseMutex(); return(significant); }