Exemplo n.º 1
0
        private void TrackEngagedPlayersViaHandOverHead()
        {
            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)
            {
                var bodyTrackingId = bodyHandPair.BodyTrackingId;
                foreach (var body in this.bodies)
                {
                    if (body.TrackingId == bodyTrackingId)
                    {
                        // check for disengagement
                        JointType engagedHandJoint =
                            (bodyHandPair.HandType == HandType.LEFT) ? JointType.HandLeft : JointType.HandRight;
                        bool toBeDisengaged = HandOverheadEngagementModel.IsHandBelowHip(engagedHandJoint, body);

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

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

                    if (!alreadyEngaged)
                    {
                        // check for engagement
                        if (HandOverheadEngagementModel.IsHandOverhead(JointType.HandLeft, body))
                        {
                            // engage the left hand
                            this.handsToEngage.Add(
                                new BodyHandPair(body.TrackingId, HandType.LEFT));
                            this.engagementPeopleHaveChanged = true;
                        }
                        else if (HandOverheadEngagementModel.IsHandOverhead(JointType.HandRight, body))
                        {
                            // engage the right hand
                            this.handsToEngage.Add(
                                new BodyHandPair(body.TrackingId, HandType.RIGHT));
                            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 1:
                    KinectCoreWindow.SetKinectOnePersonManualEngagement(firstPersonToEngage);
                    break;

                case 2:
                    KinectCoreWindow.SetKinectTwoPersonManualEngagement(firstPersonToEngage, secondPersonToEngage);
                    break;
                }
            }
        }
Exemplo n.º 2
0
        private void TrackEngagedPlayersViaHandInScreen()
        {
            if (this.stopped)
            {
                return;
            }

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

            this.handsToEngage.Clear();

            foreach (var bodyHandPair in currentlyEngagedHands)
            {
                foreach (var kinectPointerPoint in this.pointerPoints)
                {
                    if (kinectPointerPoint.Properties.BodyTrackingId == bodyHandPair.BodyTrackingId &&
                        kinectPointerPoint.Properties.HandType == bodyHandPair.HandType)
                    {
                        bool toBeDisengaged = this.IsHandBelowScreen(kinectPointerPoint.Properties.UnclampedPosition, kinectPointerPoint.PointerId);

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


            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)
                    {
                        if (HandInScreenEngagementModel.IsHandInScreen(kinectPointerPoint.Properties.UnclampedPosition))
                        {
                            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;
                }
            }
        }