Example #1
0
        private void UpdateParameters()
        {
            // If we're currently at rest, start the timer.
            if (_atRest)
            {
                _ticks = Environment.TickCount;
            }

            _depTargetValue.OnGet();
            if (!_initialized)
            {
                // Start at the target value.
                _targetTicks = _ticks;
                _a           = 1.0F;
                _c           = _targetValue;
                _initialized = true;
            }
            else if (!_hasInertia)
            {
                // Fix at the target value.
                _targetTicks = _ticks;
                _a           = 1.0F;
                _c           = _targetValue;
            }
            else if (_c != _targetValue)
            {
                // Get the starting state using the previous parameters.
                float y0;
                float yp0;
                long  relativeToEnd = unchecked (_ticks - _targetTicks);
                if (relativeToEnd < 0)
                {
                    float x = relativeToEnd * SPEED;
                    y0  = _a * (2.0F * x + 3.0F) * x * x + _c;
                    yp0 = _a * (6.0F * x + 6.0F) * x;
                }
                else
                {
                    y0  = _c;
                    yp0 = 0.0F;
                }

                // Calculate the parameters of the curve based on the target value.
                float x0 = -1.0F;
                if (Math.Abs(yp0) > EPSILON)
                {
                    float t = 6.0F * (y0 - _targetValue) / yp0;         // Temporary
                    float d = (float)Math.Sqrt((t + 2.0F) * t + 9.0F);  // Square root of discriminant
                    float c = (t - 3.0F + d) / 4.0F;                    // Larger candidate root.

                    // x0 must be negative. If larger candidate is negative, use it. Otherwise, use smaller one.
                    x0 = (c < 0.0F) ? c : ((t - 3.0F - d) / 4.0F);
                }
                _a           = (y0 - _targetValue) / ((2.0F * x0 + 3.0F) * x0 * x0);
                _c           = _targetValue;
                _targetTicks = unchecked (_ticks - (long)(x0 / SPEED));
            }

            _atRest = false;
        }
 private void UpdateNow()
 {
     if (_running)
     {
         _computed.OnGet();
     }
 }
Example #3
0
 private void UpdateValue()
 {
     _depParameters.OnGet();
     if (!_atRest)
     {
         // Calculate the current value based on the current time and the parameters of the curve.
         _dynTicks.OnGet();
         long relativeToEnd = unchecked (_ticks - _targetTicks);
         if (relativeToEnd >= 0)
         {
             // We've reached the target. Stop moving.
             _atRest = true;
             _value  = _c;
         }
         else
         {
             // Determine the current position based on how much time is left.
             float x = relativeToEnd * SPEED;
             _value = _a * (2.0F * x + 3.0F) * x * x + _c;
         }
     }
 }
Example #4
0
 private void UpdateNow()
 {
     _depCollection.OnGet();
 }
Example #5
0
 public bool CanExecute(object parameter)
 {
     // Just returning the flag. The flag gets set elsewhere.
     _depCanExecute.OnGet();
     return(_canExecute);
 }