/// <summary> /// Make the model smoothly animate to the supplied pose. Animation is a Slerp /// /// This is a Slerp animation, so it should be called repeatedly through a tickEvent. /// </summary> /// <param name="frameIn">Frame to animate to</param> public void AnimateToFrame(SerializeScript.SnapshotClass frameIn) { //store init rotation of avatar Quaternion initRotation = gameObject.GetComponent<Transform>().rotation; //play frame foreach (ZigJointId j in Enum.GetValues(typeof(ZigJointId))) { if (transforms.Length > (int)j) //check for out of bounds { if (null != transforms[(int)j]) { //transforms[(int)j].rotation = transform.rotation * frameIn.jointRotations[(int)j]; transforms[(int)j].rotation = Quaternion.Slerp(transforms[(int)j].rotation, transform.rotation * frameIn.jointRotations[(int)j], Time.deltaTime * animateSpeed); } } } //TESTING CODE //make character not rotate Transform temp = gameObject.GetComponent<Transform>(); temp.rotation = initRotation; }
/// <summary> /// Loads the indicated recording from disk /// Recordings are stored as XML files /// </summary> /// <param name="fileNameIn">The name of the XML file to be loaded</param> public void LoadList(string fileNameIn) { //stop checking if checking if (listeningForWholeBodyGesture || isPlaying || isAnimatingIndicatorModel || listeningForGesture) { listeningForWholeBodyGesture = false; indicatorModelKeyPoint = 0; currentKeyPoint = 0; listeningForGesture = false; isAnimatingIndicatorModel = false; isPlaying = false; //reset the gestures of the 2 models GameObject.Find(indicatorGameObjectName).GetComponent <ZigSkeleton> ().RotateToCalibrationPose(); GameObject.Find(avatarGameObjectName).GetComponent <ZigSkeleton> ().RotateToCalibrationPose(); //feedback feedbackText1.text = "File loaded succesfully!"; feedbackText2.text = "Press play game to start!"; } playbackList = SerializeScript.deserializeFromDisk(fileNameIn); Debug.Log("List " + fileNameIn + " succesfully loaded"); SyncLists(); //refresh keypointslist }
/// <summary> /// Loads the indicated recording from disk /// Recordings are stored as XML files /// </summary> /// <param name="fileNameIn">The name of the XML file to be loaded</param> public void LoadList(string fileNameIn) { playbackList = SerializeScript.deserializeFromDisk(fileNameIn); Debug.Log("List " + fileNameIn + " succesfully loaded"); StopPlaying(); //reset playback SyncLists(); //refresh keypointslist UpdateGUIKPList(); }
/// <summary> /// Makes the avatar assume the pose recorded in the frame passed in /// </summary> /// <param name="frameIn">The frame to be played</param> public void PlayFrame(SerializeScript.SnapshotClass frameIn) { //play frame foreach (ZigJointId j in Enum.GetValues(typeof(ZigJointId))) { if (null != transforms[(int)j]) { transforms[(int)j].rotation = transform.rotation * frameIn.jointRotations[(int)j]; } } }
/// <summary> /// Check if the avatar's current pose is the same as the pose /// passed in /// </summary> /// <param name="frameIn"></param> public void CheckForPose(SerializeScript.SnapshotClass frameIn, Quaternion leftShoulderPoseIn) { //declare vars //get quaternion of local left shoulder Quaternion localLeftShoulder = transforms[(int)ZigJointId.LeftShoulder].rotation; //define vectors to compare Vector2 local, template; local = localLeftShoulder * Vector3.forward; template = leftShoulderPoseIn * Vector3.forward; Vector3.Normalize(local); Vector3.Normalize(template); //Quaternion leftShoulderInverse = Quaternion.Inverse(leftShoulderPoseIn); string QuatDotProduct = Quaternion.Dot(leftShoulderPoseIn, localLeftShoulder).ToString(); string dotProduct = Vector3.Dot(local, template).ToString(); //GUIOutputText1 = outputString1; //GUIOutputText2 = outputString2; GUIOutputText1 = dotProduct; GUIOutputText2 = QuatDotProduct; //Now redo using dot product of euclidian vectors }
/// <summary> /// Check if the avatar's current pose is the same as the pose /// passed in /// </summary> /// <param name="frameIn"></param> public void CheckForPose(SerializeScript.SnapshotClass frameIn, Quaternion leftShoulderPoseIn) { //declare vars float avatarX, avatarY, avatarZ, templateX, templateY, templateZ, xDiff, yDiff, zDiff; //instantiate vars /* templateX = frameIn.jointRotations[(int)ZigJointId.LeftShoulder].eulerAngles.x; templateY = frameIn.jointRotations[(int)ZigJointId.LeftShoulder].eulerAngles.y; templateZ = frameIn.jointRotations[(int)ZigJointId.LeftShoulder].eulerAngles.z; */ //get quaternion of local left shoulder Quaternion localLeftShoulder = transforms[(int)ZigJointId.LeftShoulder].rotation; //define vectors to compare Vector2 local, template; local = localLeftShoulder * Vector3.forward; template = leftShoulderPoseIn * Vector3.forward; Vector3.Normalize(local); Vector3.Normalize(template); //Quaternion leftShoulderInverse = Quaternion.Inverse(leftShoulderPoseIn); string QuatDotProduct = Quaternion.Dot(leftShoulderPoseIn, localLeftShoulder).ToString(); string dotProduct = Vector3.Dot(local, template).ToString(); //GUIOutputText1 = outputString1; //GUIOutputText2 = outputString2; GUIOutputText1 = dotProduct; GUIOutputText2 = QuatDotProduct; //Now redo using dot product of euclidian vectors }
/// <summary> /// Saves the playback list in memory to disk /// </summary> /// <param name="fileNameIn">target filename to save to</param> public void SaveList(string fileNameIn) { SerializeScript.SaveToDisk(fileNameIn, playbackList); Debug.Log("Playback list saved succesfully"); }
/// <summary> /// Used to export the indicated recording from disk. Triggered from the Ok button /// in the save dialog box. Exported files are compressed. /// </summary> /// <param name="fileNameIn"></param> public void ExportList(string fileNameIn) { SerializeScript.SaveToDisk(fileNameIn, CompressPlaybackList()); Debug.Log("File exported succesfully"); }