private async void WindowLoaded(object sender, RoutedEventArgs windowLoadedArgs) { // In XAML, we have specified a 3D scene containing a cube. We would like to use our hand to control the camera in this scene. // The following gesture subscribes to the hand skeleton stream whenever our hand forms the pinch pose. The information in // the skeleton stream will be used to move the camera. // Data flow outline: // [GestureServiceEndpoint]-----Skeleton----->[PalmSmoother]-----SmoothedPositionDelta----->[SphericalCamera] // We would like to translate hand motion to camera motion. Because the palm position // values in the skeleton stream contain some jitter, we smooth them (using a moving-average window). _palmSmoother = new PalmSmoother(); // Define the gesture so that when the hand forms a pinch pose register to the skeleton stream and pass it to the palm smoother. var pinchClose = new PinchPose("PinchClosePose", pinchSpread: false); pinchClose.Triggered += (s, args) => _gesturesService.RegisterToSkeleton((s1, args1) => _palmSmoother.Smooth(args1.DefaultHandSkeleton)); _cameraPinch = new Gesture("CameraPinch", new PinchPose("PinchOpenPose", pinchSpread: true), pinchClose, new PinchPose("PinchReleasePose", pinchSpread: true)); _cameraPinch.IdleTriggered += (s, args) => _gesturesService.UnregisterFromSkeleton(); // The smoothed palm position is used to rotate the camera. _sphericalCamera = new SphericalCamera(Camera, Dispatcher); _palmSmoother.SmoothedPositionChanged += (s, args) => _sphericalCamera.UpdateCamera(args.SmoothedPositionDelta); // Connect to the Gestures Service and register the gesture we've defined _gesturesService = GesturesServiceEndpointFactory.Create(); _gesturesService.StatusChanged += (s, arg) => Dispatcher.Invoke(() => GesturesServiceStatus.Text = $"[{arg.Status}]"); await _gesturesService.ConnectAsync(); await _gesturesService.RegisterGesture(_cameraPinch); }
private async void WindowLoaded(object sender, RoutedEventArgs windowLoadedArgs) { IndexPosition = new FingerPosition(this.Canvas, this.Dispatcher, this.IndexEllipse, Finger.Index); ThumbPosition = new FingerPosition(this.Canvas, this.Dispatcher, this.ThumbEllipse, Finger.Thumb); MiddlePosition = new FingerPosition(this.Canvas, this.Dispatcher, this.MiddleEllipse, Finger.Middle); RingPosition = new FingerPosition(this.Canvas, this.Dispatcher, this.RingEllipse, Finger.Ring); PinkyPosition = new FingerPosition(this.Canvas, this.Dispatcher, this.PinkyEllipse, Finger.Pinky); _gesturesService = GesturesServiceEndpointFactory.Create(); await _gesturesService.ConnectAsync(); await _gesturesService.RegisterToSkeleton(SkeletonHandler); }