Пример #1
0
        void kinectRegion_Loaded(object sender, RoutedEventArgs e)
        {
            App app = ((App)App.Current);

            IKinectEngagementManager kinectEngagementManager = app.KinectRegion.KinectEngagementManager;

            var handInScreenEngagementModel = kinectEngagementManager as HandInScreenEngagementModel;
            var handOverHeadEngagementModel = kinectEngagementManager as HandOverheadEngagementModel;

            var engagementModel1 = new HandOverheadEngagementModel(1);

            var engagementModel2 = new HandInScreenEngagementModel(1, app.KinectRegion.InputPointerManager);
//app.KinectRegion.SetKinectOnePersonManualEngagement(engagementModel2);
        }
Пример #2
0
        private void TrackEngagedPlayersViaHandInScreen()
        {
            if (this.stopped)
            {
                return;
            }

            this.engagementPeopleHaveChanged = false;
            var currentlyEngagedHands = KinectCoreWindow.KinectManualEngagedHands;

            this.handsToEngage.Clear();

            // check to see if anybody who is currently engaged should be disengaged
            foreach (var bodyHandPair in currentlyEngagedHands)
            {
                foreach (var kinectPointerPoint in this.pointerPoints)
                {
                    if (kinectPointerPoint.Properties.BodyTrackingId == bodyHandPair.BodyTrackingId &&
                        kinectPointerPoint.Properties.HandType == bodyHandPair.HandType)
                    {
                        // check for disengagement
                        bool toBeDisengaged = this.IsHandBelowScreen(kinectPointerPoint.Properties.UnclampedPosition, kinectPointerPoint.PointerId);

                        if (toBeDisengaged)
                        {
                            this.engagementPeopleHaveChanged = true;
                        }
                        else
                        {
                            this.handsToEngage.Add(bodyHandPair);
                        }
                    }
                }
            }

            // check to see if anybody should be engaged, if not already engaged
            foreach (var kinectPointerPoint in this.pointerPoints)
            {
                if (this.handsToEngage.Count < this.engagedPeopleAllowed)
                {
                    bool alreadyEngaged = false;
                    foreach (var bodyHandPair in this.handsToEngage)
                    {
                        alreadyEngaged = (kinectPointerPoint.Properties.BodyTrackingId == bodyHandPair.BodyTrackingId);
                    }

                    if (!alreadyEngaged)
                    {
                        // check for engagement
                        if (HandInScreenEngagementModel.IsHandInScreen(kinectPointerPoint.Properties.UnclampedPosition))
                        {
                            // engage the left hand
                            this.handsToEngage.Add(
                                new BodyHandPair(kinectPointerPoint.Properties.BodyTrackingId, kinectPointerPoint.Properties.HandType));
                            this.engagementPeopleHaveChanged = true;
                        }
                    }
                }
            }

            if (this.engagementPeopleHaveChanged)
            {
                BodyHandPair firstPersonToEngage  = null;
                BodyHandPair secondPersonToEngage = null;

                Debug.Assert(this.handsToEngage.Count <= 2, "handsToEngage should be <= 2");

                switch (this.handsToEngage.Count)
                {
                case 0:
                    break;

                case 1:
                    firstPersonToEngage = this.handsToEngage[0];
                    break;

                case 2:
                    firstPersonToEngage  = this.handsToEngage[0];
                    secondPersonToEngage = this.handsToEngage[1];
                    break;
                }

                switch (this.EngagedPeopleAllowed)
                {
                case 0:
                case 1:
                    KinectCoreWindow.SetKinectOnePersonManualEngagement(firstPersonToEngage);
                    break;

                case 2:
                    KinectCoreWindow.SetKinectTwoPersonManualEngagement(firstPersonToEngage, secondPersonToEngage);
                    break;
                }
            }
        }