/// <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;
    }
Example #2
0
    /// <summary>
    /// Checks the tracking stream if the current posture matches the
    /// one of the keypoint passed in
    ///
    /// Invoked by timerTick if isListening is true
    /// </summary>
    public void ListenForGesture()
    {
        //check the first keypoint
        if (keypointsList != null)
        {
            if (keypointsList[0] != null)
            {
                //send snapshot to be checked
                SerializeScript.SnapshotClass checkSnap =
                    new SerializeScript.SnapshotClass();
                checkSnap = playbackList[keypointsList[0].frameID]; //assign snapshot

                //gather Eulerinfo on movement of character's left arm
                //Quaternion poseIn = GameObject.Find(indicatorGameObjectName).GetComponent<ZigSkeleton>()
                //  .ReturnLeftArmPose();

                //GameObject.Find(avatarGameObjectName).GetComponent<ZigSkeleton>()
                //  .CheckForPose(checkSnap, poseIn); //pass snap to thingy
            }

            else
            {
                listeningForGesture = false;
            }
        }

        else
        {
            listeningForGesture = false;
        }
    }
    /// <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>
 /// 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
        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>
    /// NOTE: THIS METHOD IS DEPRECATED:
    /// the system no longer plays back a recording; instead, in demo mode, the exercise is
    /// demonstrated key point at a time.
    /// plays the current frame from the recording in memory
    /// Note: Only invoked from TickEvent
    /// </summary>
    void PlayFrame()
    {
        if (currentFrame < playbackList.Count)    //check if playback is within bounds
        {
            //load current frame
            SerializeScript.SnapshotClass currFrame = playbackList[currentFrame];

            //play current frame
            GameObject.Find(avatarGameObjectName).GetComponent <ExtendedZigSkeleton>().PlayFrame(currFrame);

            //increment frame
            currentFrame++;
        }

        else     //playback has exceeded bounds
        {
            resetPlayback();
        }
    }
    public void CaptureFrameFunction(ZigTrackedUser user)
    {
        //create frame
        SerializeScript.SnapshotClass frame =
            new SerializeScript.SnapshotClass();

        foreach (ZigInputJoint joint in user.Skeleton)
        {
            if (joint.GoodRotation)
            {
                UpdateRotation(joint.Id, joint.Rotation);
            }
            if (joint.GoodRotation)
            {
                frame.jointRotations[(int)joint.Id] = joint.Rotation; //store joint?
            }
        }

        recordList.Add(frame);

        isReturningFrame = false; //reset flag
    }
    public void CaptureFrameFunction(ZigTrackedUser user)
    {
        //create frame
        SerializeScript.SnapshotClass frame =
            new SerializeScript.SnapshotClass();

        foreach (ZigInputJoint joint in user.Skeleton)
        {
            if (joint.GoodRotation) UpdateRotation(joint.Id, joint.Rotation);
            if (joint.GoodRotation)
            {
                frame.jointRotations[(int)joint.Id] = joint.Rotation; //store joint?
            }

        }

        recordList.Add(frame);

        isReturningFrame = false; //reset flag
    }
    /// <summary>
    /// Checks the tracking stream if the current posture matches the
    /// one of the keypoint passed in
    /// 
    /// Invoked by timerTick if isListening is true
    /// </summary>
    public void ListenForGesture()
    {
        //check the first keypoint
        if (keypointsList != null)
            if (keypointsList[0] != null)
            {

                //send snapshot to be checked
                SerializeScript.SnapshotClass checkSnap =
                    new SerializeScript.SnapshotClass();
                checkSnap = playbackList[keypointsList[0].frameID]; //assign snapshot

                //gather Eulerinfo on movement of character's left arm
                //Quaternion poseIn = GameObject.Find(indicatorGameObjectName).GetComponent<ZigSkeleton>()
                  //  .ReturnLeftArmPose();

                //GameObject.Find(avatarGameObjectName).GetComponent<ZigSkeleton>()
                  //  .CheckForPose(checkSnap, poseIn); //pass snap to thingy

            }

            else
                listeningForGesture = false;

        else
            listeningForGesture = false;
    }
    /// <summary>
    /// Checks if current posture matches the one of the keypoint passed in
    /// </summary>
    public void ListenForWholeBodyGesture()
    {
        //variables
        bool isHoldingPose = false;

        if (cloneCreated == false)    //if the clone is not instantiated
        {
            //make a copy of the player avatar in the same place
            //get position and rotation of avatar to create clone
            Vector3 avatarPosition =
                GameObject.Find(avatarGameObjectName).GetComponent <Transform>().position;
            Quaternion avatarRotation =
                GameObject.Find(avatarGameObjectName).GetComponent <Transform>().rotation;

            //instantiate clone
            gestureRecognitionClone = Instantiate(gestureRecognitionPrefab, avatarPosition, avatarRotation) as GameObject;

            //make clone invisible
            gestureRecognitionClone.GetComponentInChildren <Renderer>().enabled = false;

            cloneCreated = true;    //set flag to true
        }

        //check the current keypoint
        if (keypointsList != null)
        {
            if (keypointsList[currentKeyPoint] != null)
            {
                //send snapshot to be checked
                SerializeScript.SnapshotClass checkSnap =
                    new SerializeScript.SnapshotClass();
                checkSnap = playbackList[keypointsList[currentKeyPoint].frameID];     //assign snapshot

                //make the clone assume the pose to check
                gestureRecognitionClone.GetComponent <ExtendedZigSkeleton>().JumpToFrame(checkSnap);

                /*                //make the template model assume pose to check
                 *              GameObject.Find(indicatorGameObjectName).GetComponent<ZigSkeleton>()
                 *                  .JumpToFrame(checkSnap);
                 */

                List <Transform> avatarPose =
                    GameObject.Find(avatarGameObjectName).GetComponent <ExtendedZigSkeleton>().ReturnTransformsList();

                List <Transform> templatePose =
                    gestureRecognitionClone.GetComponent <ExtendedZigSkeleton>().ReturnTransformsList();

                if (!seatedModeOn)
                {
                    isHoldingPose = CheckForPose(avatarPose, templatePose);
                }
                else
                {
                    isHoldingPose = CheckForSeatedPose(avatarPose, templatePose);
                    //make gesture recognition clone assume seated mode
                    gestureRecognitionClone.GetComponent <ExtendedZigSkeleton>().SeatedMode();
                }

                if (isHoldingPose)
                {
                    feedbackText2.text  = "Holding Pose!";
                    isHoldingGesture    = true;  //initiate gesture
                    listeningForGesture = false; //disable listening for gesture
                }

                else
                {
                    feedbackText2.text = "Not holding Pose";
                }
            }

            else
            {
                listeningForWholeBodyGesture = false;
            }
        }

        else
        {
            listeningForWholeBodyGesture = false;
        }
    }
    /// <summary>
    /// Checks if current posture matches the one of the keypoint passed in
    /// </summary>
    public void ListenForWholeBodyGesture()
    {
        //variables
            bool isHoldingPose = false;

            if (cloneCreated == false)//if the clone is not instantiated
            {
                //make a copy of the player avatar in the same place
                //get position and rotation of avatar to create clone
                Vector3 avatarPosition =
                    GameObject.Find(avatarGameObjectName).GetComponent<Transform>().position;
                Quaternion avatarRotation =
                    GameObject.Find(avatarGameObjectName).GetComponent<Transform>().rotation;

                //instantiate clone
                gestureRecognitionClone = Instantiate(gestureRecognitionPrefab, avatarPosition, avatarRotation) as GameObject;

                //make clone invisible
                gestureRecognitionClone.GetComponentInChildren<Renderer>().enabled = false;

                cloneCreated = true;//set flag to true
            }

            //check the current keypoint
            if (keypointsList != null)
                if (keypointsList[currentKeyPoint] != null)
                {

                    //send snapshot to be checked
                    SerializeScript.SnapshotClass checkSnap =
                        new SerializeScript.SnapshotClass();
                    checkSnap = playbackList[keypointsList[currentKeyPoint].frameID]; //assign snapshot

                    //make the clone assume the pose to check
                    gestureRecognitionClone.GetComponent<ExtendedZigSkeleton>().JumpToFrame(checkSnap);

        /*                //make the template model assume pose to check
                    GameObject.Find(indicatorGameObjectName).GetComponent<ZigSkeleton>()
                        .JumpToFrame(checkSnap);
         */

                    List<Transform> avatarPose =
                        GameObject.Find(avatarGameObjectName).GetComponent<ExtendedZigSkeleton>().ReturnTransformsList();

                    List<Transform> templatePose =
                        gestureRecognitionClone.GetComponent<ExtendedZigSkeleton>().ReturnTransformsList();

                    if (!seatedModeOn)
                        isHoldingPose = CheckForPose(avatarPose, templatePose);
                    else
                    {
                        isHoldingPose = CheckForSeatedPose(avatarPose, templatePose);
                        //make gesture recognition clone assume seated mode
                        gestureRecognitionClone.GetComponent<ExtendedZigSkeleton>().SeatedMode();
                    }

                    if (isHoldingPose)
                    {
                        feedbackText2.text = "Holding Pose!";
                        isHoldingGesture = true; //initiate gesture
                        listeningForGesture = false; //disable listening for gesture
                    }

                    else
                        feedbackText2.text = "Not holding Pose";
                }

                else
                    listeningForWholeBodyGesture = false;

            else
                listeningForWholeBodyGesture = false;
    }