Пример #1
0
        private void Update(EvaluationContext context)
        {
            var v       = Value.GetValue(context);
            var damping = Damping.GetValue(context);

            var f = (float)(damping * EvaluationContext.LastFrameDuration).Clamp(0f, 1f);

            _dampedValue = MathUtils.Lerp(v, _dampedValue, f);
            Result.Value = _dampedValue;
        }
Пример #2
0
        private void Update(EvaluationContext context)
        {
            var v       = Value.GetValue(context);
            var damping = Damping.GetValue(context);

            var t = context.LocalFxTime;

            if (Math.Abs(t - _lastEvalTime) < 0.001f)
            {
                return;
            }

            _lastEvalTime = t;
            const float FrameRate = 60f;

            var method = (Methods)Method.GetValue(context).Clamp(0, 1);

            switch (method)
            {
            case Methods.LinearInterpolation:
                var framesPassed = (int)((Playback.LastFrameDuration * FrameRate) - 0.5f).Clamp(0, 5) + 1;

                for (int stepIndex = 0; stepIndex < framesPassed; stepIndex++)
                {
                    _dampedValue = MathUtils.Lerp(v, _dampedValue, damping);
                }

                break;

            case Methods.DampedSpring:
                _dampedValue = MathUtils.SpringDamp(v, _dampedValue, ref _velocity, 0.5f / (damping + 0.001f), (float)Playback.LastFrameDuration);
                break;
            }

            // Prevent NaN
            if (float.IsNaN(_dampedValue) || float.IsNaN(_velocity))
            {
                _dampedValue = 0;
                _velocity    = 0;
            }

            Result.Value = _dampedValue;
        }