示例#1
0
        public static void trackJointProgression(Skeleton skeleton, Joint joint)
        {
            if (!jointPosition.ContainsKey(skeleton.TrackingId)) {
                jointPosition.Add(skeleton.TrackingId, new Dictionary<JointType,SkeletonPoint>());
            }

            if (!jointPosition[skeleton.TrackingId].ContainsKey(joint.JointType))
            {
                //We don't have a record of this joint so far, so make one
                jointPosition[skeleton.TrackingId].Add(joint.JointType, new SkeletonPoint());

                if (!difference.ContainsKey(skeleton.TrackingId)) {
                    difference.Add(skeleton.TrackingId, new Dictionary<JointType, difference3>());
                }
                difference[skeleton.TrackingId].Add(joint.JointType, new difference3());

                //We can't do any more calculation. Stop now.
                return;
            }
            else
            {
                difference3 theDifference = new difference3();
                theDifference.X = joint.Position.X - jointPosition[skeleton.TrackingId][joint.JointType].X;
                theDifference.Y = joint.Position.Y - jointPosition[skeleton.TrackingId][joint.JointType].Y;
                theDifference.Z = joint.Position.Z - jointPosition[skeleton.TrackingId][joint.JointType].Z;

                difference[skeleton.TrackingId][joint.JointType] = theDifference;

                jointPosition[skeleton.TrackingId][joint.JointType] = joint.Position;
            }
        }
示例#2
0
        public static void listenForGestures(Skeleton skeleton)
        {
            if (MainWindow.gestureSkeletonKey == skeleton.TrackingId || MainWindow.activeGesture == ActiveGesture.None)
            {
                if (!LeftGestureStatus.ContainsKey(skeleton.TrackingId))
                {
                    //If this is a skeleton we haven't tracked before, add them to our gesture tracking dictionary
                    addToGestureTracker(skeleton);
                }

                int angleDrift = 15;
                double anAngle;
                bool failed;

                if (LeftGesture != null)
                {
                    failed = true;

                    //Check if left hand stretched out
                    anAngle = getAngle(skeleton.Joints[JointType.ShoulderLeft].Position, skeleton.Joints[JointType.HandLeft].Position);

                    if (Math.Abs(anAngle - 90) < angleDrift && skeleton.Joints[JointType.HandLeft].Position.X < skeleton.Joints[JointType.ShoulderLeft].Position.X)
                    {
                        if (isLimbStraight(skeleton.Joints[JointType.ShoulderLeft], skeleton.Joints[JointType.ElbowLeft], skeleton.Joints[JointType.HandLeft], 30))
                        {
                            failed = false;
                            if (!LeftGestureStatus[skeleton.TrackingId])
                            {
                                toggleGestureStatus(skeleton, ref LeftGestureStatus, LeftGesture, true);
                            }
                        }
                    }

                    if (failed)
                    {
                        toggleGestureStatus(skeleton, ref LeftGestureStatus, LeftGesture, false);
                    }
                }

                if (KinectGuideGesture != null)
                {

                    failed = true;

                    anAngle = getAngle(skeleton.Joints[JointType.ShoulderLeft].Position, skeleton.Joints[JointType.WristLeft].Position);

                    //'Kinect Guide' gesture
                    if ((Math.Abs(anAngle - 45) < angleDrift) && (skeleton.Joints[JointType.HandLeft].Position.Y < getMidpoint(skeleton.Joints[JointType.Spine], skeleton.Joints[JointType.HipCenter]).Y) && (skeleton.Joints[JointType.HandLeft].Position.X < skeleton.Joints[JointType.Spine].Position.X))
                    {
                        if (isLimbStraight(skeleton.Joints[JointType.ShoulderLeft], skeleton.Joints[JointType.ElbowLeft], skeleton.Joints[JointType.HandLeft], 30))
                        {
                            failed = false;
                            if (!KinectGuideGestureStatus[skeleton.TrackingId])
                            {
                                toggleGestureStatus(skeleton, ref KinectGuideGestureStatus, KinectGuideGesture, true);
                            }
                        }
                    }

                    if (failed)
                    {
                        toggleGestureStatus(skeleton, ref KinectGuideGestureStatus, KinectGuideGesture, false);
                    }
                }

                failed = true;

                if (RightGesture != null)
                {
                    //Check if right hand stretched out
                    anAngle = getAngle(skeleton.Joints[JointType.ShoulderRight].Position, skeleton.Joints[JointType.HandRight].Position);

                    if (Math.Abs(anAngle - 90) < angleDrift && skeleton.Joints[JointType.HandRight].Position.X > skeleton.Joints[JointType.ShoulderRight].Position.X)
                    {
                        if (isLimbStraight(skeleton.Joints[JointType.ShoulderRight], skeleton.Joints[JointType.ElbowRight], skeleton.Joints[JointType.HandRight], 30))
                        {
                            failed = false;
                            if (!RightGestureStatus[skeleton.TrackingId])
                            {
                                toggleGestureStatus(skeleton, ref RightGestureStatus, RightGesture, true);
                            }
                        }
                    }

                    if (failed)
                    {
                        toggleGestureStatus(skeleton, ref RightGestureStatus, RightGesture, false);
                    }
                }

                if (LeftSwipeRight != null)
                {
                    if (difference[skeleton.TrackingId][JointType.HandLeft].X > 0.06)
                    {
                        if (leftSwipeRightIn == null)
                        {
                            leftSwipeRightIn = new gesturePoint();

                            //Create a new start point
                            difference3 newPosition = new difference3();
                            newPosition.X = skeleton.Joints[JointType.HandLeft].Position.X;
                            newPosition.Y = skeleton.Joints[JointType.HandLeft].Position.Y;
                            newPosition.Z = skeleton.Joints[JointType.HandLeft].Position.Z;

                            leftSwipeRightIn.Position = newPosition;
                            leftSwipeRightIn.Timestamp = currentTimestamp;
                        }
                    }
                    else
                    {
                        if (leftSwipeRightIn != null)
                        {
                            //Create a new end point, then compare
                            //Creating the end point
                            leftSwipeRightOut = new gesturePoint();

                            difference3 newPosition = new difference3();
                            newPosition.X = skeleton.Joints[JointType.HandLeft].Position.X;
                            newPosition.Y = skeleton.Joints[JointType.HandLeft].Position.Y;
                            newPosition.Z = skeleton.Joints[JointType.HandLeft].Position.Z;

                            leftSwipeRightOut.Position = newPosition;
                            leftSwipeRightOut.Timestamp = currentTimestamp;

                            //Comparison
                            if ((leftSwipeRightOut.Position.X - leftSwipeRightIn.Position.X) >= 0.2 && (leftSwipeRightOut.Timestamp - leftSwipeRightIn.Timestamp) < 4000)
                            {
                                //Fire the event
                                toggleGestureStatus(skeleton, ref LeftSwipeRightStatus, LeftSwipeRight, true);
                                toggleGestureStatus(skeleton, ref LeftSwipeRightStatus, LeftSwipeRight, false);
                            }

                            //Reset both values
                            leftSwipeRightIn = null;
                            leftSwipeRightOut = null;
                        }
                    }
                }
            }
        }