Ejemplo n.º 1
0
    /// <summary>
    /// Almacena una lista de frames con su correspondiente ángulo, considerando el ejercicio especificado, por ejemplo, para rodilla puede importar el ángulo que se genera entre los segmentos involucrados con el plano sagital
    /// </summary>
    /// <param name="exercise">Ejercicio al cual se le quieren extraer los ángulo de interés</param>
    /// <param name="action">Callback especificado para guardar los frames que se van generando</param>
    /// <returns></returns>
    private void SaveTimesAngle(AnimatorStateInfo animatorState) //ref List<AnimationInfo> aInfo)
    {
        JointTypePlanoResult tempJointTypePlanoResult = MovementJointMatch.movementJointMatch[new MovementLimbKey(movement, limb)];
        ArticulacionClass    joint             = AnimatorScript.instance.utils.getArticulacion(tempJointTypePlanoResult.jointType);
        AnimationInfo        tempAnimationInfo = new AnimationInfo();
        float time = animatorState.normalizedTime * animatorState.length;

        switch (tempJointTypePlanoResult.plain)
        {
        case Plano.planos.planoFrontal:
            tempAnimationInfo = new AnimationInfo(time, joint.AngleFrontal);
            break;

        case Plano.planos.planoHorizontal:
            tempAnimationInfo = new AnimationInfo(time, joint.AngleHorizontal);
            break;

        case Plano.planos.planoSagital:
            tempAnimationInfo = new AnimationInfo(time, joint.AngleSagital);
            break;

        case Plano.planos.planoHorizontalAcostado:
            tempAnimationInfo = new AnimationInfo(time, joint.AngleHorizontalAcostado);
            break;
        }
        _timeAndAngles.Add(tempAnimationInfo);
    }
