Ejemplo n.º 1
0
        void gestureController_SkeletonPreProcessed(object sender, SkeletonPreProcessedEventArgs e)
        {
            if (!_trackSkeleton)
            {
                return;
            }
            Skeleton skeleton = e.Skeleton;
            // Seralize
            List <JointType[]> jointChains = new List <JointType[]>();

            jointChains.Add(new JointType[] { JointType.ShoulderLeft, JointType.ElbowLeft, JointType.HandLeft });
            jointChains.Add(new JointType[] { JointType.ShoulderRight, JointType.ElbowRight, JointType.HandRight });
            jointChains.Add(new JointType[] { JointType.HipLeft, JointType.KneeLeft, JointType.FootLeft });
            jointChains.Add(new JointType[] { JointType.HipRight, JointType.KneeRight, JointType.FootRight });
            foreach (var jointChain in jointChains)
            {
                for (int i = 0; i < jointChain.Length - 1; i++)
                {
                    positionLimb(skeleton, jointChain[i], jointChain[i + 1]);
                }
            }
            // Position elements
            PositionBody(uxMainBody, skeleton);
            PositionElement(uxHeadPart, skeleton.Joints[JointType.Head], true);
            PositionElement(uxLeftHand, skeleton.Joints[JointType.HandLeft], true);
            PositionElement(uxRightHand, skeleton.Joints[JointType.HandRight], true);
        }
        void controller_SkeletonPreProcessed(object sender, SkeletonPreProcessedEventArgs e)
        {
            // Process core
            Skeleton           skel      = e.Skeleton;
            SkeletonPoint      leftFoot  = skel.Joints[JointType.FootLeft].Position;
            SkeletonPoint      rightFoot = skel.Joints[JointType.FootRight].Position;
            float              minFootY;
            JointTrackingState leftFootTracking  = skel.Joints[JointType.FootLeft].TrackingState;
            JointTrackingState rightFootTracking = skel.Joints[JointType.FootRight].TrackingState;
            bool footTracked = true;

            if (leftFootTracking == JointTrackingState.Tracked && rightFootTracking == JointTrackingState.Tracked)
            {
                minFootY = Math.Min(leftFoot.Y, rightFoot.Y);
            }
            else if (leftFootTracking == JointTrackingState.Tracked)
            {
                minFootY = leftFoot.Y;
            }
            else if (rightFootTracking == JointTrackingState.Tracked)
            {
                minFootY = rightFoot.Y;
            }
            else
            {
                footTracked = false;
                minFootY    = leftFoot.Y; // Not sure what's best in this case
            }

            if (skel.Joints[JointType.ShoulderCenter].TrackingState == JointTrackingState.Tracked && footTracked)
            {
                SkeletonPoint shoulderPos = skel.Joints[JointType.ShoulderCenter].Position;

                // ## Compute scale factor for larger/smaller people based off spine to foot height ##
                double shoulderHeight = shoulderPos.Y - minFootY;                        // Get the spinal height and use it a rough guide
                double fullHeight     = SHOULDER_TO_EXTENDED_ARM_RATIO * shoulderHeight; // Get the full height as a scale
                float  scale          = (float)(ActiveRectangle.Height / fullHeight);

                if (skel.TrackingId != curSkeletonId)
                {
                    scaleHistory.Clear();
                    curSkeletonId = skel.TrackingId;
                }
                if (scaleHistory.Count > 5)
                {
                    scaleHistory.RemoveAt(0);
                }
                scaleHistory.Add(scale);
                scaleFactor = scaleHistory.Average();
            }
            bottomCenterPoint   = skel.Joints[JointType.HipCenter].Position;
            bottomCenterPoint.Y = minFootY;
        }
        void controller_SkeletonPreProcessed(object sender, SkeletonPreProcessedEventArgs e)
        {
            // Process core
            Skeleton skel = e.Skeleton;
            SkeletonPoint leftFoot = skel.Joints[JointType.FootLeft].Position;
            SkeletonPoint rightFoot = skel.Joints[JointType.FootRight].Position;
            float minFootY;
            JointTrackingState leftFootTracking = skel.Joints[JointType.FootLeft].TrackingState;
            JointTrackingState rightFootTracking = skel.Joints[JointType.FootRight].TrackingState;
            bool footTracked = true;
            if (leftFootTracking == JointTrackingState.Tracked && rightFootTracking == JointTrackingState.Tracked)
                minFootY = Math.Min(leftFoot.Y, rightFoot.Y);
            else if (leftFootTracking == JointTrackingState.Tracked)
                minFootY = leftFoot.Y;
            else if (rightFootTracking == JointTrackingState.Tracked)
                minFootY = rightFoot.Y;
            else
            {
                footTracked = false;
                minFootY = leftFoot.Y; // Not sure what's best in this case
            }

            if (skel.Joints[JointType.ShoulderCenter].TrackingState == JointTrackingState.Tracked && footTracked)
            {
                SkeletonPoint shoulderPos = skel.Joints[JointType.ShoulderCenter].Position;

                // ## Compute scale factor for larger/smaller people based off spine to foot height ##
                double shoulderHeight = shoulderPos.Y - minFootY; // Get the spinal height and use it a rough guide
                double fullHeight = SHOULDER_TO_EXTENDED_ARM_RATIO * shoulderHeight; // Get the full height as a scale
                float scale = (float)(ActiveRectangle.Height / fullHeight);

                if (skel.TrackingId != curSkeletonId)
                {
                    scaleHistory.Clear();
                    curSkeletonId = skel.TrackingId;
                }
                if (scaleHistory.Count > 5) scaleHistory.RemoveAt(0);
                scaleHistory.Add(scale);
                scaleFactor = scaleHistory.Average();
            }
            bottomCenterPoint = skel.Joints[JointType.HipCenter].Position;
            bottomCenterPoint.Y = minFootY;
        }