예제 #1
0
        public void ParseBody(Body playerBody, long timeStamp)
        {
            filter.UpdateFilter(playerBody);
            var joints = filter.GetFilteredJoints();


            JointType pointerHand = LeftHand ? JointType.HandLeft : JointType.HandRight;
            JointType throwHand   = LeftHand ? JointType.HandRight : JointType.HandLeft;

            var pointerLocation = joints[(int)pointerHand];
            var throwLocation   = joints[(int)throwHand];

            var       throwTrackingState = playerBody.Joints[throwHand].TrackingState;
            HandState handState          = LeftHand ? playerBody.HandLeftState : playerBody.HandRightState;

            if (!initialized)
            {
                center   = joints[(int)JointType.SpineShoulder].Y + 0.15f;
                LeftHand = joints[(int)JointType.HandLeft].Z < joints[(int)JointType.HandRight].Z;
                board.PointAt(pointerLocation.X, pointerLocation.Y - center);
                return;
            }

            bool t = joints[(int)JointType.HandLeft].Z < joints[(int)JointType.HandRight].Z;

            if (LeftHand != t)
            {
                if (!handChangeTimer.Enabled)
                {
                    handChangeTimer.Start();
                }
            }
            else
            {
                if (handChangeTimer.Enabled)
                {
                    handChangeTimer.Stop();
                }
            }

            KinectGesture throwGesture = IsThrowing(throwLocation.Z, timeStamp);

            if (throwGesture != null &&
                throwTrackingState == TrackingState.Tracked &&
                playerBody.Joints[pointerHand].Position.Y > playerBody.Joints[JointType.HipRight].Position.Y)
            {
                GestureParser.AddKinectGesture(throwGesture);
            }


            if (HandStateChanged(handState))
            {
                GestureParser.AddKinectGesture(handGesture);
            }
            board.PointAt(pointerLocation.X, pointerLocation.Y - center);
        }
예제 #2
0
        public static void AddKinectGesture(KinectGesture receivedGesture)
        {
            Console.WriteLine($"{DateTime.Now.ToString("h:mm:ss tt")}: KINECT: {receivedGesture.Type} {receivedGesture.Direction}");
            if (paused) return;
            Logger.CurrentLogger.AddNewKinectGesture(receivedGesture, board.GetCell(receivedGesture.Pointer));
            if (typeContext == receivedGesture.Type) {
                switch (receivedGesture.Type) {
                    case GestureType.Pinch:
                        {
                            if (directionContext == receivedGesture.Direction) {
                                if (directionContext == GestureDirection.Pull) {
                                    board.LockPointer();
                                    string shape = "";
                                    shape = board.GetCell(receivedGesture.Pointer)?.Shape is Ellipse ? "circle" : "square";
                                    KinectGesture gesture = new KinectGesture(shape);
                                    connection.SendPinch();
                                    ClearGestures();
                                    waitingKinectGesture = gesture;
                                } else if (waitingMobileGesture != null) {
                                    KinectGesture gesture = new KinectGesture(waitingMobileGesture.Shape);
                                    ClearGestures();
                                    AwaitingGesture = gesture;
                                }
                            }
                            else if(directionContext == GestureDirection.Pull && receivedGesture.Direction == GestureDirection.Push) {
                                /*ClearGestures();
                                board.UnlockPointer();*/
                            }
                        }
                        break;
                    case GestureType.Throw:
                        {
                            if (directionContext != receivedGesture.Direction) {
                                ClearGestures();
                            } else if (waitingMobileGesture == null) {
                                ClearGestures();
                                waitingKinectGesture = receivedGesture;
                            } else if (waitingMobileGesture?.Type == GestureType.Throw) {
                                KinectGesture gesture = new KinectGesture(waitingMobileGesture.Shape);
                                ClearGestures();
                                AwaitingGesture = gesture;
                            } else {
                                ClearGestures();

                            }
                        }
                        break;
                }
            }
        }
예제 #3
0
 private bool HandStateChanged(HandState handstate)
 {
     if (handstate == HandState.Unknown)
     {
         return(false);
     }
     if (handstate != currentHandState)
     {
         if (handstate == HandState.Open)
         {
             currentHandState = handstate;
             handGesture      = new KinectGesture(GestureType.Pinch, GestureDirection.Push);
             return(true);
         }
         else if (handstate == HandState.Closed)
         {
             currentHandState = handstate;
             handGesture      = new KinectGesture(GestureType.Pinch, GestureDirection.Pull);
             return(true);
         }
         return(false);
     }
     return(false);
 }
예제 #4
0
 public virtual void ExtendedDraw(KinectGesture gesture)
 {
 }
