/// <summary> /// Callback method for any "gestured recognized" event that is triggered. /// Will in turn invoke the registered callback of the client, if any is available. /// </summary> /// <param name="sender">Object that triggered the event</param> /// <param name="e">Triggered event arguments</param> public void KinectGesture_KinectGestureRecognized(object sender, KinectGestureEventArgs e) { // Inkoke callback method if the client registered one. if (this.KinectGestureRecognized != null) { this.KinectGestureRecognized(this, e); } // Reset all gesture states foreach (KinectGesture gesture in this.recognizableGestures) { gesture.ResetGesture(); } }
/// <summary> /// Updates the gesture state. If a gesture is successfully recognized /// an event is triggered. /// </summary> /// <param name="skeleton">Skeleton to analyze</param> public void UpdateGesture(Skeleton skeleton) { // Checks if the enough time between active frame checks // has passed, unpausing them if if true. if (this.gesturePaused) { if (this.currentFrameCount == this.pausedFrameCount) { this.gesturePaused = false; } this.currentFrameCount++; } // Compares the skeleton data with the current frame. KinectGestureResult result = this.gestureFrames[this.currentFrameIndex].ProcessFrame(skeleton); // In case of a successful recognition, moves on to the next frame if there's any, // otherwise triggers the recognized gesture event. if (result == KinectGestureResult.Success) { if (this.currentFrameIndex + 1 < this.gestureFrames.Length) { this.currentFrameIndex++; this.currentFrameCount = 0; this.pausedFrameCount = 10; this.gesturePaused = true; } else { // Triggers any registered event if (this.KinectGestureRecognized != null) { KinectGestureEventArgs args = new KinectGestureEventArgs(this.gestureType, skeleton.TrackingId); this.KinectGestureRecognized(this, args); } // Resets the gesture state. this.ResetGesture(); } } // If the gesture recognition failed beyond recovery, or the gesture is being // processed for to long, the gesture state is reseted. else if (result == KinectGestureResult.Fail || this.currentFrameCount == 50) { this.currentFrameIndex = 0; this.currentFrameCount = 0; this.pausedFrameCount = 5; this.gesturePaused = true; } // If the gesture recognition was inconclusive and there's still // time to wait, the gesture waits for the next frame. else { this.currentFrameCount++; this.pausedFrameCount = 5; this.gesturePaused = true; } }
/// <summary> /// Handles gesture recognized events. /// </summary> /// <param name="sender">Event sender</param> /// <param name="args">Event arguments</param> public void callback_KinectGestureRecognized(object sender, KinectGestureEventArgs args) { // Engage animations. if (args.GestureType == KinectGestureType.WaveRightHand && this.skeletonId == -1 && !endGame) { this.skeletonId = args.TrackingId; token = ""; this.endGame = false; this.controller.StartTrackingSkeleton(this.skeletonId); foreach(var parts in hitSkeleton.BodyParts) { if(parts.Key == HitSkeletonBodyPart.ForearmLeft || parts.Key == HitSkeletonBodyPart.ForearmRight) { parts.Value.State = BodyPartState.Armor; } else { parts.Value.State = BodyPartState.NotHit; } } // Paddle animation. this.hitSkeleton.PaddleRight.State = PaddleState.NotHit; this.hitSkeleton.PaddleLeft.State = PaddleState.NotHit; // Background animation. Storyboard backgroundSb = (Storyboard)this.FindResource("BackgroundFadeOutStoryboard"); Storyboard backgroundImgSb = (Storyboard)this.FindResource("BackgroundFadeOutImageStoryboard"); this.OverlayBackRectangle.BeginStoryboard(backgroundSb); this.OverlayRectangle.BeginStoryboard(backgroundImgSb); // Scoreboard animation. Storyboard sb = (Storyboard)this.FindResource("ScoreboardAppearStoryboard"); sb.Begin(); // Start websocket client. ws = new WebSocket("ws://192.168.27.133:1234/"); ws.OnMessage += ws_OnMessage; ws.Connect(); } }