/// <summary> /// Funkcja ta przestawia punkt zero z miednicy na poziom glowy /// </summary> /// <param name="rightHanded"></param> /// <param name="skeleton"></param> /// <returns></returns> private Joint normalizeJoint(bool rightHanded, TrackedSkeleton skeleton) { Joint head = skeleton.getJoint(JointType.ShoulderCenter); Joint wrist = skeleton.getJoint(JointType.WristRight); Joint newJoint = new Joint(); SkeletonPoint newPoint = new SkeletonPoint() { X = wrist.Position.X, Y = wrist.Position.Y - head.Position.Y }; newJoint.Position = newPoint; return(newJoint); }
public void updateByKinect(TrackedSkeleton skeleton) { if (!isEnabled) { return; } if (skeleton.getJoint(JointType.WristRight).Position.X == 0 && skeleton.getJoint(JointType.WristRight).Position.Y == 0) { return; } //Bazujac na pozycji prawej reki, dopasowuje wspolrzedne Microsoft.Kinect.Vector4 newPos = PointerAdjustment.AdjustToScreen(normalizeJoint(true, skeleton)); posPointer = new Vector2(newPos.X, newPos.Y); rectanglePointer = new Rectangle((int)posPointer.X, (int)posPointer.Y, txPointer.Width, txPointer.Height); }
protected override void Update(GameTime gameTime) { KeyboardState newState = Keyboard.GetState(); // Wyjscie z gry if (newState.IsKeyDown(Keys.Escape)) { this.Exit(); } // Podanie komendy play if (newState.IsKeyDown(Keys.P)) { speech.setLastCommand(WordCommands.START); } if (newState.IsKeyDown(Keys.A)) { if (speech.getConfidenceThreshold() + 0.01f < 1) { speech.setConfidenceThreshold(Math.Round(speech.getConfidenceThreshold() + 0.01f, 2)); } else { speech.setConfidenceThreshold(1.0f); } } if (newState.IsKeyDown(Keys.Z)) { if (speech.getConfidenceThreshold() - 0.01f > 0) { speech.setConfidenceThreshold(Math.Round(speech.getConfidenceThreshold() - 0.01f, 2)); } else { speech.setConfidenceThreshold(0.0f); } } //Infobox jest update'owany niezaleznie od ekranu trackedSkeleton.updateSkeleton(depthStream.skeletonStream.getLastSkeleton()); activeScreen = infoBox.update(trackedSkeleton.getJoint(JointType.WristRight), pointer.rectanglePointer, activeScreen, speech.getConfidenceThreshold()); //Stan myszy MouseState mouse = Mouse.GetState(); pointer.update(mouse.X, mouse.Y); //Ruch reka pointer.updateByKinect(trackedSkeleton); depthStream.Visible = false; depthStream.Enabled = true; colorStream.Visible = true; colorStream.Enabled = true; //Update screenu ze wzgledu na aktywny ekran switch (activeScreen) { case GameType.LoadingScreen: { infoBox.Invisible(); colorStream.Visible = false; colorStream.Enabled = false; depthStream.Visible = false; depthStream.Enabled = false; activeScreen = loadingScreen.update(); pointer.Disable(); LoadContentInTime(loadingScreen.getTime()); break; } case GameType.Intro: { infoBox.Invisible(); colorStream.Visible = false; colorStream.Enabled = false; depthStream.Visible = false; depthStream.Enabled = false; activeScreen = introScreen.update(); pointer.Disable(); break; } case GameType.MainMenu: { infoBox.Visible(); activeScreen = mainMenuScreen.update(pointer.rectanglePointer); pointer.Enable(); break; } case GameType.Kindergarten: { infoBox.Visible(); activeScreen = kindergartenScreen.update(pointer.rectanglePointer); pointer.Enable(); break; } case GameType.School: { infoBox.Visible(); activeScreen = schoolScreen.update(pointer.rectanglePointer); pointer.Enable(); break; } case GameType.Memory: { infoBox.Visible(); activeScreen = memoryScreen.update(pointer.rectanglePointer); pointer.Enable(); break; } case GameType.ToyStore: { infoBox.Visible(); activeScreen = toystoreScreen.update(pointer.rectanglePointer); pointer.Enable(); break; } case GameType.EngColors: { infoBox.Visible(); activeScreen = engColorsScreen.update(pointer.rectanglePointer); pointer.Enable(); break; } case GameType.Gymnastics: { infoBox.Invisible(); speech.EnableSpeechRecognition(); GameType newMode = gymnasticsScreen.update(pointer.rectanglePointer, trackedSkeleton.getSkeleton(), speech.getLastCommand()); if (newMode != activeScreen) { speech.DisableSpeechRecognition(); } speech.cleanLastCommand(); pointer.Disable(); activeScreen = newMode; break; } case GameType.PickingApples: { infoBox.Invisible(); colorStream.Visible = false; GameType newMode = pickingApplesScreen.update(trackedSkeleton.getJoint(JointType.HandLeft), trackedSkeleton.getJoint(JointType.HandRight), speech.getLastCommand()); if (newMode == activeScreen) { if (pickingApplesScreen.firstEntrance) { //Tryb uruchomiony pierwszy raz, trzeba zmienic viewport pickingApplesScreen.firstEntrance = false; speech.EnableSpeechRecognition(); this.setKinectViewport(KinectViewportModes.PICKING_APPLES); } } else { //Zmiana trybu pickingApplesScreen.firstEntrance = true; this.setKinectViewport(KinectViewportModes.NORMAL); speech.DisableSpeechRecognition(); } speech.cleanLastCommand(); pointer.Disable(); activeScreen = newMode; break; } } base.Update(gameTime); }