/// <summary> /// Function that takes the state of the core interaction components /// and translates it to RoutedEvents. Also updates hand pointer states. /// </summary> /// <param name="data">Data directly from the core interaction components</param> public void HandleHandPointerData(InteractionFrameData data) { Debug.Assert(this.IsInInteractionFrame, "Call to HandleHandPointerData made without call to BeginInteractionFrame"); if (this.isClearRequestPending) { // We don't care about new hand pointer data if client requested to clear // all hand pointers while in the middle of interaction frame processing. return; } var id = new Tuple <int, HandType>(data.TrackingId, data.HandType); HandPointer handPointer; if (!this.handPointers.TryGetValue(id, out handPointer)) { handPointer = new HandPointer { TrackingId = data.TrackingId, PlayerIndex = data.PlayerIndex, HandType = data.HandType, Owner = this, }; this.handPointers[id] = handPointer; } handPointer.Updated = true; handPointer.TimestampOfLastUpdate = data.TimeStampOfLastUpdate; handPointer.HandEventType = data.HandEventType; bool pressedChanged = handPointer.IsPressed != data.IsPressed; handPointer.IsPressed = data.IsPressed; handPointer.IsTracked = data.IsTracked; handPointer.IsActive = data.IsActive; handPointer.IsInteractive = data.IsInteractive; bool primaryHandOfPrimaryUserChanged = handPointer.IsPrimaryHandOfPrimaryUser != (data.IsPrimaryHandOfUser && data.IsPrimaryUser); handPointer.IsPrimaryHandOfUser = data.IsPrimaryHandOfUser; handPointer.IsPrimaryUser = data.IsPrimaryUser; double newX; double newY; //InteractionZoneDefinition.InteractionZoneToUserInterface(data.X, data.Y, data.Z, this.InteractionRootElement.ActualWidth, this.InteractionRootElement.ActualHeight, mapperParameters, out newX, out newY); InteractionZoneDefinition.InteractionZoneToUserInterface(data.X, data.Y, this.InteractionRootElement.ActualWidth, this.InteractionRootElement.ActualHeight, out newX, out newY); bool positionChanged = !InteractionZoneDefinition.AreUserInterfaceValuesClose(newX, handPointer.X) || !InteractionZoneDefinition.AreUserInterfaceValuesClose(newY, handPointer.Y) || !InteractionZoneDefinition.AreUserInterfaceValuesClose(data.Z, handPointer.PressExtent); handPointer.X = newX; handPointer.Y = newY; handPointer.PressExtent = data.Z; this.HandleHandPointerChanges(handPointer, pressedChanged, positionChanged, primaryHandOfPrimaryUserChanged, false); }
private void KinectScrollViewerHandPointersUpdated(object sender, EventArgs e) { var kinectRegion = (KinectRegion)sender; var primaryHandPointer = kinectRegion.HandPointers.FirstOrDefault(hp => hp.IsPrimaryHandOfPrimaryUser); if (primaryHandPointer == null) { return; } if (primaryHandPointer.HandEventType == HandEventType.Grip) { if (this.capturedHandPointer == primaryHandPointer) { return; } this.grippedHandpointer = primaryHandPointer; return; } if (this.grippedHandpointer == primaryHandPointer && primaryHandPointer.HandEventType == HandEventType.GripRelease) { this.grippedHandpointer = null; } }
private void HandleHandPointerGrip(HandPointer handPointer) { if (handPointer == null) { return; } if (this.capturedHandPointer != handPointer) { if (handPointer.Captured == null) { // Only capture hand pointer if it isn't already captured handPointer.Capture(this); } else { // Some other control has capture, ignore grip return; } } this.lastGripState = GripState.Gripped; this.lastGripTimeStamp = handPointer.TimestampOfLastUpdate; this.scrollViewerInertiaScroller.Stop(); this.gripPoint = handPointer.GetPosition(this); this.startingScrollOffset = new Point(this.HorizontalOffset, this.VerticalOffset); }
internal bool CaptureHandPointer(HandPointer handPointer, UIElement element) { this.InteractionRootElement.VerifyAccess(); var id = new Tuple <int, HandType>(handPointer.TrackingId, handPointer.HandType); HandPointer checkHandPointer; if (!this.handPointers.TryGetValue(id, out checkHandPointer)) { // No hand pointer to capture return(false); } if (!object.ReferenceEquals(handPointer, checkHandPointer)) { // The HandPointer we have for this hand pointer is not the one // we were handed in. Caller has an older instance of the HandPointer return(false); } if (element != null && handPointer.Captured != null) { // Request wasn't to clear capture and some other element has this captured // Maybe this isn't necessary. return(false); } SwitchCapture(handPointer, handPointer.Captured, element); return(true); }
// TODO: Remove private void SwipeGestureDetected(string gesture) { HandPointer primaryHandPointer = this.HandPointers.SingleOrDefault(handPointer => handPointer.IsPrimaryHandOfPrimaryUser); if (primaryHandPointer == null) { return; } if (gesture.Equals("SwipeToLeft")) { HandPointerSwipeEventArgs handPointerSwipeEventArgs = new HandPointerSwipeEventArgs(primaryHandPointer, new SwipeGesture { SwipeDirection = SwipeDirection.Left }, HandPointerSwipeEvent, uiElement); uiElement.RaiseEvent(handPointerSwipeEventArgs); } else { HandPointerSwipeEventArgs handPointerSwipeEventArgs = new HandPointerSwipeEventArgs(primaryHandPointer, new SwipeGesture { SwipeDirection = SwipeDirection.Right }, HandPointerSwipeEvent, uiElement); uiElement.RaiseEvent(handPointerSwipeEventArgs); } }
/// <summary> /// Updates the internal state about the elements this hand pointer is over. /// Does not set any attached properties or send any events. /// </summary> /// <param name="handPointer">The hand pointer we are updating</param> /// <param name="targetElement">element the hand pointer is over or captured to</param> /// <param name="oldIntersectedElements">The list of elements this hand pointer was intersecting before they were updated</param> private void UpdateIntersections(HandPointer handPointer, UIElement targetElement, out HashSet <UIElement> oldIntersectedElements) { var newIntersectedElements = new HashSet <UIElement>(); var scanStop = (UIElement)VisualTreeHelper.GetParent(this.InteractionRootElement); oldIntersectedElements = handPointer.EnteredElements; // Get the list of elements this hand pointer is now over. Note that // we will say the pointer is over an element even if it is really // over a child which could be transformed outside the bounds of // the item. for (DependencyObject scan = targetElement; scan != null && scan != scanStop; scan = VisualTreeHelper.GetParent(scan)) { var scanElement = scan as UIElement; if (scanElement != null) { newIntersectedElements.Add(scanElement); } } // Update to the new list of entered elements before sending // any events. If we get called back in an event handler, we // will have the current data, not the old data. handPointer.EnteredElements = newIntersectedElements; }
/// <summary> /// Sends the events and updates the attached properties having to do /// with this hand pointer being over any elements. /// </summary> /// <param name="handPointer">The hand pointer we are working with</param> /// <param name="primaryHandOfPrimaryUserChanged"> Did the primary hand of the primary user change </param> /// <param name="oldIntersectedElements">The list of elements this hand pointer used to intersect</param> private static void DoIntersectionNotifications(HandPointer handPointer, bool primaryHandOfPrimaryUserChanged, HashSet <UIElement> oldIntersectedElements) { var wasPrimaryHandOfPrimaryUser = primaryHandOfPrimaryUserChanged ? !handPointer.IsPrimaryHandOfPrimaryUser : handPointer.IsPrimaryHandOfPrimaryUser; // Leave any elements we aren't in any more foreach (var oldIntersectedElement in oldIntersectedElements) { if (!handPointer.EnteredElements.Contains(oldIntersectedElement)) { // We are no longer over this element. // If we were or still are the HandPointer for the primary user's // primary hand then clear out the attatched DP for this. if (wasPrimaryHandOfPrimaryUser) { KinectRegion.SetIsPrimaryHandPointerOver(oldIntersectedElement, false); } // Tell this element that this hand pointer has left var leaveArgs = new HandPointerEventArgs(handPointer, KinectRegion.HandPointerLeaveEvent, oldIntersectedElement); oldIntersectedElement.RaiseEvent(leaveArgs); } else { if (wasPrimaryHandOfPrimaryUser && !handPointer.IsPrimaryHandOfPrimaryUser) { // Hand pointer didn't leave the element but it is no longer the primary KinectRegion.SetIsPrimaryHandPointerOver(oldIntersectedElement, false); } } } // Enter any elements that we are now in foreach (var newEnteredElement in handPointer.EnteredElements) { if (!oldIntersectedElements.Contains(newEnteredElement)) { // Tell this element the hand pointer entered. // Set the attached DP for this if (handPointer.IsPrimaryHandOfPrimaryUser) { KinectRegion.SetIsPrimaryHandPointerOver(newEnteredElement, true); } // Send the routed event for this. var enterArgs = new HandPointerEventArgs(handPointer, KinectRegion.HandPointerEnterEvent, newEnteredElement); newEnteredElement.RaiseEvent(enterArgs); } else { if (!wasPrimaryHandOfPrimaryUser && handPointer.IsPrimaryHandOfPrimaryUser) { // Hand pointer was already in this element but it became the primary KinectRegion.SetIsPrimaryHandPointerOver(newEnteredElement, true); } } } }
private void OnHandPointerLostCapture(object sender, HandPointerEventArgs handPointerEventArgs) { if (this.capturedHandPointer == handPointerEventArgs.HandPointer) { this.capturedHandPointer = null; this.IsPressed = false; handPointerEventArgs.Handled = true; } }
private void OnHandPointerCaptured(object sender, HandPointerEventArgs handPointerEventArgs) { if (this.capturedHandPointer == null) { this.capturedHandPointer = handPointerEventArgs.HandPointer; this.IsPressed = true; handPointerEventArgs.Handled = true; } }
private void OnHandPointerLostCapture(object sender, HandPointerEventArgs kinectHandPointerEventArgs) { if (this.capturedHandPointer == kinectHandPointerEventArgs.HandPointer) { this.capturedHandPointer = null; this.lastGripState = GripState.Released; this.scrollMoveTimer.Start(); kinectHandPointerEventArgs.Handled = true; this.DoTransformAnimations(); } }
private void OnHandPointerEnter(object sender, HandPointerEventArgs kinectHandPointerEventArgs) { if (kinectHandPointerEventArgs.HandPointer.IsPrimaryHandOfPrimaryUser) { kinectHandPointerEventArgs.Handled = true; if (this.grippedHandpointer == kinectHandPointerEventArgs.HandPointer) { this.HandleHandPointerGrip(kinectHandPointerEventArgs.HandPointer); this.grippedHandpointer = null; } } }
private void OnHandPointerCaptured(object sender, HandPointerEventArgs kinectHandPointerEventArgs) { if (this.capturedHandPointer != null) { // Release capture on any previous captured handpointer this.capturedHandPointer.Capture(null); } this.capturedHandPointer = kinectHandPointerEventArgs.HandPointer; kinectHandPointerEventArgs.Handled = true; this.SetScrollBarVisualState("GripScrolling"); this.scrollMoveTimer.Stop(); }
public override void HandPointersCallback(long timestamp, HandPointer[] handPointers) { HashSet<int> activeUserIds = new HashSet<int>(); foreach (HandPointer handPointer in handPointers) { if (handPointer.IsActive) { activeUserIds.Add(handPointer.TrackingId); } } ActiveUserCount = activeUserIds.Count; }
private static void SwitchCapture(HandPointer handPointer, UIElement oldElement, UIElement newElement) { handPointer.Captured = newElement; if (oldElement != null) { var lostArgs = CreateEventArgs(KinectRegion.HandPointerLostCaptureEvent, oldElement, handPointer); oldElement.RaiseEvent(lostArgs); } if (newElement != null) { var gotArgs = CreateEventArgs(KinectRegion.HandPointerGotCaptureEvent, newElement, handPointer); newElement.RaiseEvent(gotArgs); } }
//Se define esta función para detectar cuando se ha cerrado la mano //Primero se guarda en la variable mano los datos para acceder posteriormente //y a continuación se inicializan las variables de posición private void mano_cerrada(object sender, RoutedEventArgs e) { if (this.kinectRegion.HandPointers[0].IsActive) mano = this.kinectRegion.HandPointers[0]; else mano = this.kinectRegion.HandPointers[1]; posicion_cuadrado = mano.GetPosition(wrapPanel); cuadrado_max = posicion_cuadrado; puno = true; }
/// <summary> /// Function that takes the state of the core interaction components /// and translates it to RoutedEvents. Also updates hand pointer states. /// </summary> /// <param name="data">Data directly from the core interaction components</param> public void HandleHandPointerData(InteractionFrameData data) { Debug.Assert(this.IsInInteractionFrame, "Call to HandleHandPointerData made without call to BeginInteractionFrame"); if (this.isClearRequestPending) { // We don't care about new hand pointer data if client requested to clear // all hand pointers while in the middle of interaction frame processing. return; } var id = new Tuple<int, HandType>(data.TrackingId, data.HandType); HandPointer handPointer; if (!this.handPointers.TryGetValue(id, out handPointer)) { handPointer = new HandPointer { TrackingId = data.TrackingId, PlayerIndex = data.PlayerIndex, HandType = data.HandType, Owner = this, }; this.handPointers[id] = handPointer; } handPointer.Updated = true; handPointer.TimestampOfLastUpdate = data.TimeStampOfLastUpdate; handPointer.HandEventType = data.HandEventType; bool pressedChanged = handPointer.IsPressed != data.IsPressed; handPointer.IsPressed = data.IsPressed; handPointer.IsTracked = data.IsTracked; handPointer.IsActive = data.IsActive; handPointer.IsInteractive = data.IsInteractive; bool primaryHandOfPrimaryUserChanged = handPointer.IsPrimaryHandOfPrimaryUser != (data.IsPrimaryHandOfUser && data.IsPrimaryUser); handPointer.IsPrimaryHandOfUser = data.IsPrimaryHandOfUser; handPointer.IsPrimaryUser = data.IsPrimaryUser; double newX; double newY; InteractionZoneDefinition.InteractionZoneToUserInterface(data.X, data.Y, this.InteractionRootElement.ActualWidth, this.InteractionRootElement.ActualHeight, out newX, out newY); bool positionChanged = !InteractionZoneDefinition.AreUserInterfaceValuesClose(newX, handPointer.X) || !InteractionZoneDefinition.AreUserInterfaceValuesClose(newY, handPointer.Y) || !InteractionZoneDefinition.AreUserInterfaceValuesClose(data.Z, handPointer.PressExtent); handPointer.X = newX; handPointer.Y = newY; handPointer.PressExtent = data.Z; this.HandleHandPointerChanges(handPointer, pressedChanged, positionChanged, primaryHandOfPrimaryUserChanged, false); }
internal HandPointerEventArgs(HandPointer handPointer, RoutedEvent routedEvent, UIElement source) : base(routedEvent, source) { this.HandPointer = handPointer; }
internal bool CaptureHandPointer(HandPointer handPointer, UIElement element) { this.InteractionRootElement.VerifyAccess(); var id = new Tuple<int, HandType>(handPointer.TrackingId, handPointer.HandType); HandPointer checkHandPointer; if (!this.handPointers.TryGetValue(id, out checkHandPointer)) { // No hand pointer to capture return false; } if (!object.ReferenceEquals(handPointer, checkHandPointer)) { // The HandPointer we have for this hand pointer is not the one // we were handed in. Caller has an older instance of the HandPointer return false; } if (element != null && handPointer.Captured != null) { // Request wasn't to clear capture and some other element has this captured // Maybe this isn't necessary. return false; } SwitchCapture(handPointer, handPointer.Captured, element); return true; }
/// <summary> /// Check the position of the hand on the Y-axis to determine what track it is over /// </summary> /// <param name="handPointer">A Kinect.Toolkit.Controls.HandPointer object</param> /// <returns>The track number</returns> public int CheckHandForTrack(HandPointer handPointer) { double y = handPointer.GetPosition(tracksUI).Y; int trackSelected = (int)y / 101; return trackSelected; }
private static HandPointerEventArgs CreateEventArgs(RoutedEvent routedEvent, UIElement targetElement, HandPointer handPointer) { return new HandPointerEventArgs(handPointer, routedEvent, targetElement); }
/// <summary> /// Check the position of the hand on the X-axis to determine what slot it is over /// </summary> /// <param name="hand">A Kinect.Toolkit.Controls.HandPointer object</param> /// <returns>The slot number</returns> public int CheckHandForSlot(HandPointer hand) { double x = hand.GetPosition(tracksUI).X; int slot = (int)x / 101; return slot; }
/// <summary> /// Updates the internal state about the elements this hand pointer is over. /// Does not set any attached properties or send any events. /// </summary> /// <param name="handPointer">The hand pointer we are updating</param> /// <param name="targetElement">element the hand pointer is over or captured to</param> /// <param name="oldIntersectedElements">The list of elements this hand pointer was intersecting before they were updated</param> private void UpdateIntersections(HandPointer handPointer, UIElement targetElement, out HashSet<UIElement> oldIntersectedElements) { var newIntersectedElements = new HashSet<UIElement>(); var scanStop = (UIElement)VisualTreeHelper.GetParent(this.InteractionRootElement); oldIntersectedElements = handPointer.EnteredElements; // Get the list of elements this hand pointer is now over. Note that // we will say the pointer is over an element even if it is really // over a child which could be transformed outside the bounds of // the item. for (DependencyObject scan = targetElement; scan != null && scan != scanStop; scan = VisualTreeHelper.GetParent(scan)) { var scanElement = scan as UIElement; if (scanElement != null) { newIntersectedElements.Add(scanElement); } } // Update to the new list of entered elements before sending // any events. If we get called back in an event handler, we // will have the current data, not the old data. handPointer.EnteredElements = newIntersectedElements; }
private void HandleHandPointerChanges( HandPointer handPointer, bool pressedChanged, bool positionChanged, bool primaryHandOfPrimaryUserChanged, bool removed) { bool doPress = false; bool doRelease = false; bool doMove = false; bool doLostCapture = false; bool doGrip = false; bool doGripRelease = false; if (removed) { // Deny the existence of this hand pointer doRelease = handPointer.IsPressed; doLostCapture = handPointer.Captured != null; } else { if (pressedChanged) { doPress = handPointer.IsPressed; doRelease = !handPointer.IsPressed; } if (positionChanged) { doMove = true; } doGrip = handPointer.HandEventType == HandEventType.Grip; doGripRelease = handPointer.HandEventType == HandEventType.GripRelease; } if (doLostCapture) { SwitchCapture(handPointer, handPointer.Captured, null); } var targetElement = handPointer.Captured; if (targetElement == null) { var position = handPointer.GetPosition(this.InteractionRootElement); targetElement = this.HitTest(position); } // Update internal enter/leave state HashSet<UIElement> oldIntersectingElements; this.UpdateIntersections(handPointer, removed ? null : targetElement, out oldIntersectingElements); // See if this hand pointer is participating in a grip-initiated // interaction. var newIsInGripInteraction = false; if (targetElement != null) { var args = new QueryInteractionStatusEventArgs(handPointer, this.InteractionRootElement); targetElement.RaiseEvent(args); if (args.Handled && args.IsInGripInteraction) { newIsInGripInteraction = true; } } handPointer.IsInGripInteraction = newIsInGripInteraction; //// After this point there should be no more changes to the internal //// state of the handPointers. We don't want event handlers calling us //// when our internal state is inconsistent. DoIntersectionNotifications(handPointer, primaryHandOfPrimaryUserChanged, oldIntersectingElements); if (targetElement == null) { return; } if (doGrip) { var args = CreateEventArgs(KinectRegion.HandPointerGripEvent, targetElement, handPointer); targetElement.RaiseEvent(args); } if (doGripRelease) { var args = CreateEventArgs(KinectRegion.HandPointerGripReleaseEvent, targetElement, handPointer); targetElement.RaiseEvent(args); } if (doPress) { var args = CreateEventArgs(KinectRegion.HandPointerPressEvent, targetElement, handPointer); targetElement.RaiseEvent(args); } if (doMove) { var args = CreateEventArgs(KinectRegion.HandPointerMoveEvent, targetElement, handPointer); targetElement.RaiseEvent(args); } if (doRelease) { var args = CreateEventArgs(KinectRegion.HandPointerPressReleaseEvent, targetElement, handPointer); targetElement.RaiseEvent(args); } }
internal HandPointerSwipeEventArgs(HandPointer handPointer, SwipeGesture swipeGesture, RoutedEvent routedEvent, UIElement source) : base(routedEvent, source) { HandPointer = handPointer; SwipeGesture = swipeGesture; }
private static HandPointerSwipeEventArgs CreateSwipeEventArgs(RoutedEvent routedEvent, UIElement targetElement, HandPointer handPointer, SwipeGesture swipeGesture) { return(new HandPointerSwipeEventArgs(handPointer, swipeGesture, routedEvent, targetElement)); }
/// <summary> /// Sends the events and updates the attached properties having to do /// with this hand pointer being over any elements. /// </summary> /// <param name="handPointer">The hand pointer we are working with</param> /// <param name="primaryHandOfPrimaryUserChanged"> Did the primary hand of the primary user change </param> /// <param name="oldIntersectedElements">The list of elements this hand pointer used to intersect</param> private static void DoIntersectionNotifications(HandPointer handPointer, bool primaryHandOfPrimaryUserChanged, HashSet<UIElement> oldIntersectedElements) { var wasPrimaryHandOfPrimaryUser = primaryHandOfPrimaryUserChanged ? !handPointer.IsPrimaryHandOfPrimaryUser : handPointer.IsPrimaryHandOfPrimaryUser; // Leave any elements we aren't in any more foreach (var oldIntersectedElement in oldIntersectedElements) { if (!handPointer.EnteredElements.Contains(oldIntersectedElement)) { // We are no longer over this element. // If we were or still are the HandPointer for the primary user's // primary hand then clear out the attatched DP for this. if (wasPrimaryHandOfPrimaryUser) { KinectRegion.SetIsPrimaryHandPointerOver(oldIntersectedElement, false); } // Tell this element that this hand pointer has left var leaveArgs = new HandPointerEventArgs(handPointer, KinectRegion.HandPointerLeaveEvent, oldIntersectedElement); oldIntersectedElement.RaiseEvent(leaveArgs); } else { if (wasPrimaryHandOfPrimaryUser && !handPointer.IsPrimaryHandOfPrimaryUser) { // Hand pointer didn't leave the element but it is no longer the primary KinectRegion.SetIsPrimaryHandPointerOver(oldIntersectedElement, false); } } } // Enter any elements that we are now in foreach (var newEnteredElement in handPointer.EnteredElements) { if (!oldIntersectedElements.Contains(newEnteredElement)) { // Tell this element the hand pointer entered. // Set the attached DP for this if (handPointer.IsPrimaryHandOfPrimaryUser) { KinectRegion.SetIsPrimaryHandPointerOver(newEnteredElement, true); } // Send the routed event for this. var enterArgs = new HandPointerEventArgs(handPointer, KinectRegion.HandPointerEnterEvent, newEnteredElement); newEnteredElement.RaiseEvent(enterArgs); } else { if (!wasPrimaryHandOfPrimaryUser && handPointer.IsPrimaryHandOfPrimaryUser) { // Hand pointer was already in this element but it became the primary KinectRegion.SetIsPrimaryHandPointerOver(newEnteredElement, true); } } } }
private static HandPointerEventArgs CreateEventArgs(RoutedEvent routedEvent, UIElement targetElement, HandPointer handPointer) { return(new HandPointerEventArgs(handPointer, routedEvent, targetElement)); }
/// <summary> /// This implements any special interactions with the hand pointer. /// For example, if the hand pointer was to repel or attract this object, /// the code to implement that would go here. /// </summary> /// <param name="pointer"></param> public override void InteractWithHandPointer(HandPointer pointer) { /* Also no interactions with a hand pointer. We'll handle the * button press separately. */ }
internal QueryInteractionStatusEventArgs(HandPointer handPointer, UIElement source) : base(handPointer, KinectRegion.QueryInteractionStatusEvent, source) { }
private void OnHandPointerLeave(object sender, HandPointerEventArgs e) { if (this.activeHandpointer != e.HandPointer) { return; } this.activeHandpointer = null; this.IsHandPointerOver = false; this.repeatTimer.Stop(); }
public virtual void OnHandPointerGripRelease(HandPointer grippedHandpointer, Point startGripPoint, Point endGripPoint) { }
private void OnHandPointerEnter(object sender, HandPointerEventArgs e) { if (!e.HandPointer.IsPrimaryHandOfUser || !e.HandPointer.IsPrimaryUser) { return; } this.activeHandpointer = e.HandPointer; this.IsHandPointerOver = true; this.repeatTimer.Start(); ((MainWindow)System.Windows.Application.Current.MainWindow).glove.ActivateMotor(positivePins, valuesMax); }
private void HandleHandPointerChanges( HandPointer handPointer, bool pressedChanged, bool positionChanged, bool primaryHandOfPrimaryUserChanged, bool removed) { bool doPress = false; bool doRelease = false; bool doMove = false; bool doLostCapture = false; bool doGrip = false; bool doGripRelease = false; // bool doSwipe = false; if (removed) { // Deny the existence of this hand pointer doRelease = handPointer.IsPressed; doLostCapture = handPointer.Captured != null; } else { if (pressedChanged) { doPress = handPointer.IsPressed; doRelease = !handPointer.IsPressed; } if (positionChanged) { doMove = true; } doGrip = handPointer.HandEventType == HandEventType.Grip; doGripRelease = handPointer.HandEventType == HandEventType.GripRelease; } if (doLostCapture) { SwitchCapture(handPointer, handPointer.Captured, null); } var targetElement = handPointer.Captured; if (targetElement == null) { var position = handPointer.GetPosition(this.InteractionRootElement); targetElement = this.HitTest(position); } // Update internal enter/leave state HashSet <UIElement> oldIntersectingElements; this.UpdateIntersections(handPointer, removed ? null : targetElement, out oldIntersectingElements); // See if this hand pointer is participating in a grip-initiated // interaction. var newIsInGripInteraction = false; if (targetElement != null) { var args = new QueryInteractionStatusEventArgs(handPointer, this.InteractionRootElement); targetElement.RaiseEvent(args); if (args.Handled && args.IsInGripInteraction) { newIsInGripInteraction = true; } } handPointer.IsInGripInteraction = newIsInGripInteraction; //// After this point there should be no more changes to the internal //// state of the handPointers. We don't want event handlers calling us //// when our internal state is inconsistent. DoIntersectionNotifications(handPointer, primaryHandOfPrimaryUserChanged, oldIntersectingElements); if (targetElement == null) { return; } if (doGrip) { var args = CreateEventArgs(KinectRegion.HandPointerGripEvent, targetElement, handPointer); targetElement.RaiseEvent(args); } if (doGripRelease) { var args = CreateEventArgs(KinectRegion.HandPointerGripReleaseEvent, targetElement, handPointer); targetElement.RaiseEvent(args); } if (doPress) { var args = CreateEventArgs(KinectRegion.HandPointerPressEvent, targetElement, handPointer); targetElement.RaiseEvent(args); } if (doMove) { var args = CreateEventArgs(KinectRegion.HandPointerMoveEvent, targetElement, handPointer); targetElement.RaiseEvent(args); } if (doRelease) { var args = CreateEventArgs(KinectRegion.HandPointerPressReleaseEvent, targetElement, handPointer); targetElement.RaiseEvent(args); } }
//Se define esta función para detectar cuando se ha cerrado la mano //Primero se guarda en la variable mano los datos para acceder posteriromente //y a continuación se inicializan las variables de posición private void mano_cerrada(object sender, RoutedEventArgs e) { if (this.kinectRegion.HandPointers[0].IsActive) mano = this.kinectRegion.HandPointers[0]; else mano = this.kinectRegion.HandPointers[1]; posicion_cuadrado = mano.GetPosition(wrapPanel); cuadrado_max = posicion_cuadrado; puno = true; this.wrapPanel.Children.Add(new SelectionDisplay(("Mano cerrada, puede comenzar el cuadrado"))); }
public override void OnHandPointerGripRelease(HandPointer grippedHandpointer, System.Windows.Point startGripPoint, System.Windows.Point endGripPoint) { System.Windows.Point diffVector = (System.Windows.Point)(endGripPoint - startGripPoint); if (Math.Abs(diffVector.X / diffVector.Y) > 2.0) { page.performMove(diffVector.X < 0 ? GameManager.Direction.LEFT : GameManager.Direction.RIGHT); } else if (Math.Abs(diffVector.Y / diffVector.X) > 2.0) { page.performMove(diffVector.Y < 0 ? GameManager.Direction.UP : GameManager.Direction.DOWN); } }
/// <summary> /// Defines non-click/grip interactions with any hand pointers on the screen. /// </summary> /// <param name="pointer"></param> public override void InteractWithHandPointer(HandPointer pointer) { /* For now, we don't do anything here. */ }
private void OnHandPointerEnter(object sender, HandPointerEventArgs e) { if (!e.HandPointer.IsPrimaryHandOfUser || !e.HandPointer.IsPrimaryUser) { return; } this.activeHandpointer = e.HandPointer; this.IsHandPointerOver = true; this.repeatTimer.Start(); }
/// <summary> /// This implements any special interactions with the hand pointer. /// For example, if the hand pointer was to repel or attract this object, /// the code to implement that would go here. /// </summary> /// <param name="pointer"></param> public override void InteractWithHandPointer(HandPointer pointer) { }
private void OnHandPointerLeave(object sender, HandPointerEventArgs e) { if (this.activeHandpointer != e.HandPointer) { return; } this.activeHandpointer = null; this.IsHandPointerOver = false; this.repeatTimer.Stop(); ((MainWindow)System.Windows.Application.Current.MainWindow).glove.ActivateMotor(positivePins, valuesMinium); }
public virtual void Add(HandPointer handPointer) { handPointerSampleTracker.AddSample(handPointer.X, handPointer.Y, handPointer.TimestampOfLastUpdate); LookForGesture(); }