private KinectCursorManager(Window window, KinectSensor sensor, FrameworkElement cursor) { this.window = window; if (KinectSensor.KinectSensors.Count > 0) { window.Unloaded += delegate { if (this.kinectSensor.SkeletonStream.IsEnabled) { this.kinectSensor.SkeletonStream.Disable(); } }; window.Loaded += delegate { if (cursor == null) { cursorAdorner = new CursorAdorner((FrameworkElement)window.Content); } else { cursorAdorner = new CursorAdorner((FrameworkElement)window.Content, cursor); } this.kinectSensor = sensor; this.kinectSensor.SkeletonFrameReady += SkeletonFrameReady; this.kinectSensor.SkeletonStream.Enable(new TransformSmoothParameters()); this.kinectSensor.Start(); }; } }
private void SetHandTrackingDeactivated() { CursorAdorner.SetVisibility(false); if (lastElementOver != null && isHandTrackingActivated == true) { lastElementOver.RaiseEvent(new RoutedEventArgs(KinectInput.KinectCursorDeactivatedEvent)); } isHandTrackingActivated = false; }
private void AnimateCursorAwayFromLockPosition(KinectCursorEventArgs e, CursorAdorner cursor, ref Point lockPoint, ref Point cursorPoint) { DoubleAnimation moveLeft = new DoubleAnimation(lockPoint.X, cursorPoint.X, new Duration(TimeSpan.FromMilliseconds(UnlockInterval))); Storyboard.SetTarget(moveLeft, cursor.CursorVisual); Storyboard.SetTargetProperty(moveLeft, new PropertyPath(Canvas.LeftProperty)); DoubleAnimation moveTop = new DoubleAnimation(lockPoint.Y, cursorPoint.Y, new Duration(TimeSpan.FromMilliseconds(UnlockInterval))); Storyboard.SetTarget(moveTop, cursor.CursorVisual); Storyboard.SetTargetProperty(moveTop, new PropertyPath(Canvas.TopProperty)); move = new Storyboard(); move.Children.Add(moveTop); move.Children.Add(moveLeft); move.Completed += delegate { move.Stop(cursor); cursor.UpdateCursor(new Point(e.X, e.Y), false); this.RaiseEvent(new KinectCursorEventArgs(KinectCursorUnlockEvent, new Point(e.X, e.Y), e.Z) { Cursor = e.Cursor }); }; move.Begin(cursor, true); }
private void AnimateCursorToLockPosition(KinectCursorEventArgs e, double x, double y, CursorAdorner cursor, ref Point lockPoint, ref Point cursorPoint) { DoubleAnimation moveLeft = new DoubleAnimation(cursorPoint.X, lockPoint.X, new Duration(TimeSpan.FromMilliseconds(LockInterval))); Storyboard.SetTarget(moveLeft, cursor.CursorVisual); Storyboard.SetTargetProperty(moveLeft, new PropertyPath(Canvas.LeftProperty)); DoubleAnimation moveTop = new DoubleAnimation(cursorPoint.Y, lockPoint.Y, new Duration(TimeSpan.FromMilliseconds(LockInterval))); Storyboard.SetTarget(moveTop, cursor.CursorVisual); Storyboard.SetTargetProperty(moveTop, new PropertyPath(Canvas.TopProperty)); move = new Storyboard(); move.Children.Add(moveTop); move.Children.Add(moveLeft); move.Completed += delegate { this.RaiseEvent(new KinectCursorEventArgs(KinectCursorLockEvent, new Point(x, y), e.Z) { Cursor = e.Cursor }); }; if (move != null) { move.Stop(e.Cursor); } move.Begin(cursor, false); }