Exemplo n.º 1
0
        private void InputText(string text)
        {
            if (LogOnReceive)
            {
                Debug.Log(">> " + text);
            }
            //receivedData = text;
            //newDataFlag = true;
            StreamFrameController.AppendNewFrameJson(text);

            // timing
            float thisFrameTime = currentFrameLength;

            currentFrameLength = 0f;
            if (avgFrameTime == float.PositiveInfinity)
            {
                if (!serverActive) // first package
                {
                    serverActive = true;
                }
                else   // second package
                {
                    avgFrameTime = thisFrameTime;
                }
            }
            else   // continueous receiving
            {
                avgFrameTime = (1f - CurrentTimeRatio) * avgFrameTime + CurrentTimeRatio * thisFrameTime;
            }
        }
Exemplo n.º 2
0
        // Update is called once per frame
        void Update()
        {
            switch (Controller.Mode)
            {
            case PlayMode.Stream:
            {
                // Update data
                if (StreamFrameController.DataNew)
                {
                    frameData = StreamFrameController.GetCurrentFrame();
                    //interpolateFrameRest = UDPReceiver.EstimatedRestFrameTime;
                    if (frameData.isValid)
                    {
                        // Calculate vertical stablization
                        if (AllowVerticalStablization)
                        {
                            UpdateModel(1f);         // set to next state
                            PushNewFeetHeights();    // calculate feet heights
                            if (IsVerticalStable() || GetLowestFeetHeight() < 0f)
                            {
                                HeightDiff -= GetLowestFeetHeight();
                            }
                            ChangeModelToLastSavedState();         // change the model state back
                        }
                        // New insert coroutine for new data
                        //if (AllowInterpolation)
                        {
                            StopCoroutine(InsertStepsCoroutine());
                            StartCoroutine(InsertStepsCoroutine());
                        }
                    }
                }
                // Update model every frame for interpolation

                /*if (AllowInterpolation)
                 * {
                 *  if (frameData.isValid)
                 *  {
                 *      UpdateModelAndFace(Time.deltaTime / interpolateFrameRest);
                 *  }
                 * }*/
            }
            break;

            case PlayMode.FileJson:
            {
                frameData = DataFrameController.GetCurrentFrame();
                bool newData = DataFrameController.RestFrameTime > interpolateFrameRest;
                interpolateFrameRest = DataFrameController.RestFrameTime;
                if (frameData.isValid)
                {
                    if (AllowVerticalStablization)
                    {
                        if (newData)                       // push new feet data
                        {
                            UpdateModel(1f);               // set to next state
                            PushNewFeetHeights();          // calculate feet heights
                            ChangeModelToLastSavedState(); // change the model state back
                        }

                        if (IsVerticalStable() || GetLowestFeetHeight() < 0f)
                        {
                            HeightDiff -= GetLowestFeetHeight();
                        }
                    }
                    if (AllowInterpolation)
                    {
                        UpdateModelAndFace(Time.deltaTime / interpolateFrameRest);
                    }
                    else
                    {
                        UpdateModelAndFace();
                    }
                }
            }
            break;

            case PlayMode.FileBvh:
            {
                frameData = DataFrameController.GetCurrentFrame();
                bool newData = DataFrameController.RestFrameTime > interpolateFrameRest;
                interpolateFrameRest = DataFrameController.RestFrameTime;
                if (frameData.isValid)
                {
                    if (AllowVerticalStablization)
                    {
                        if (newData)                       // push new feet data
                        {
                            UpdateModel(1f);               // set to next state
                            PushNewFeetHeights();          // calculate feet heights
                            ChangeModelToLastSavedState(); // change the model state back
                        }

                        if (IsVerticalStable() || GetLowestFeetHeight() < 0f)
                        {
                            HeightDiff -= GetLowestFeetHeight();
                        }
                    }
                    if (AllowInterpolation)
                    {
                        UpdateModel(Time.deltaTime / interpolateFrameRest);
                    }
                    else
                    {
                        UpdateModel();
                    }
                }
            }
            break;
            }
        }
 private void Awake()
 {
     instance = this;
 }