예제 #5
0
        public void PointAt(double xFromMid, double yFromMid)
        {
            if (pointerFigure == null)
            {
                pointerFigure = ShapeFactory.CreatePointer(accuracyTest);
                canvas.Children.Add(pointerFigure);
                Canvas.SetZIndex(pointerFigure, 10000);
                xPoint = xFromMid;
                yPoint = yFromMid;
            }
            if (target != null)
            {
                target.GridCell.Fill = targetColor;
            }
            if (extraTarget != null)
            {
                extraTarget.GridCell.Fill = targetColor;
            }

            DrawNextTargets();
            if (AttemptRepository.SaveStatus == DatabaseSaveStatus.Saving && !savingToDB)
            {
                savingToDB = true;
                ShowStatusMessage("Saving to database...");
            }
            if (savingToDB && AttemptRepository.SaveStatus != DatabaseSaveStatus.Saving)
            {
                savingToDB = false;
                string status = AttemptRepository.SaveStatus == DatabaseSaveStatus.Failed ? "Failed!" : "Success!";
                ShowStatusMessage(status);
                Background = AttemptRepository.SaveStatus == DatabaseSaveStatus.Failed ? Brushes.Red : Brushes.Blue;
            }

            Point currentGyroPoint = new Point(GyroPositionX, -GyroPositionY);

            if (currentGyroPoint != lastGyroPoint)
            {
                lastGyroPoint = new Point(GyroPositionX, -GyroPositionY);
            }

            xPoint = xFromMid;
            yPoint = yFromMid;

            if (!lockedPointer)
            {
                pointer = GetPoint(xPoint, yPoint);
            }
            MoveShape(pointerFigure, pointer);
            if (!accuracyTest)
            {
                ColorCell(pointer);
            }
            KinectGesture gesture = GestureParser.AwaitingGesture;

            if (runningTest && runningGesture)
            {
                if (gesture != null)
                {
                    UnlockPointer();
                    GestureParser.Pause(true);
                    Cell currCell     = GetCell(pointer);
                    bool hit          = currCell == target;
                    bool correctShape = true;

                    string           shape     = target.Shape is Ellipse ? "circle" : "square";
                    GestureDirection direction = GestureParser.GetDirectionContext();
                    GestureType      type      = GestureParser.GetTypeContext();
                    if (direction == GestureDirection.Push)
                    {
                        correctShape = shape == gesture.Shape;
                    }
                    currentTest.TargetHit(hit, correctShape, target, pointer, currCell, currentLength);
                    if (hit && !correctShape)
                    {
                        hit = false;
                    }
                    TargetHit(target, hit);
                }
            }
            ExtendedDraw(gesture);
        }
예제 #6
0
 private bool HandStateChanged(HandState handstate)
 {
     if(handstate == HandState.Unknown) { return false; }
     if(handstate != currentHandState) {
         if(handstate == HandState.Open) {
             currentHandState = handstate;
             handGesture = new KinectGesture(GestureType.Pinch, GestureDirection.Push);
             return true;
         } else if (handstate == HandState.Closed) {
             currentHandState = handstate;
             handGesture = new KinectGesture(GestureType.Pinch, GestureDirection.Pull);
             return true;
         }
         return false;
     }
     return false;
 }
예제 #7
0
        static public void AddMobileGesture(MobileGesture receivedGesture)
        {
            Console.WriteLine($"{DateTime.Now.ToString("h:mm:ss tt")}: MOBILE: {receivedGesture.Type} {receivedGesture.Direction}");
            if (paused)
            {
                return;
            }
            Logger.CurrentLogger.AddNewMobileGesture(receivedGesture);
            if (receivedGesture.Type == typeContext)
            {
                switch (receivedGesture.Type)
                {
                case GestureType.Swipe: {
                    if (receivedGesture.Direction != GetDirectionContext())
                    {
                        return;
                    }
                    ClearGestures();
                    AwaitingGesture = new KinectGesture(receivedGesture.Shape);
                }
                break;

                case GestureType.Tilt: {
                    ClearGestures();
                    AwaitingGesture = new KinectGesture(receivedGesture.Shape);
                }
                break;

                case GestureType.Pinch: {
                    if (directionContext == receivedGesture.Direction)
                    {
                        if (directionContext == GestureDirection.Push)
                        {
                            if (waitingKinectGesture?.Direction == GestureDirection.Pull)
                            {
                                KinectGesture gesture = waitingKinectGesture;
                                ClearGestures();
                                AwaitingGesture = gesture;
                            }
                            else
                            {
                                ClearGestures();
                                waitingMobileGesture = receivedGesture;
                            }
                        }
                        else
                        {
                            if (waitingKinectGesture != null)
                            {
                                KinectGesture gesture = waitingKinectGesture;
                                ClearGestures();
                                AwaitingGesture = gesture;
                            }
                        }
                    }
                }
                break;

                case GestureType.Throw:
                    if (waitingKinectGesture?.Type == GestureType.Throw)
                    {
                        ClearGestures();
                        AwaitingGesture = new KinectGesture(receivedGesture.Shape);
                    }
                    else
                    {
                        ClearGestures();
                        waitingMobileGesture = receivedGesture;
                    }
                    break;
                }
            }
        }
