diff --git a/MyGestureBank/PostureHandDownRight.cs b/MyGestureBank/PostureHandDownRight.cs index c010095..1b1f6bc 100644 --- a/MyGestureBank/PostureHandDownRight.cs +++ b/MyGestureBank/PostureHandDownRight.cs @@ -29,7 +29,7 @@ namespace MyGestureBank { // Check if right hand is below the right hip var result = body.Joints[JointType.HandRight].Position.Y < body.Joints[JointType.HipRight].Position.Y && - body.Joints[JointType.HandLeft].Position.Y > body.Joints[JointType.HipLeft].Position.Y && + body.Joints[JointType.HandLeft].Position.Y > body.Joints[JointType.SpineBase].Position.Y && body.Joints[JointType.HandLeft].Position.Y < body.Joints[JointType.SpineShoulder].Position.Y; return result; diff --git a/MyGestureBank/PostureHandUpLeft.cs b/MyGestureBank/PostureHandUpLeft.cs index f4f9bb4..c2474ef 100644 --- a/MyGestureBank/PostureHandUpLeft.cs +++ b/MyGestureBank/PostureHandUpLeft.cs @@ -30,7 +30,7 @@ namespace MyGestureBank // Check if the left hand is above the left shoulder return body.Joints[JointType.HandLeft].Position.Y > body.Joints[JointType.SpineShoulder].Position.Y && body.Joints[JointType.HandRight].Position.Y < body.Joints[JointType.SpineShoulder].Position.Y && - body.Joints[JointType.HandRight].Position.Y > body.Joints[JointType.HipRight].Position.Y; + body.Joints[JointType.HandRight].Position.Y > body.Joints[JointType.SpineBase].Position.Y; } } } diff --git a/MyGestureBank/SoccerShootGesture .cs b/MyGestureBank/SoccerShootGesture .cs index f6a75df..fcb3b04 100644 --- a/MyGestureBank/SoccerShootGesture .cs +++ b/MyGestureBank/SoccerShootGesture .cs @@ -9,6 +9,9 @@ using System.Threading.Tasks; namespace MyGestureBank { + /// + /// The soccer shoot gesture. + /// public class SoccerShootGesture : Gesture { private CameraSpacePoint lastLeftFootPosition; @@ -20,17 +23,24 @@ namespace MyGestureBank MaxNbOfFrames = 30; } + /// + /// Tests if the gesture is recognized. + /// + /// public override void TestGesture(Body body) { if (TestPosture(body)) { Console.WriteLine("Gesture recognized, shooting motion"); - Thread.Sleep(1000); - OnGestureRecognized(); } } + /// + /// Tests the end conditions of the gesture. + /// + /// + /// protected override bool TestEndConditions(Body body) { float threshold = 0.05f; @@ -39,25 +49,42 @@ namespace MyGestureBank return areFeetClose; } + /// + /// Tests the intial conditions of the gesture. + /// + /// + /// protected override bool TestInitialConditions(Body body) { + // Position of the feet + hips and head CameraSpacePoint currentLeftFootPosition = body.Joints[JointType.FootLeft].Position; CameraSpacePoint currentRightFootPosition = body.Joints[JointType.FootRight].Position; CameraSpacePoint currentHipPosition = body.Joints[JointType.SpineBase].Position; CameraSpacePoint currentHeadPosition = body.Joints[JointType.Head].Position; + // X and Y that should be respected bool isWithinDistanceX = Math.Abs(currentLeftFootPosition.X - currentRightFootPosition.X) < Math.Abs(currentHipPosition.Y - currentHeadPosition.Y); bool isWithinRangeY = IsFootBetweenHeadAndSpinBase(body.Joints[JointType.FootRight].Position, body.Joints[JointType.Head].Position, body.Joints[JointType.SpineBase].Position); return isWithinDistanceX && isWithinRangeY; } + /// + /// Test the posture + /// + /// + /// protected override bool TestPosture(Body body) { bool isWithinRangeY = IsFootBetweenHeadAndSpinBase(body.Joints[JointType.FootRight].Position, body.Joints[JointType.Head].Position, body.Joints[JointType.SpineBase].Position); return isWithinRangeY; } + /// + /// Tests the running gesture + /// + /// + /// protected override bool TestRunningGesture(Body body) { CameraSpacePoint currentLeftFootPosition = body.Joints[JointType.FootLeft].Position; diff --git a/PenaltyMaster3000/Helpers/VisibilityManager.cs b/PenaltyMaster3000/Helpers/VisibilityManager.cs index 40fe02d..af2c712 100644 --- a/PenaltyMaster3000/Helpers/VisibilityManager.cs +++ b/PenaltyMaster3000/Helpers/VisibilityManager.cs @@ -195,18 +195,22 @@ namespace PenaltyMaster3000.Helpers switch (gesturePosition) { case "HandUpRight": + HideQuestionPoint(); QuestionPointTopRightVisibility = Visibility.Visible; break; case "HandUpLeft": + HideQuestionPoint(); QuestionPointTopLeftVisibility = Visibility.Visible; break; case "HandDownRight": + HideQuestionPoint(); QuestionPointDownRightVisibility = Visibility.Visible; break; case "HandDownLeft": + HideQuestionPoint(); QuestionPointDownLeftVisibility = Visibility.Visible; break; @@ -258,7 +262,7 @@ namespace PenaltyMaster3000.Helpers break; case "HandDownLeft": - BallTopRightVisibility = Visibility.Visible; + BallDownLeftVisibility = Visibility.Visible; break; default: return; diff --git a/PenaltyMaster3000/View/MainView.xaml b/PenaltyMaster3000/View/MainView.xaml index cc7737a..25ccf28 100644 --- a/PenaltyMaster3000/View/MainView.xaml +++ b/PenaltyMaster3000/View/MainView.xaml @@ -27,21 +27,21 @@ Grid.Row="0" Grid.RowSpan="2" Grid.Column="0" - Visibility="{Binding VsMgr.GoalTopRightVisibility}"/> + Visibility="{Binding VsMgr.GoalTopLeftVisibility}"/> + Visibility="{Binding VsMgr.BallTopLeftVisibility}"/> + Visibility="{Binding VsMgr.QuestionPointTopLeftVisibility}"/> + Visibility="{Binding VsMgr.GoalTopRightVisibility}"/> + Visibility="{Binding VsMgr.BallTopRightVisibility}"/> + Visibility="{Binding VsMgr.QuestionPointTopRightVisibility}"/> + Visibility="{Binding VsMgr.GoalDownLeftVisibility}"/> + Visibility="{Binding VsMgr.BallDownLeftVisibility}"/> + Visibility="{Binding VsMgr.QuestionPointDownLeftVisibility}"/> + Visibility="{Binding VsMgr.GoalDownRightVisibility}"/> + Visibility="{Binding VsMgr.BallDownRightVisibility}"/> + Visibility="{Binding VsMgr.QuestionPointDownRightVisibility}"/> ReadAGesture(int ReadTimeInSeconds) + private Task ReadAPosture() { + var tcs = new TaskCompletionSource(); string gestureRead = ""; // load all @@ -403,27 +404,72 @@ namespace PenaltyMaster3000.ViewModel // If new gesture read, replace th gesture name if(gestureRead != args.GestureName) { - // [TODO?] Display gesture on screen + // save the recognized gesture gestureRead = args.GestureName; + // display where VsMgr.SetQuestionPoint(gestureRead); - + if (!tcs.Task.IsCompleted) + { + tcs.SetResult(args.GestureName); + } } }; } // Read frames for ReadTimeSeconds GestureManager.StartAcquiringFrames(GestureManager.KinectManager); - await Task.Delay(ReadTimeInSeconds*5000); - // Stop reading and unsub from the GestureRecognized event to prevent memory leaks - GestureManager.StopAcquiringFrame(GestureManager.KinectManager); + return tcs.Task.ContinueWith(t => + { + // Stop reading and unsub from the GestureRecognized event to prevent memory leaks + GestureManager.StopAcquiringFrame(GestureManager.KinectManager); + foreach (var gesture in GestureManager.KnownGestures) + { + gesture.GestureRecognized = null; + } + + return t.Result; + }); + } + + private Task ReadShootingGesture() + { + var tcs = new TaskCompletionSource(); + + // load all + GestureManager.AddGestures(this.GestureFactory); + + // subscribe to the OnGestureRecognized event foreach (var gesture in GestureManager.KnownGestures) { - gesture.GestureRecognized = null; + var soccerShootGesture = gesture as SoccerShootGesture; + if (soccerShootGesture != null) + { + soccerShootGesture.GestureRecognized += (sender, args) => + { + if (!tcs.Task.IsCompleted) + { + tcs.SetResult(true); + } + }; + + } } - // return gestureRead; - return gestureRead; + // Read frames for ReadTimeInSeconds + GestureManager.StartAcquiringFrames(GestureManager.KinectManager); + + return tcs.Task.ContinueWith(t => + { + // Stop reading and unsub from the GestureRecognized event to prevent memory leaks + GestureManager.StopAcquiringFrame(GestureManager.KinectManager); + foreach (var gesture in GestureManager.KnownGestures) + { + gesture.GestureRecognized = null; + } + + return t.Result; + }); } } }