private void EngagementSettings_Unloaded(object sender, RoutedEventArgs e) { int people = onePerson.IsChecked.HasValue && onePerson.IsChecked.Value ? 1 : 2; App app = ((App)App.Current); if (system.IsChecked.HasValue && system.IsChecked.Value) { switch (people) { case 1: app.KinectRegion.SetKinectOnePersonSystemEngagement(); break; case 2: app.KinectRegion.SetKinectTwoPersonSystemEngagement(); break; } } else if (manualOverHead.IsChecked.HasValue && manualOverHead.IsChecked.Value) { var engagementModel = new HandOverheadEngagementModel(people); switch (people) { case 1: app.KinectRegion.SetKinectOnePersonManualEngagement(engagementModel); break; case 2: app.KinectRegion.SetKinectTwoPersonManualEngagement(engagementModel); break; } } else if (manualOnScreen.IsChecked.HasValue && manualOnScreen.IsChecked.Value) { var engagementModel = new HandInScreenEngagementModel(people, app.KinectRegion.InputPointerManager); switch (people) { case 1: app.KinectRegion.SetKinectOnePersonManualEngagement(engagementModel); break; case 2: app.KinectRegion.SetKinectTwoPersonManualEngagement(engagementModel); break; } } // Manage cursor sprite sheets if (cursorSpriteSheetDefault.IsChecked.HasValue && cursorSpriteSheetDefault.IsChecked.Value) { app.KinectRegion.CursorSpriteSheetDefinition = KinectRegion.DefaultSpriteSheet; } else if (cursorSpriteSheetColor.IsChecked.HasValue && cursorSpriteSheetColor.IsChecked.Value) { app.KinectRegion.CursorSpriteSheetDefinition = new CursorSpriteSheetDefinition(new System.Uri("pack://application:,,,/Assets/CursorSpriteSheetPurple.png"), 4, 20, 137, 137); } }
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; } } }