Example #1
0
        private void HandleHandPointerData(long timeStamp, UserInfo userInfo, int userIndex, InteractionHandPointer handPointer)
        {
            //var parameters = this.KinectSensor.CoordinateMapper.ColorToDepthRelationalParameters;
            //byte[] mapper = new byte[parameters.Count];
            //parameters.CopyTo(mapper, 0);
            var interactionData = new InteractionFrameData
            {
                TimeStampOfLastUpdate = timeStamp,
                TrackingId            = userInfo.SkeletonTrackingId,
                PlayerIndex           = userIndex,
                HandType      = EnumHelper.ConvertHandType(handPointer.HandType),
                IsTracked     = handPointer.IsTracked,
                IsActive      = handPointer.IsActive,
                IsInteractive = handPointer.IsInteractive,
                IsPressed     = handPointer.IsPressed,
                //IsPrimaryHandOfUser = handPointer.IsPrimaryForUser,
                IsPrimaryHandOfUser = false,
                IsPrimaryUser       = (userInfo.SkeletonTrackingId == this.PrimaryUserTrackingId) && (userInfo.SkeletonTrackingId != KinectPrimaryUserTracker.InvalidUserTrackingId),
                HandEventType       = EnumHelper.ConvertHandEventType(handPointer.HandEventType),
                X = handPointer.X,
                Y = handPointer.Y,
                Z = handPointer.PressExtent
            };

            this.kinectAdapter.HandleHandPointerData(interactionData);
        }
        private void HandleHandPointerData(long timeStamp, UserInfo userInfo, int userIndex, InteractionHandPointer handPointer)
        {
            var interactionData = new InteractionFrameData
            {
                TimeStampOfLastUpdate = timeStamp,
                TrackingId            = userInfo.SkeletonTrackingId,
                PlayerIndex           = userIndex,
                HandType            = EnumHelper.ConvertHandType(handPointer.HandType),
                IsTracked           = handPointer.IsTracked,
                IsActive            = handPointer.IsActive,
                IsInteractive       = handPointer.IsInteractive,
                IsPressed           = handPointer.IsPressed,
                IsPrimaryHandOfUser = handPointer.IsPrimaryForUser,
                IsPrimaryUser       = (userInfo.SkeletonTrackingId == this.PrimaryUserTrackingId) && (userInfo.SkeletonTrackingId != KinectPrimaryUserTracker.InvalidUserTrackingId),
                HandEventType       = EnumHelper.ConvertHandEventType(handPointer.HandEventType),
                X = handPointer.X,
                Y = handPointer.Y,
                Z = handPointer.PressExtent
            };

            this.kinectAdapter.HandleHandPointerData(interactionData);
        }
Example #3
0
        public InteractionInfo GetInteractionInfoAtLocation(int skeletonTrackingId, InteractionHandType handType, double x, double y)
        {
            var interactionInfo = new InteractionInfo
            {
                IsPressTarget = false,
                IsGripTarget  = false,
            };

            var hitTestPosition = InteractionZoneDefinition.InteractionZoneToElement(x, y, this.InteractionRootElement);

            Func <HandPointer, bool> isTargetCapturedElement =
                handPointer =>
                (handPointer.TrackingId == skeletonTrackingId) &&
                (handPointer.HandType == EnumHelper.ConvertHandType(handType)) &&
                (handPointer.Captured != null);
            var targetHandPointer = this.publicHandPointers.FirstOrDefault(isTargetCapturedElement);
            var targetElement     = targetHandPointer != null ? targetHandPointer.Captured : this.HitTest(hitTestPosition);

            if (targetElement != null)
            {
                // Walk up the tree and try to find a grip target and/or a press target
                for (DependencyObject search = targetElement;
                     search != null && search != this.InteractionRootElement &&
                     (!interactionInfo.IsGripTarget || !interactionInfo.IsPressTarget);
                     search = VisualTreeHelper.GetParent(search))
                {
                    var searchElement = search as FrameworkElement;
                    if (searchElement == null)
                    {
                        // We need ActualWidth and Height which comes
                        // with FrameworkElement
                        continue;
                    }

                    if (!interactionInfo.IsPressTarget)
                    {
                        bool isPressTarget = KinectRegion.GetIsPressTarget(searchElement);
                        if (isPressTarget)
                        {
                            // We found a press target.
                            if (interactionInfo.PressTargetControlId == 0)
                            {
                                interactionInfo.PressTargetControlId = searchElement.GetHashCode();
                            }

                            interactionInfo.IsPressTarget = true;

                            // Apply the margin to the press target point
                            Point pressTargetPoint = ApplyControlPressPointMargin(KinectRegion.GetPressTargetPoint(searchElement));

                            // Convert from interaction zone space into actual control coordinates
                            var elementPressTargetPoint = InteractionZoneDefinition.InteractionZoneToElement(
                                pressTargetPoint.X, pressTargetPoint.Y, searchElement);

                            // Get it into the space of the KinectRegion
                            var regionPressTargetPoint = searchElement.TranslatePoint(elementPressTargetPoint, this.InteractionRootElement);

                            // Now put it into the interaction zone space but now relative to the KinectRegion
                            var interactionPressTargetPoint = InteractionZoneDefinition.ElementToInteractionZone(
                                regionPressTargetPoint.X, regionPressTargetPoint.Y, this.InteractionRootElement);

                            interactionInfo.PressAttractionPointX = interactionPressTargetPoint.X;
                            interactionInfo.PressAttractionPointY = interactionPressTargetPoint.Y;
                        }
                    }

                    if (!interactionInfo.IsGripTarget)
                    {
                        bool isGripTarget = KinectRegion.GetIsGripTarget(searchElement);

                        if (isGripTarget)
                        {
                            // We found a grip target.
                            interactionInfo.IsGripTarget = true;
                        }
                    }
                }
            }

            return(interactionInfo);
        }