Esempio n. 1
0
 private SkeletonStatus GetSkeletonStatus(int trackingId)
 {
     if (skeletonStatusDictionary.ContainsKey(trackingId))
     {
         return(skeletonStatusDictionary[trackingId]);
     }
     else
     {
         var skeletonStatus = new SkeletonStatus()
         {
             TrackingId = trackingId,
         };
         skeletonStatusDictionary[trackingId] = skeletonStatus;
         return(skeletonStatus);
     }
 }
Esempio n. 2
0
        private void kinectSensor_SkeletonFrameReady(object sender, SkeletonFrameReadyEventArgs e)
        {
            using (var skeletonFrame = e.OpenSkeletonFrame())
            {
                if (skeletonFrame == null)
                {
                    return;
                }
                var skeletonInfoArray = new Skeleton[skeletonFrame.SkeletonArrayLength];
                skeletonFrame.CopySkeletonDataTo(skeletonInfoArray);
                foreach (var skeletonInfo in skeletonInfoArray)
                {
                    SkeletonStatus skeletonStatus = GetSkeletonStatus(skeletonInfo.TrackingId);

                    switch (skeletonInfo.TrackingState)
                    {
                    case SkeletonTrackingState.NotTracked:
                        break;

                    case SkeletonTrackingState.PositionOnly:
                        break;

                    case SkeletonTrackingState.Tracked:
                        var previousCursorX = skeletonStatus.NormalizedCursorX;
                        var previousCursorY = skeletonStatus.NormalizedCursorY;
                        skeletonStatus.UpdateMaxHandDeltaX(skeletonInfo);
                        if (skeletonStatus.IsActiveAreaReady)
                        {
                            var normalizedX = skeletonStatus.NormalizedCursorX.Value;
                            var normalizedY = skeletonStatus.NormalizedCursorY.Value;

                            var hasCursorPositionChanged = !previousCursorX.HasValue ||
                                                           previousCursorX.Value != normalizedX ||
                                                           !previousCursorY.HasValue ||
                                                           previousCursorY != normalizedY;
                            UpdateCursors(normalizedX, normalizedY, hasCursorPositionChanged);
                            UpdateControls(normalizedX, normalizedY, hasCursorPositionChanged);
                            NotifyMovementListeners(normalizedX, normalizedY);
                        }
                        break;

                    default:
                        break;
                    }
                }
            }
        }