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); }
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; } } }