コード例 #1
0
        private void KinectSkeletonFrameReady(object sender, SkeletonFrameReadyEventArgs e)
        {
            var skeletons = new Skeleton[0];

            using (var skeletonFrame = e.OpenSkeletonFrame())
            {
                if (skeletonFrame != null)
                {
                    skeletons = new Skeleton[skeletonFrame.SkeletonArrayLength];
                    skeletonFrame.CopySkeletonDataTo(skeletons);
                }
            }

            if (skeletons.Length == 0)
            {
                return;
            }

            var skel = skeletons.FirstOrDefault(x => x.TrackingState == SkeletonTrackingState.Tracked);

            if (skel == null)
            {
                return;
            }

            var leftHand   = skel.Joints[JointType.WristLeft];
            var rightHand  = skel.Joints[JointType.WristRight];
            var shoulder   = skel.Joints[JointType.ShoulderCenter];
            var leftElbow  = skel.Joints[JointType.ElbowLeft];
            var rightElbow = skel.Joints[JointType.ElbowRight];


            XValueLeft.Text = leftHand.Position.X.ToString(CultureInfo.InvariantCulture);
            YValueLeft.Text = leftHand.Position.Y.ToString(CultureInfo.InvariantCulture);
            ZValueLeft.Text = leftHand.Position.Z.ToString(CultureInfo.InvariantCulture);

            // Check if at height
            if (leftHand.Position.Y >= shoulder.Position.Y - 0.15 && rightHand.Position.Y >= shoulder.Position.Y - 0.15)
            {
                InTPos.Text = "Yes";
                if (session != null)
                {
                    session.WriteLine("yes");
                }
            }
            else
            {
                InTPos.Text = "No";
                session.WriteLine("no");
            }
        }