Ejemplo n.º 2
0
    override public void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
    {
        clockBehaviour.Update();
        if (_BehaviourState == AnimationBehaviourState.INITIAL_POSE)
        {
            if (!animator.IsInTransition(0))
            {
                animator.speed = 0;
            }
            return;
        }

        #region Interpolate
        //Si no estamos en estado Stopped
        //Y estamos preparados para hacer Lerp
        //Y el tiempo que ha transcurrido de la ultima rep es mayor al tiempo de pause entre repeticiones. O no ha habido última rep.

        if (_BehaviourState != AnimationBehaviourState.STOPPED && ReadyToLerp &&
            (endRepTime == null || new TimeSpan(0, 0, (int)_currentParams.SecondsBetweenRepetitions) <= DateTime.Now - endRepTime))
        {
            if (!BeginRep && (!IsInterleaved || (IsInterleaved && limb == Limb.Left)) &&
                this._BehaviourState != AnimationBehaviourState.PREPARING_WEB &&
                this._BehaviourState != AnimationBehaviourState.PREPARING_WITH_PARAMS &&
                this._BehaviourState != AnimationBehaviourState.PREPARING_DEFAULT)
            {
                OnRepetitionReallyStart();
                BeginRep = true;
            }
            //if(_LerpBehaviourState == LerpBehaviourState.STOPPED)
            float timeSinceStarted   = Time.time - timeStartedLerping;
            float percentageComplete = 0f;

            /*
             * switch (_currentLerpState)
             * {
             *  case LerpState.Forward:
             *
             *      percentageComplete = timeSinceStarted / timeTakenDuringForwardLerp;
             *      Debug.Log("1 " + percentageComplete + "= " + timeSinceStarted + " / " + timeTakenDuringForwardLerp + " " + animator.GetCurrentAnimatorStateInfo(0).normalizedTime );
             *      break;
             *
             *  case LerpState.Stopped:
             *      if (_lastLerpState == LerpState.Forward)
             *      {
             *          percentageComplete = timeSinceStarted / timeTakenDuringForwardLerp;
             *          Debug.Log("2 " + percentageComplete + "= " + timeSinceStarted + " / " + timeTakenDuringForwardLerp + " " + animator.GetCurrentAnimatorStateInfo(0).normalizedTime);
             *      }
             *
             *      //De ser true, indica que termino una repeticion
             *      else if (_lastLerpState == LerpState.Backward)
             *      {
             *          percentageComplete = timeSinceStarted / timeTakenDuringBackwardLerp;
             *          Debug.Log("3 " + percentageComplete + "= " + timeSinceStarted + " / " + timeTakenDuringBackwardLerp + " " + animator.GetCurrentAnimatorStateInfo(0).normalizedTime);
             *      }
             *      break;
             *
             *  case LerpState.Backward:
             *      percentageComplete = timeSinceStarted / timeTakenDuringBackwardLerp;
             *      Debug.Log("4 " + percentageComplete + "= " + timeSinceStarted + " / " + timeTakenDuringBackwardLerp + " " + animator.GetCurrentAnimatorStateInfo(0).normalizedTime);
             *      break;
             * }*/

            percentageComplete = animator.GetCurrentAnimatorStateInfo(0).normalizedTime;

            //float normalizedSpeed;
            //if (percentageComplete < 0.5)
            //    normalizedSpeed = timeSinceStarted/timeTakenDuringForwardLerp * 4;
            //else
            //    normalizedSpeed = 4f- timeSinceStarted / timeTakenDuringForwardLerp * 4;
            //Aplico el suavizado "Smotherstep"
            //percentageComplete = percentageComplete * percentageComplete * (3f - 2f * percentageComplete);
            //float percentageSmotherstep = timeSinceStarted * timeSinceStarted * timeSinceStarted * (timeSinceStarted * (6f * timeSinceStarted - 15f) + 10f);

            float sp = endPosition + startPosition;


            if (!holdingPose)
            {
                animator.StartRecording(0);
                animator.speed = sp; // Mathf.Lerp(startPosition, endPosition, normalizedSpeed);
                                     //Debug.Log("% "+ percentageComplete + "normalized speed " + normalizedSpeed + "  speed " + animator.speed);
                animator.StopRecording();
            }

            float DELTA = 0.03f;
            if ((animator.speed > 0 && percentageComplete >= 1.0f - DELTA) ||
                (animator.speed < 0 && percentageComplete <= 0f + DELTA))
            {
                Debug.Log("int end " + percentageComplete);
                InterpolationEnd();
            }
        }
        else if (this._BehaviourState == AnimationBehaviourState.RUNNING_WITH_PARAMS)
        {
            animator.speed = 0;
        }


        if (_BehaviourState == AnimationBehaviourState.PREPARING_WITH_PARAMS)
        {
            timeSinceCapture += Time.deltaTime;
            if (timeSinceCapture > INTERVAL)
            {
                timeSinceCapture = timeSinceCapture - INTERVAL;

                /*
                 * if (exerciseDataGenerator == null)
                 *  exerciseDataGenerator = GameObject.FindObjectOfType<Detector.ExerciseDataGenerator>();
                 * if (this.exerciseDataGenerator != null)
                 *  this.exerciseDataGenerator.CaptureData();*/
            }
        }


        #endregion
        if (_BehaviourState == AnimationBehaviourState.PREPARING_DEFAULT || _BehaviourState == AnimationBehaviourState.PREPARING_WEB)
        {
            this.SaveTimesAngle(stateInfo);
        }
        lastReadyToLerp = ReadyToLerp;


        JointTypePlanoResult tempJointTypePlanoResult = MovementJointMatch.movementJointMatch[new MovementLimbKey(movement, limb)];
        ArticulacionClass    joint             = AnimatorScript.instance.utils.getArticulacion(tempJointTypePlanoResult.jointType);
        AnimationInfo        tempAnimationInfo = new AnimationInfo();
        float time = stateInfo.normalizedTime; //* stateInfo.length;
        switch (tempJointTypePlanoResult.plain)
        {
        case Plano.planos.planoFrontal:
            tempAnimationInfo = new AnimationInfo(time, joint.AngleFrontal);
            break;

        case Plano.planos.planoHorizontal:
            tempAnimationInfo = new AnimationInfo(time, joint.AngleHorizontal);
            break;

        case Plano.planos.planoSagital:
            tempAnimationInfo = new AnimationInfo(time, joint.AngleSagital);
            break;

        case Plano.planos.planoHorizontalAcostado:
            tempAnimationInfo = new AnimationInfo(time, joint.AngleHorizontalAcostado);
            break;
        }
        //GameObject.FindGameObjectWithTag("angulotexto").GetComponent<Text>().text = "Angulo " + joint.articulacion.ToString() + " : " + tempAnimationInfo.angle.ToString();
    }