public void GestureInProgress(ulong userId, int userIndex, KinectGestures.Gestures gesture, float progress, KinectCommon.NuiSkeletonPositionIndex joint, Vector3 screenPos) { //GestureInfo.guiText.text = string.Format("{0} Progress: {1:F1}%", gesture, (progress * 100)); if (gesture == KinectGestures.Gestures.Click && progress > 0.3f) { string sGestureText = string.Format("{0} {1:F1}% complete", gesture, progress * 100); if (GestureInfo != null) { GestureInfo.GetComponent <GUIText>().text = sGestureText; } progressDisplayed = true; } else if ((gesture == KinectGestures.Gestures.ZoomOut || gesture == KinectGestures.Gestures.ZoomIn) && progress > 0.5f) { string sGestureText = string.Format("{0} detected, zoom={1:F1}%", gesture, screenPos.z * 100); if (GestureInfo != null) { GestureInfo.GetComponent <GUIText>().text = sGestureText; } progressDisplayed = true; } else if (gesture == KinectGestures.Gestures.Wheel && progress > 0.5f) { string sGestureText = string.Format("{0} detected, angle={1:F1} deg", gesture, screenPos.z); if (GestureInfo != null) { GestureInfo.GetComponent <GUIText>().text = sGestureText; } progressDisplayed = true; } }
public bool GestureCancelled(ulong userId, int userIndex, KinectGestures.Gestures gesture, KinectCommon.NuiSkeletonPositionIndex joint) { if (progressDisplayed) { // clear the progress info if (GestureInfo != null) { GestureInfo.GetComponent <GUIText>().text = String.Empty; } progressDisplayed = false; } return(true); }
// Update the avatar each frame. public void UpdateAvatar(ulong UserID) { if (!transform.gameObject.activeInHierarchy) { return; } Debug.Log("UpdateAvatar on " + gameObject.name); // Get the KinectManager instance if (kinectManager == null) { kinectManager = KinectManager.Instance; } // move the avatar to its Kinect position //Debug.Log("Try moving on " + gameObject.name); MoveAvatar(UserID); //Debug.Log("Before Bone transform loop on " + gameObject.name + " expected length " + bones.Length); for (var boneIndex = 0; boneIndex < bones.Length; boneIndex++) { //Debug.Log(boneIndex + " mapping to joint " + bones[boneIndex] + " on " + gameObject.name, bones[boneIndex]); //Debug.Log("Try Bone transform loop on " + gameObject.name, bones[boneIndex]); if (bones[boneIndex] == null) { continue; } if (boneIndex2JointMap.ContainsKey(boneIndex)) { KinectCommon.NuiSkeletonPositionIndex joint = !mirroredMovement ? boneIndex2JointMap[boneIndex] : boneIndex2MirrorJointMap[boneIndex]; TransformBone(UserID, joint, boneIndex, !mirroredMovement); } else if (specIndex2JointMap.ContainsKey(boneIndex)) { // special bones (clavicles) List <KinectCommon.NuiSkeletonPositionIndex> alJoints = !mirroredMovement ? specIndex2JointMap[boneIndex] : specIndex2MirrorJointMap[boneIndex]; if (alJoints.Count >= 2) { //Vector3 baseDir = alJoints[0].ToString().EndsWith("Left") ? Vector3.left : Vector3.right; //TransformSpecialBone(UserID, alJoints[0], alJoints[1], boneIndex, baseDir, !mirroredMovement); } } } }
public bool GestureCompleted(ulong userId, int userIndex, KinectGestures.Gestures gesture, KinectCommon.NuiSkeletonPositionIndex joint, Vector3 screenPos) { string sGestureText = gesture + " detected"; if (gesture == KinectGestures.Gestures.Click) { sGestureText += string.Format(" at ({0:F1}, {1:F1})", screenPos.x, screenPos.y); } if (GestureInfo != null) { GestureInfo.GetComponent <GUIText>().text = sGestureText; } progressDisplayed = false; return(true); }
// Apply the rotations tracked by kinect to a special joint protected void TransformSpecialBone(ulong userId, KinectCommon.NuiSkeletonPositionIndex joint, KinectCommon.NuiSkeletonPositionIndex jointParent, int boneIndex, Vector3 baseDir, bool flip) { Transform boneTransform = bones[boneIndex]; if (boneTransform == null || kinectManager == null) { return; } if (!kinectManager.IsJointTracked(userId, (int)joint) || !kinectManager.IsJointTracked(userId, (int)jointParent)) { return; } Vector3 jointDir = kinectManager.GetDirectionBetweenJoints(userId, (int)jointParent, (int)joint, false, true); Quaternion jointRotation = jointDir != Vector3.zero ? Quaternion.FromToRotation(baseDir, jointDir) : Quaternion.identity; // if(!flip) // { // Vector3 mirroredAngles = jointRotation.eulerAngles; // mirroredAngles.y = -mirroredAngles.y; // mirroredAngles.z = -mirroredAngles.z; // // jointRotation = Quaternion.Euler(mirroredAngles); // } if (jointRotation != Quaternion.identity) { // Smoothly transition to the new rotation Quaternion newRotation = Kinect2AvatarRot(jointRotation, boneIndex); if (smoothFactor != 0f) { boneTransform.rotation = Quaternion.Slerp(boneTransform.rotation, newRotation, smoothFactor * Time.deltaTime); } else { boneTransform.rotation = newRotation; } } }
// Apply the rotations tracked by kinect to the joints. protected void TransformBone(ulong userId, KinectCommon.NuiSkeletonPositionIndex joint, int boneIndex, bool flip) { //Debug.Log("Before Transforming bone for " + gameObject.name); Transform boneTransform = bones[boneIndex]; if (boneTransform == null || kinectManager == null) { return; } //Debug.Log("Enter Transforming bone for " + gameObject.name); //Debug.Log("Transforming boneIndex " + boneIndex + " mapping to joint " + joint.ToString("g") + " transform ", boneTransform); int iJoint = (int)joint; if (iJoint < 0) { return; } // Get Kinect joint orientation Quaternion jointRotation = kinectManager.GetJointOrientation(userId, iJoint, flip); if (jointRotation == Quaternion.identity) { return; } // Smoothly transition to the new rotation Quaternion newRotation = Kinect2AvatarRot(jointRotation, boneIndex); if (smoothFactor != 0f) { boneTransform.rotation = Quaternion.Slerp(boneTransform.rotation, newRotation, smoothFactor * Time.deltaTime); } else { boneTransform.rotation = newRotation; } }