예제 #1
0
        private void GestureRecognition(Skeleton[] skeletons)
        {
            if (skeletons.Count(t => t.TrackingState == SkeletonTrackingState.Tracked) >= 1)
            {
                Skeleton skel = skeletons.First(s => s.TrackingState == SkeletonTrackingState.Tracked);
                Joint handRight = skel.Joints[JointType.HandRight];
                Joint hipRight = skel.Joints[JointType.HipRight];
                Joint spine = skel.Joints[JointType.Spine];

                startRect = GetGestureRect(skel);
                TransformRectangle();
                handRightPoint = SkeletonPointToScreen(handRight.Position);

                isInRect = startRect.Contains(SkeletonPointToScreen(handRight.Position));
                if (isInRect != isInRectLastFrame)
                {
                    if (isInRect)
                    {
                        Hand.Visibility = Visibility.Hidden;
                        lockElement.Show();
                        entryPoint = handRight.Position;
                        isInGestureRect = true;
                    }
                    else
                    {
                        if(handRightPoint.X > startRect.TopRight.X) //leave right
                        {
                            HandleRectLeave();
                        }
                        else if (handRightPoint.Y > startRect.BottomLeft.Y) //leave bottom
                        {
                            HandleRectLeave();
                        }
                        else if(handRightPoint.Y < startRect.TopLeft.Y) //leave top
                        {
                            HandleRectLeave();
                        }
                    }
                }
                isInRectLastFrame = isInRect;

                if (isInGestureRect)
                {
                    if (handRight.Position.X < entryPoint.X)
                    {
                        lockElement.Position = Math.Abs(entryPoint.X - handRight.Position.X) / Math.Abs(entryPoint.X - spine.Position.X);
                    }
                    else
                    {
                        entryPoint = handRight.Position;
                    }
                    if (handRight.Position.X <= spine.Position.X)
                    {
                        SwipeRight();
                        HandleRectLeave();
                    }
                }
            }
        }
        private void GestureRecognition(Skeleton[] skeletons)
        {
            if (skeletons.Count(t => t.TrackingState == SkeletonTrackingState.Tracked) >= 1)
            {
                Skeleton skel = skeletons.First(s => s.TrackingState == SkeletonTrackingState.Tracked);
                Joint handRight = skel.Joints[JointType.HandRight];
                Joint hipRight = skel.Joints[JointType.HipRight];
                Joint spine = skel.Joints[JointType.Spine];

                innerRect = GetInnerRect(skel);
                outerRect = GetOuterRect(innerRect);
                TransformRectangles();
                TransformHand();
                handRightPoint = SkeletonPointToScreen(handRight.Position);

                isInRect = innerRect.Contains(handRightPoint);

                isInInnerRect = innerRect.Contains(handRightPoint);
                isInOuterRect = outerRect.Contains(handRightPoint);

                // Inneres Rechteck wurde betreten oder verlassen
                if(isInInnerRect != wasInLastFrameInInnerRect)
                {
                    // Inneres Rechteck wurde betreten
                    if (isInInnerRect)
                    {
                        // Fade-out: Save timestamp when enter the inner rect
                        enterInnerRectTimestamp = getTimeStamp();
                        wasInInnerRect = true;
                    }
                    // Inneres Rechteck wurde verlassen
                    else
                    {
                        // Fade-out: Stop animation
                        //if ()
                        if (handRightPoint.X > innerRect.TopRight.X) //leave right
                        {
                            BackColor.Fill = NextColor();
                        }
                        else if (handRightPoint.X < innerRect.TopLeft.X) //leave left
                        {
                            BackColor.Fill = PrevColor();
                        }
                        else if (handRightPoint.Y > innerRect.BottomLeft.Y) //leave bottom
                        {
                            BackColor.Fill = NextColorBlock();
                        }
                        else if (handRightPoint.Y < innerRect.TopLeft.Y) //leave top
                        {
                            BackColor.Fill = PrevColorBlock();
                        }
                    }
                    wasInLastFrameInInnerRect = isInInnerRect;
                }

                // Aeusseres Rechteck wurde betreten oder verlassen
                if (isInOuterRect != wasInLastFrameInOuterRect)
                {
                    // Aeusseres Rechteck wurde betreten
                    if (isInOuterRect)
                    {
                    }
                    // Aeusseres Rechteck wurde verlassen
                    else
                    {
                        if (wasInInnerRect)
                        {
                            if (handRightPoint.X > outerRect.TopRight.X) //leave right
                            {
                                SwipeRight();
                            }
                            else if (handRightPoint.X < outerRect.TopLeft.X) //leave left
                            {
                                SwipeLeft();
                            }
                            else if (handRightPoint.Y > outerRect.BottomLeft.Y) //leave bottom
                            {
                                SwipeDown();
                            }
                            else if (handRightPoint.Y < outerRect.TopLeft.Y) //leave top
                            {
                                SwipeUp();
                            }
                            wasInInnerRect = false;
                            FrontColor.Fill = CurrentColor();
                            TransformFrontColor(0, 0);
                        }
                    }
                }
                wasInLastFrameInOuterRect = isInOuterRect;

                if (isInOuterRect && !isInInnerRect && wasInInnerRect)
                {
                    double swipeLeft = GetPercentageSwipeLeft(handRightPoint);
                    double swipeRight = GetPercentageSwipeRight(handRightPoint);
                    double swipeTop = GetPercentageSwipeTop(handRightPoint);
                    double swipeBottom = GetPercentageSwipeBottom(handRightPoint);
                    if(swipeLeft >= 0)
                    {
                        TransformFrontColor(-swipeLeft, 0);
                    }
                    if (swipeRight >= 0)
                    {
                        TransformFrontColor(swipeRight, 0);
                    }
                    if (swipeTop >= 0)
                    {
                        TransformFrontColor(0, -swipeTop);
                    }
                    if (swipeBottom >= 0)
                    {
                        TransformFrontColor(0, swipeBottom);
                    }
                }

                //Fade-out: If true, start fade animation
                if (getTimeStamp() - enterInnerRectTimestamp > rectFadeOutTimer && isInInnerRect)
                {
                    wasInInnerRect = false;
                }
            }
        }
         //Skeleton FrameEdges ready event - start DTW processing
        void SkeletonFrameReady_Init_DTW_Process(object sender, SkeletonFrameReadyEventArgs e)
        {
            //Get the skeletons from the skeleton frame
            //Some frames come back empty - check for null
            SkeletonFrame skeleton_frame = e.OpenSkeletonFrame();
            if (skeleton_frame == null)
            {
                //Do nothin'
                return;
            }

            //Init a new skeletons array of proper size
            Skeleton[] skeletons = new Skeleton[skeleton_frame.SkeletonArrayLength];
            //Copy data into array
            skeleton_frame.CopySkeletonDataTo(skeletons);

            //For each skeleton, process the data
            //Keep an 'index' of which of the two tracked skeletons is being passed
            int num_tracked = 0;
            for (int i = 0; i < skeletons.Count<Skeleton>(); i++)
            {
                //Only do DTW for skeletons which are fully tracked
                if(skeletons[i].TrackingState == SkeletonTrackingState.Tracked)
                {
                    //Get the event args
                    Skeleton2DdataCoordEventArgs args = Skeleton2DDataExtract.skeletonToSkeleton2DdataCoordEventArgs(skeletons[i],num_tracked);
                    //Launch the events
                    Skeleton2DdataCoordReady(null, args);
                    num_tracked++;
                    //Stop looping if this was the second (max) tracked skeleton 
                    if(num_tracked >= MAX_TRACKED_SKELETONS)
                    {
                        break;
                    }
                }
            }

            //A warning told me to do this - and I am code monkey.
            skeleton_frame.Dispose();
        }