// Update is called once per frame
    void Update()
    {
        if (saveCounter == 6 && !flag)
        {
            for (int i = 0; i < 2 * numExercises; i++)
            {
                //Get the data of the particular pose from the respective exercise, store it PoseModelDataClass object and then add it to the AllSavedPoses array
                PoseModelDataClass pose = new PoseModelDataClass();

                pose.numExercise = exerciseIndex;
                pose.BonePos     = ArraySavedPoses[i];

                AllSavedPoses.Add(pose);
            }
            flag = true;
        }
    }
        // Gets the difference between the User pose and the list of saved poses
        private void GetPoseDifference(bool isMirrored)
        {
            // by-default values
            bPoseMatched   = false;
            fMatchPercent  = 0f;
            fMatchPoseTime = 0f;

            KinectManager kinectManager = KinectManager.Instance;

            if (poseJoints == null || poseUser.avBoneDirs == null)
            {
                return;
            }

            if (sbDebug != null)
            {
                sbDebug.Clear();
                sbDebug.AppendLine();
            }

            // check the difference with saved poses, starting from the last one
            for (int p = 0; p < 2; p++)
            {
                float fAngleDiff = 0f;
                float fMaxDiff   = 0f;

                PoseModelDataClass modelPose = PoseArchive.AllSavedPoses[p + exerNum];
                for (int i = 0; i < poseJoints.Count; i++)
                {
                    Vector3 vPoseBone = modelPose.BonePos[i];
                    Vector3 vUserBone = poseUser.avBoneDirs[i];

                    if (vPoseBone == Vector3.zero || vUserBone == Vector3.zero)
                    {
                        continue;
                    }

                    float fDiff = Vector3.Angle(vPoseBone, vUserBone);
                    if (fDiff > 90f)
                    {
                        fDiff = 90f;
                    }

                    fAngleDiff += fDiff;
                    fMaxDiff   += 90f; // we assume the max diff could be 90 degrees

                    if (sbDebug != null)
                    {
                        sbDebug.AppendFormat("SP: {0}, {1} - angle: {2:F0}, match: {3:F0}%", p, poseJoints[i], fDiff, (1f - fDiff / 90f) * 100f);
                        sbDebug.AppendLine();
                    }
                }

                float fPoseMatch = fMaxDiff > 0f ? (1f - fAngleDiff / fMaxDiff) : 0f;
                if (fPoseMatch > fMatchPercent)
                {
                    fMatchPercent = fPoseMatch;
                    //fMatchPoseTime = poseModel.fTime;
                    bPoseMatched = (fMatchPercent >= matchThreshold);
                    if (bPoseMatched)
                    {
                        matchPercentIndex[p] = fMatchPercent * 100f;
                    }
                    else
                    {
                        matchPercentIndex[p] = 0;
                    }
                }
            }

            Debug.Log("THE MATCH PERCENTAGES ARE HERE: " + new Vector2(matchPercentIndex[0], matchPercentIndex[1]));
            //PosePercentage.text = matchPercentIndex[0].ToString() + "   ,   " + matchPercentIndex[1].ToString();

            //This is to find which pose the user is close to

            /*
             * if (matchPercentIndex[0] != 0 && matchPercentIndex[1] != 0)
             * {
             *  Debug.Log(new Vector2(matchPercentIndex[0], matchPercentIndex[1]));
             *  if (matchPercentIndex[0] / matchPercentIndex[1] > 1)
             *      identifiedPose = 1;
             *  else
             *      identifiedPose = 2;
             * }
             * else
             * {
             *  identifiedPose = 0;
             * }*/

            //This is to check if user's start and end poses are close to a threshold percentage value
            if (matchPercentIndex[0] != 0 && matchPercentIndex[1] == 0)
            {
                identifiedPose = 1;
            }
            else if (matchPercentIndex[0] == 0 && matchPercentIndex[1] != 0)
            {
                identifiedPose = 2;
            }
        }