예제 #8
0
        static public void AddKinectGesture(KinectGesture receivedGesture)
        {
            Console.WriteLine($"{DateTime.Now.ToString("h:mm:ss tt")}: KINECT: {receivedGesture.Type} {receivedGesture.Direction}");
            if (paused)
            {
                return;
            }
            Logger.CurrentLogger.AddNewKinectGesture(receivedGesture, board.GetCell(receivedGesture.Pointer));
            if (typeContext == receivedGesture.Type)
            {
                switch (receivedGesture.Type)
                {
                case GestureType.Pinch:
                {
                    if (directionContext == receivedGesture.Direction)
                    {
                        if (directionContext == GestureDirection.Pull)
                        {
                            board.LockPointer();
                            string shape = "";
                            shape = board.GetCell(receivedGesture.Pointer)?.Shape is Ellipse ? "circle" : "square";
                            KinectGesture gesture = new KinectGesture(shape);
                            connection.SendPinch();
                            ClearGestures();
                            waitingKinectGesture = gesture;
                        }
                        else if (waitingMobileGesture != null)
                        {
                            KinectGesture gesture = new KinectGesture(waitingMobileGesture.Shape);
                            ClearGestures();
                            AwaitingGesture = gesture;
                        }
                    }
                    else if (directionContext == GestureDirection.Pull && receivedGesture.Direction == GestureDirection.Push)
                    {
                        /*ClearGestures();
                         * board.UnlockPointer();*/
                    }
                }
                break;

                case GestureType.Throw:
                {
                    if (directionContext != receivedGesture.Direction)
                    {
                        ClearGestures();
                    }
                    else if (waitingMobileGesture == null)
                    {
                        ClearGestures();
                        waitingKinectGesture = receivedGesture;
                    }
                    else if (waitingMobileGesture?.Type == GestureType.Throw)
                    {
                        KinectGesture gesture = new KinectGesture(waitingMobileGesture.Shape);
                        ClearGestures();
                        AwaitingGesture = gesture;
                    }
                    else
                    {
                        ClearGestures();
                    }
                }
                break;
                }
            }
        }
예제 #9
0
 static public void ClearGestures()
 {
     waitingKinectGesture = null;
     waitingMobileGesture = null;
     awaitingGesture      = null;
 }
예제 #10
0
 public static void ClearGestures()
 {
     waitingKinectGesture = null;
     waitingMobileGesture = null;
     awaitingGesture = null;
 }
예제 #11
0
 public static void AddMobileGesture(MobileGesture receivedGesture)
 {
     Console.WriteLine($"{DateTime.Now.ToString("h:mm:ss tt")}: MOBILE: {receivedGesture.Type} {receivedGesture.Direction}");
     if (paused) return;
     Logger.CurrentLogger.AddNewMobileGesture(receivedGesture);
     if (receivedGesture.Type == typeContext) {
         switch (receivedGesture.Type) {
             case GestureType.Swipe: {
                     if (receivedGesture.Direction != GetDirectionContext()) return;
                     ClearGestures();
                     AwaitingGesture = new KinectGesture(receivedGesture.Shape);
                 }
                 break;
             case GestureType.Tilt: {
                     ClearGestures();
                     AwaitingGesture = new KinectGesture(receivedGesture.Shape);
                 }
                 break;
             case GestureType.Pinch: {
                     if (directionContext == receivedGesture.Direction) {
                         if (directionContext == GestureDirection.Push) {
                             if (waitingKinectGesture?.Direction == GestureDirection.Pull) {
                                 KinectGesture gesture = waitingKinectGesture;
                                 ClearGestures();
                                 AwaitingGesture = gesture;
                             } else {
                                 ClearGestures();
                                 waitingMobileGesture = receivedGesture;
                             }
                         } else {
                             if(waitingKinectGesture != null) {
                                 KinectGesture gesture = waitingKinectGesture;
                                 ClearGestures();
                                 AwaitingGesture = gesture;
                             }
                         }
                     }
                 }
                 break;
             case GestureType.Throw:
                 if (waitingKinectGesture?.Type == GestureType.Throw) {
                     ClearGestures();
                     AwaitingGesture = new KinectGesture(receivedGesture.Shape);
                 } else {
                     ClearGestures();
                     waitingMobileGesture = receivedGesture;
                 }
                 break;
         }
     }
 }