private void RecognizeMotion(Skeleton[] skeletons) { Point pt = new Point(0, 0); foreach (Skeleton skeleton in skeletons) { // 动作进行识别 _featureData.SetRelativeJoints(skeleton); int rec = _motion.HandleDataEx(_featureData); switch (rec) { case -1: break; //未识别直接返回 case 34: // 左手向上 pt.X = SystemParameters.PrimaryScreenWidth / 2; pt.Y = SystemParameters.PrimaryScreenHeight / 2; Mouse.MoveTo(pt); Mouse.Click(MouseButton.Left); break; //case 35: // 右手向上 // break; case 36: // 左手向下 break; case 37: // 右手向下 isHandDown = true; Keyboard.Press(Key.Tab); Keyboard.Release(Key.Tab); HighlightSkeleton(skeleton); break; case 21: // 水平展开 if (isHandDown == false) { break; } isHandMiddle = true; Keyboard.Press(Key.Enter); Keyboard.Release(Key.Enter); Keyboard.Press(Key.Left); Keyboard.Release(Key.Left); Keyboard.Press(Key.Enter); Keyboard.Release(Key.Enter); HighlightSkeleton(skeleton); Thread.Sleep(1000); pt.X = SystemParameters.PrimaryScreenWidth / 2; pt.Y = SystemParameters.PrimaryScreenHeight / 2; Mouse.MoveTo(pt); Mouse.DoubleClick(MouseButton.Left); break; case 35: // 水平收缩 if (isHandMiddle == false) { break; } Keyboard.Press(Key.Escape); Keyboard.Release(Key.Escape); Thread.Sleep(500); Keyboard.Press(Key.LeftAlt); Keyboard.Press(Key.F4); Keyboard.Release(Key.LeftAlt); Keyboard.Release(Key.F4); HighlightSkeleton(skeleton); isHandDown = false; isHandMiddle = false; break; default: break; } } }
// Process the skeleton data void ProcessSkeleton() { List <uint> lostUsers = new List <uint>(); lostUsers.AddRange(allUsers); for (int i = 0; i < KinectWrapper.Constants.NuiSkeletonCount; i++) { KinectWrapper.NuiSkeletonData skeletonData = skeletonFrame.SkeletonData[i]; uint userId = skeletonData.dwTrackingID; if (skeletonData.eTrackingState == KinectWrapper.NuiSkeletonTrackingState.SkeletonTracked) { if (!AllPlayersCalibrated) { CalibrateUser(userId); } int stateNotTracked = (int)KinectWrapper.NuiSkeletonPositionTrackingState.NotTracked; if (userId == Player1ID) { //Debug.Log("user yes:" + userId.ToString()); //Waterstrong // get player position player1Pos = kinectToWorld.MultiplyPoint3x4(skeletonData.Position); player1Pos.z = -player1Pos.z; //Debug.Log(String.Format("({0}, {1}, {2})", player1Pos.x, player1Pos.y, player1Pos.z)); //CalibrationText.guiText.text = String.Format("({0:F1}, {1:F1}, {2:F1})", player1Pos.x, player1Pos.y, player1Pos.z); // get joints rotation for (int j = 0; j < (int)KinectWrapper.NuiSkeletonPositionIndex.Count; j++) { player1JointsTracked[j] = (int)skeletonData.eSkeletonPositionTrackingState[j] != stateNotTracked; if (player1JointsTracked[j]) { player1JointsPos[j] = kinectToWorld.MultiplyPoint3x4(skeletonData.SkeletonPositions[j]); player1JointsPos[j].z = -player1JointsPos[j].z; } } // get joint orientations KinectWrapper.GetSkeletonJointOrientation(ref player1JointsPos, ref player1JointsTracked, ref player1JointsOri); // get player rotation player1Ori = player1JointsOri[(int)KinectWrapper.NuiSkeletonPositionIndex.HipCenter]; // Waterstrong Add UI //_adaptiveUi.SetUiCenter(player1JointsPos[(int)KinectWrapper.NuiSkeletonPositionIndex.Head], player1JointsPos[(int)KinectWrapper.NuiSkeletonPositionIndex.HandLeft], player1JointsPos[(int)KinectWrapper.NuiSkeletonPositionIndex.HandRight]); // Waterstrong Add FeatureData featureData = new FeatureData(); featureData.SetRelativeJoints(player1JointsPos); MotionType mt = _motion.HandleDataEx(featureData); switch (mt) { case MotionType.Jump: Debug.Log("jump"); //SendMessage("DidJumpReachApex", SendMessageOptions.DontRequireReceiver); break; //case MotionType.Left: // Debug.Log("left"); // break; //case MotionType.Right: // Debug.Log("right"); // break; default: break; } } else if (userId == Player2ID) { // get player position player2Pos = kinectToWorld.MultiplyPoint3x4(skeletonData.Position); player2Pos.z = -player2Pos.z; // get joints rotation for (int j = 0; j < (int)KinectWrapper.NuiSkeletonPositionIndex.Count; j++) { player2JointsTracked[j] = (int)skeletonData.eSkeletonPositionTrackingState[j] != stateNotTracked; if (player2JointsTracked[j]) { player2JointsPos[j] = kinectToWorld.MultiplyPoint3x4(skeletonData.SkeletonPositions[j]); player2JointsPos[j].z = -player2JointsPos[j].z; } } // get joint orientations KinectWrapper.GetSkeletonJointOrientation(ref player2JointsPos, ref player2JointsTracked, ref player2JointsOri); // get player rotation player2Ori = player2JointsOri[(int)KinectWrapper.NuiSkeletonPositionIndex.HipCenter]; } lostUsers.Remove(userId); } } // remove the lost users if any if (lostUsers.Count > 0) { foreach (uint userId in lostUsers) { RemoveUser(userId); } lostUsers.Clear(); } }
private void MotionRecognition() { if (nuiElementPress.IsGestureCtrolling) { return; } if (handWave.Recognise(sw, player)) { nuiElementPress.OnSwitchInteractionPress(); } FeatureData feature = new FeatureData(); feature.SetRelativeJoints(sw.rawBonePos, player); MotionType mt = motion.HandleDataEx(feature); switch (mt) { case MotionType.None: break; case MotionType.Jump: // 起跳 nuiElementPress.TurnOver(1); Debug.Log("Jump"); break; case MotionType.HandLeftSlide: // 左滑动 Debug.Log("LeftSlide"); nuiElementPress.Rotate(1); break; case MotionType.HandRightSlide: // 右滑动 Debug.Log("RightSlide"); nuiElementPress.Rotate(-1); break; case MotionType.HandsUp: // 举手 Debug.Log("HandsUp"); break; case MotionType.HandsMiddle: // 双手水平展开 //promptUiCtrl.Show("双手水平展开"); nuiElementPress.Zoom(1); Debug.Log("HandsMiddle"); break; case MotionType.HandsFold: // 双手水平收缩 //promptUiCtrl.Show("双手水平收缩"); nuiElementPress.Zoom(-1); Debug.Log("HandsFold"); break; case MotionType.HandLeftUp: // 左手向上 nuiElementPress.TurnOver(-1); break; case MotionType.HandRightUp: // 右手向上 Debug.Log("Hand L&R Up"); nuiElementPress.StopRotate(); break; case MotionType.HandLeftCircle: // 左手划圆 case MotionType.HandRightCircle: // 右手划圆 nuiElementPress.OnSwitchInteractionPress(); Debug.Log("HandRightCircle"); break; case MotionType.HandLeftDown: Debug.Log("HandLeftDown"); break; case MotionType.HandRightDown: Debug.Log("HandRightDown"); break; default: break; } }