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;
                }
            }
        }
 private Skeleton FindSkeleton()
 {
     var skeletonData = kinectSensor.SkeletonStream.OpenNextFrame(200);
     if (skeletonData != null)
     {
         Skeleton[] skeletons = new Skeleton[skeletonData.SkeletonArrayLength];
         skeletonData.CopySkeletonDataTo(skeletons);
         return skeletons.First();
     }
     return null;
 }
        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();
                    }
                }
            }
        }
示例#4
0
        private void get_postion2(AllFramesReadyEventArgs e)
        {
            // スケルトンフレームを取得する
            SkeletonFrame skeletonFrame = e.OpenSkeletonFrame();
            if (skeletonFrame == null) return;

            // スケルトンデータを取得する
            Skeleton[] skeletonData = new Skeleton[skeletonFrame.SkeletonArrayLength];
            skeletonFrame.CopySkeletonDataTo(skeletonData);

            //1プレーヤースケルトン
            var skeleton = skeletonData.First();
            if (skeleton.TrackingState != SkeletonTrackingState.Tracked && skeleton.TrackingState != SkeletonTrackingState.PositionOnly) return;

            //両手のポジション取得
            var left_joint = skeleton.Joints.Where(p => p.JointType == JointType.HandLeft).Single();
            var right_joint = skeleton.Joints.Where(p => p.JointType == JointType.HandRight).Single();
            //var right_joint2 = skeleton.Joints.Where(p => p.JointType == JointType.WristRight).Single();
            var right_Elbow = skeleton.Joints.Where(p => p.JointType == JointType.ElbowRight).Single();

            var left_v = new Microsoft.Xna.Framework.Vector3(left_joint.Position.X, left_joint.Position.Y, left_joint.Position.Z);
            var right_v = new Microsoft.Xna.Framework.Vector3(right_joint.Position.X, right_joint.Position.Y, right_joint.Position.Z);
            var right_Elbow_v = new Microsoft.Xna.Framework.Vector3(right_Elbow.Position.X, right_Elbow.Position.Y, right_Elbow.Position.Z);

            //両手の距離
            Microsoft.Xna.Framework.Vector3 vec1 = left_v - right_v;
            float len = vec1.Length();

            if (len_back == 0) { len_back = len; return; }

            int step;
            #region 拡大・縮小
            step = 10;
            if (len_back > len)
            {
                MouseWinAPI.SendRightButtonDown(SssimWnd, 1, 1);
                MouseWinAPI.SendMouseMove(SssimWnd, 1, step);
                MouseWinAPI.SendRightButtonUp(SssimWnd, 1, step);
            }
            else
            {
                MouseWinAPI.SendRightButtonDown(SssimWnd, 1, step);
                MouseWinAPI.SendMouseMove(SssimWnd, 1, 1);
                MouseWinAPI.SendRightButtonUp(SssimWnd, 1, step);
            }
            len_back = len;
            #endregion

            #region 回転
            step = 2;

            //左手、右手、右ひじの、外積を求める
            Microsoft.Xna.Framework.Vector3 v1 = right_v - left_v; //右手位置-左手位置
            Microsoft.Xna.Framework.Vector3 v2 = right_Elbow_v - left_v; //右ひじ置-左手位置
            Microsoft.Xna.Framework.Vector3 v3 = Vector3.Cross(v1, v2);

            //前回ベクトルと、現在ベクトルの差
            Microsoft.Xna.Framework.Vector3 now_vec = v3_old - v3;

            MouseWinAPI.SendLeftButtonDown(SssimWnd, 100, 100);

            int x = (int)(now_vec.X * 1000) * step;
            int y = (int)(now_vec.Y * 1000) * step;
            MouseWinAPI.SendMouseMove(SssimWnd, 100 + x, 100 + y);
            MouseWinAPI.SendLeftButtonUp(SssimWnd, 100 + x, 100 + y);

            label1.Content = "X=" + x;
            label2.Content = "Y=" + y;

            v3_old = v3;

            #endregion
        }