public void UserDetected(ulong userId, int userIndex) { // the gestures are allowed for the selected user only KinectGestureManager gestureManager = KinectManager.Instance.gestureManager; if (!gestureManager || (userIndex != playerIndex)) { return; } // set the gestures to detect gestureManager.DetectGesture(userId, GestureType.SwipeLeft); gestureManager.DetectGesture(userId, GestureType.SwipeRight); gestureManager.DetectGesture(userId, GestureType.SwipeUp); gestureManager.DetectGesture(userId, GestureType.Psi); gestureManager.DetectGesture(userId, GestureType.ZoomIn); gestureManager.DetectGesture(userId, GestureType.ZoomOut); gestureManager.DetectGesture(userId, GestureType.Wheel); gestureManager.DetectGesture(userId, GestureType.Jump); if (gestureInfo != null) { // gestureInfo.text = "Swipe left, right or up to change the slides."; } }
public void UserDetected(ulong userId, int userIndex) { KinectGestureManager gestureManager = KinectManager.Instance.gestureManager; if (!gestureManager || (userIndex != playerIndex)) { return; } gestureManager.DetectGesture(userId, stageOriginCalibratePose); }
void Start() { KinectManager kinectManager = KinectManager.Instance; if (kinectManager) { // remove all users & filters kinectManager.ClearKinectUsers(); // refresh gesture listeners KinectGestureManager gestureManager = kinectManager.gestureManager; if (gestureManager) { gestureManager.RefreshGestureListeners(); } } }
// invoked when a new user is detected public void UserDetected(ulong userId, int userIndex) { if (userIndex == playerIndex) { // as an example - detect these user specific gestures KinectGestureManager gestureManager = KinectManager.Instance.gestureManager; foreach (GestureType gesture in detectGestures) { gestureManager.DetectGesture(userId, gesture); } } if (gestureInfo != null) { //gestureInfo.text = "Please do the gestures and look for the gesture detection state."; } }
public void UserDetected(ulong userId, int userIndex) { KinectManager kinectManager = KinectManager.Instance; KinectGestureManager gestureManager = kinectManager ? kinectManager.gestureManager : null; if (!gestureManager || (userIndex != playerIndex)) { return; } if (raiseHandToChangeCategory) { gestureManager.DetectGesture(userId, GestureType.RaiseRightHand); gestureManager.DetectGesture(userId, GestureType.RaiseLeftHand); } if (swipeToChangeModel) { gestureManager.DetectGesture(userId, GestureType.SwipeLeft); gestureManager.DetectGesture(userId, GestureType.SwipeRight); } }
/// <summary> /// Invoked when a new user is detected. Here you can start gesture tracking by invoking KinectManager.DetectGesture()-function. /// </summary> /// <param name="userId">User ID</param> /// <param name="userIndex">User index</param> public void UserDetected(ulong userId, int userIndex) { // the gestures are allowed for the selected user only KinectGestureManager gestureManager = KinectManager.Instance.gestureManager; if (!gestureManager || (userIndex != playerIndex)) { return; } // set the gestures to detect gestureManager.DetectGesture(userId, GestureType.ZoomOut); gestureManager.DetectGesture(userId, GestureType.ZoomIn); gestureManager.DetectGesture(userId, GestureType.Wheel); gestureManager.DetectGesture(userId, GestureType.RaiseLeftHand); gestureManager.DetectGesture(userId, GestureType.RaiseRightHand); if (gestureInfo != null) { gestureInfo.text = "Zoom-in or wheel to rotate the model.\nRaise hand to reset it."; } }
// check if the calibration pose is complete for given user protected virtual bool CheckForCalibrationPose(ulong UserId, int bodyIndex, GestureType calibrationGesture, KinectGestureManager gestureManager, ref KinectInterop.BodyData[] alTrackedBodies) { if (calibrationGesture == GestureType.None) { return(true); } if (!gestureManager) { return(false); } KinectGestureManager.GestureData gestureData = playerCalibrationData.ContainsKey(UserId) ? playerCalibrationData[UserId] : new KinectGestureManager.GestureData(); // init gesture data if needed if (gestureData.userId != UserId) { gestureData.userId = UserId; gestureData.gesture = calibrationGesture; gestureData.state = 0; gestureData.timestamp = Time.realtimeSinceStartup; gestureData.joint = 0; gestureData.progress = 0f; gestureData.complete = false; gestureData.cancelled = false; } // get joint positions and tracking int iAllJointsCount = (int)KinectInterop.JointType.Count; bool[] playerJointsTracked = new bool[iAllJointsCount]; Vector3[] playerJointsPos = new Vector3[iAllJointsCount]; int[] aiNeededJointIndexes = gestureManager.GetNeededJointIndexes(); int iNeededJointsCount = aiNeededJointIndexes.Length; for (int i = 0; i < iNeededJointsCount; i++) { int joint = aiNeededJointIndexes[i]; if (joint >= 0) { KinectInterop.JointData jointData = alTrackedBodies[bodyIndex].joint[joint]; playerJointsTracked[joint] = jointData.trackingState != KinectInterop.TrackingState.NotTracked; playerJointsPos[joint] = jointData.kinectPos; if (!playerJointsTracked[joint] && (joint == (int)KinectInterop.JointType.Neck)) { KinectInterop.JointData lShoulderData = alTrackedBodies[bodyIndex].joint[(int)KinectInterop.JointType.ShoulderLeft]; KinectInterop.JointData rShoulderData = alTrackedBodies[bodyIndex].joint[(int)KinectInterop.JointType.ShoulderRight]; if (lShoulderData.trackingState != KinectInterop.TrackingState.NotTracked && rShoulderData.trackingState != KinectInterop.TrackingState.NotTracked) { playerJointsTracked[joint] = true; playerJointsPos[joint] = (lShoulderData.kinectPos + rShoulderData.kinectPos) / 2f; } } } } // estimate the gesture progess gestureManager.CheckForGesture(UserId, ref gestureData, Time.realtimeSinceStartup, ref playerJointsPos, ref playerJointsTracked); playerCalibrationData[UserId] = gestureData; // check if gesture is complete if (gestureData.complete) { gestureData.userId = 0; playerCalibrationData[UserId] = gestureData; return(true); } return(false); }
// Adds UserId to the list of users public virtual int CalibrateUser(ulong userId, int bodyIndex, ref KinectInterop.BodyData[] alTrackedBodies, KinectManager.UserDetectionOrder userDetectionOrder, GestureType playerCalibrationPose, KinectGestureManager gestureManager) { if (!alUserIds.Contains(userId)) { if (CheckForCalibrationPose(userId, bodyIndex, playerCalibrationPose, gestureManager, ref alTrackedBodies)) { //int uidIndex = alUserIds.Count; int uidIndex = GetEmptyUserSlot(userId, bodyIndex, ref alTrackedBodies, userDetectionOrder); if (uidIndex >= 0) { aUserIndexIds[uidIndex] = userId; } else { // no empty user-index slot return(-1); } dictUserIdToIndex[userId] = bodyIndex; dictUserIdToTime[userId] = Time.time; alUserIds.Add(userId); // set primary user-id, if there is none if (liPrimaryUserId == 0 && aUserIndexIds.Length > 0) { liPrimaryUserId = aUserIndexIds[0]; // userId } return(uidIndex); } } return(-1); }