void KinectSensor_KinectChanged(object sender, KinectChangedEventArgs e) { bool error = true; if (e.OldSensor == null) { try { e.OldSensor.DepthStream.Disable(); e.OldSensor.SkeletonStream.Disable(); } catch (Exception) { error = true; } } if (e.NewSensor == null) { return; } try { Kinect = e.NewSensor; e.NewSensor.DepthStream.Enable(DepthImageFormat.Resolution640x480Fps30); e.NewSensor.SkeletonStream.Enable(); e.NewSensor.SkeletonFrameReady += KinectSensor_SkeletonFrameReady; try { e.NewSensor.SkeletonStream.TrackingMode = SkeletonTrackingMode.Seated; e.NewSensor.DepthStream.Range = DepthRange.Near; e.NewSensor.SkeletonStream.EnableTrackingInNearRange = true; } catch (InvalidOperationException) { e.NewSensor.DepthStream.Range = DepthRange.Default; e.NewSensor.SkeletonStream.EnableTrackingInNearRange = false; } } catch (InvalidOperationException) { error = true; } ZonaCursor.KinectSensor = e.NewSensor; KinectRegion.AddHandPointerGripHandler(this.ZonaCursor, this.OnHandGripHandler); KinectRegion.AddHandPointerGripReleaseHandler(this.ZonaCursor, this.OngRripReleaseHandler); KinectRegion.AddHandPointerMoveHandler(this.ZonaCursor, this.OnMoveHandler); KinectRegion.AddHandPointerPressHandler(this.ZonaCursor, this.OnPressHandler); KinectRegion.AddHandPointerPressReleaseHandler(this.ZonaCursor, this.OnPressRelaaseHandler); }
private void InitializeKinectButtonBase() { KinectRegion.AddHandPointerEnterHandler(this, this.OnHandPointerEnter); KinectRegion.AddHandPointerMoveHandler(this, this.OnHandPointerMove); KinectRegion.AddHandPointerGotCaptureHandler(this, this.OnHandPointerCaptured); KinectRegion.AddHandPointerLostCaptureHandler(this, this.OnHandPointerLostCapture); KinectRegion.AddHandPointerGripHandler(this, this.OnHandPointerGrip); KinectRegion.AddHandPointerGripReleaseHandler(this, this.OnHandPointerGripRelease); KinectRegion.AddQueryInteractionStatusHandler(this, this.OnQueryInteractionStatus); }
public DragDropElement() { lastGripState = GripState.Released; kinectRegionBinder = new KinectRegionBinder(this); kinectRegionBinder.OnKinectRegionChanged += OnKinectRegionChanged; KinectRegion.AddHandPointerEnterHandler(this, OnHandPointerEnter); KinectRegion.AddHandPointerMoveHandler(this, OnHandPointerMove); KinectRegion.AddHandPointerGotCaptureHandler(this, OnHandPointerCaptured); KinectRegion.AddHandPointerLostCaptureHandler(this, OnHandPointerLostCapture); KinectRegion.AddHandPointerGripHandler(this, OnHandPointerGrip); KinectRegion.AddHandPointerGripReleaseHandler(this, OnHandPointerGripRelease); KinectRegion.AddQueryInteractionStatusHandler(this, OnQueryInteractionStatus); }
private void createApplesAndTrees() { setAppleSize(); Point rangeMin = new Point(); Point rangeMax = new Point(); Canvas[] tree = new Canvas[treesCount]; myApple = new Apple[treesCount * applesOnTree]; ImageBrush treeBg = new ImageBrush(); treeBg.ImageSource = new BitmapImage(new Uri(@"../../../Graphics/ApplesGame/tree.png", UriKind.Relative)); int appleCounter = 0; for (int i = 0; i < treesCount; i++) { tree[i] = new Canvas(); tree[i].Width = (int)(windowWidth / treesCount * 0.5) * 1.5;//*1.7 - full screen of trees; tree[i].Height = (int)(windowHeight / 1.25); Canvas.SetTop(tree[i], 50); Canvas.SetLeft(tree[i], (i * tree[i].Width + 20)); tree[i].Margin = new Thickness((i * 0.2 * tree[i].Width), 0, 20, 0); tree[i].Name = "tree" + i; playfield.Children.Add(tree[i]); tree[i].Background = treeBg; setApplesArena(ref rangeMin, ref rangeMax); colorsCount = basketCount; for (int j = 0; j < applesOnTree; j++) { myApple[appleCounter] = new Apple(rangeMin, rangeMax, appleSize, appleCounter, i, colorsCount); var button = myApple[appleCounter].Figure; button.Foreground = new SolidColorBrush(Colors.Transparent); KinectRegion.AddQueryInteractionStatusHandler(button, OnQuery); KinectRegion.AddHandPointerGripHandler(button, OnHandPointerGrip); tree[i].Children.Add(button); button.MouseEnter += button_MouseEnter; button.StylusEnter += button_StylusEnter; button.MouseLeave += button_MouseLeave; button.StylusLeave += button_StylusLeave; appleCounter++; } } }
/// <summary> /// Called to update where we listen for grip. /// </summary> internal void ListenForGrip() { if (this.gripEventTarget != null) { KinectRegion.RemoveHandPointerGripHandler(this.gripEventTarget, this.OnHandPointerGrip); KinectRegion.SetIsGripTarget(this, false); BindingOperations.ClearBinding(this, IsPrimaryHandPointerOverProperty); this.gripEventTarget.IsEnabledChanged -= this.OnStateChangeEvent; this.gripEventTarget.MouseEnter -= this.OnMouseChange; this.gripEventTarget.MouseLeave -= this.OnMouseChange; this.gripEventTarget = null; } this.sliderParent = FindAncestor <KinectSlider>(this); if (this.sliderParent == null) { this.gripEventTarget = this; } else if (this.sliderParent.GripEventTarget != null) { this.gripEventTarget = this.sliderParent.GripEventTarget; } else { this.gripEventTarget = this.sliderParent; } var binding = new Binding { Source = this.gripEventTarget, Path = new PropertyPath(KinectRegion.IsPrimaryHandPointerOverProperty) }; BindingOperations.SetBinding(this, IsPrimaryHandPointerOverProperty, binding); this.gripEventTarget.IsEnabledChanged += this.OnStateChangeEvent; this.gripEventTarget.MouseEnter += this.OnMouseChange; this.gripEventTarget.MouseLeave += this.OnMouseChange; KinectRegion.AddHandPointerGripHandler(this.gripEventTarget, this.OnHandPointerGrip); KinectRegion.SetIsGripTarget(this.gripEventTarget, true); }
private void OnHandPointerGripRelase(object sender, HandPointerEventArgs handPointerEventArgs) { if (handPointerEventArgs.HandPointer.IsInGripInteraction == false && GripOverButton == true) { bool check = false; Point point = handPointerEventArgs.HandPointer.GetPosition(playfield); for (int i = 0; i < basketCount; i++) { if ((point.X >= basket[i].Position.X) && (point.X <= basket[i].EndPosition.X) && (point.Y >= basket[i].Position.Y) && (point.Y <= basket[i].EndPosition.Y)) { if (GripApple.Color == basket[i].Color) { handPointerEventArgs.Handled = true; gameScore.collectSuccess(); check = true; } } } if (!check) { handPointerEventArgs.Handled = true; gameScore.collectFail(); check = false; Apple MovingApple = new Apple(GripApple, point.X, point.Y); playfield.Children.Add(MovingApple.Figure); MoveTo(MovingApple, GripApple.Pos.X, GripApple.Pos.Y, point.X, point.Y); KinectRegion.AddQueryInteractionStatusHandler(MovingApple.Figure, OnQuery); KinectRegion.AddHandPointerGripHandler(MovingApple.Figure, OnHandPointerGrip); handPointerEventArgs.Handled = true; } } GripOverButton = false; }
/// <summary> /// Constructor. Creates a new DEEPKinectObject and binds it to an existing /// Shape object that is on the GUI. /// </summary> /// <param name="onScreenShape">The Shape that is on the GUI. We need this to bind the /// DEEPKinectObject to the shape on the screen.</param> /// <param name="isGrippable">Indicates whether the user can grip this object using a Kinect hand pointer.</param> /// <param name="isPressable">Indicates whether the user can press this object using a Kinect hand pointer.</param> public DEEPKinectObjectBaseClass(System.Windows.Shapes.Ellipse onScreenShape, UIElement backGroundRectangle, bool isGrippable, bool isPressable) { //Get a reference to the on-screen shape, so we can manipulate it later. this.onScreenShape = onScreenShape; /* Also get a starting location for the physical simulation. */ this.onScreenShapePosition.X = onScreenShape.Margin.Left; this.onScreenShapePosition.Y = onScreenShape.Margin.Top; //Make sure the onscreen shape is grippable and touchable if the caller desires it. KinectRegion.SetIsGripTarget(onScreenShape, isGrippable); KinectRegion.SetIsPressTarget(onScreenShape, isPressable); //Add handlers so that we can do things when the shape is touched or gripped on screen. if (isGrippable) { KinectRegion.AddHandPointerGripHandler(onScreenShape, OnGripHandler); KinectRegion.AddHandPointerGripReleaseHandler(onScreenShape, OnGripReleaseHandler); KinectRegion.AddHandPointerGripReleaseHandler(backGroundRectangle, OnGripReleaseHandler); } if (isPressable) { KinectRegion.AddHandPointerPressHandler(onScreenShape, OnPressHandler); KinectRegion.AddHandPointerPressReleaseHandler(onScreenShape, OnPressReleaseHandler); } KinectRegion.AddHandPointerMoveHandler(backGroundRectangle, OnHandPointerMoveHandler); KinectRegion.AddHandPointerMoveHandler(onScreenShape, OnHandPointerMoveHandler); //Here, we initialize the animationTimer, which we will later use for effects. internalTimer = new System.Timers.Timer(internalRefreshRate * 1000d); internalTimer.Elapsed += InternalTimer_Elapsed; internalTimer.Start(); }
public void RegisterCallbackToSensor(KinectSensor sensor) { if (isRegisterAllFrameReady) { sensor.AllFramesReady += sensor_AllFramesReady; } else { sensor.SkeletonFrameReady += sensor_SkeletonFrameReady; sensor.DepthFrameReady += sensor_DepthFrameReady; sensor.ColorFrameReady += sensor_ColorFrameReady; } KinectRegion.AddHandPointerGotCaptureHandler(element, this.OnHandPointerCaptured); KinectRegion.AddHandPointerLostCaptureHandler(element, this.OnHandPointerLostCapture); KinectRegion.AddHandPointerEnterHandler(element, this.OnHandPointerEnter); KinectRegion.AddHandPointerMoveHandler(element, this.OnHandPointerMove); KinectRegion.AddHandPointerPressHandler(element, this.OnHandPointerPress); KinectRegion.AddHandPointerGripHandler(element, this.OnHandPointerGrip); KinectRegion.AddHandPointerGripReleaseHandler(element, this._onHandPointerGripRelease); KinectRegion.AddQueryInteractionStatusHandler(element, this.OnQueryInteractionStatus); KinectRegion.SetIsGripTarget(element, true); KinectState.Instance.KinectRegion.HandPointersUpdated += KinectRegion_HandPointersUpdated; }