Example #1
0
 public void FastTick(double updateTime, int microSteps)
 {
     for (int j = 0; j < microSteps; j++)
     {
         TerminalGuidanceThrust(updateTime / microSteps, ref _currentState, _currentState.Position.Length);
         _integrator.Integrate(updateTime / microSteps, ref _currentState, out _currentState, ComputeCurrentAcceleration);
         _currentState.ReachedAltitude = Math.Max(_currentState.ReachedAltitude, _currentAltitude);
         if (_currentAltitude < -0.1)
         {
             _currentState.IsDone = true;
         }
     }
     LookAhead.CalculateOrbit(ref LookAheadState, _currentState);
 }
Example #2
0
        public void Tick(double updateTime, int rate, int microSteps)
        {
            for (int i = 0; i < rate; i++)
            {
                for (int j = 0; j < microSteps; j++)
                {
                    TerminalGuidanceThrust(updateTime / microSteps, ref _currentState, _currentState.Position.Length);
                    _integrator.Integrate(updateTime / microSteps, ref _currentState, out _currentState, ComputeCurrentAcceleration);
                    _currentState.ReachedAltitude = Math.Max(_currentState.ReachedAltitude, _currentAltitude);

                    double radius = _currentState.Position.Length;
                    if (radius < Constants.EarthRadius - 0.1)
                    {
                        _currentState.Position = _currentState.Position.Normalized() * (Constants.EarthRadius - 0.1);
                        _currentState.Velocity = Vector3d.Zero;
                        _currentState.IsDone   = true;
                    }
                }
                if ((_lastState.Position - _currentState.Position).LengthSquared > 100.0)
                {
                    ComputeCurrentAcceleration(updateTime, ref _currentState);
                    States.Add(_currentState);
                    _lastState = _currentState;
                }
            }

            ComputeCurrentAcceleration(updateTime, ref _currentState);
            States.Add(_currentState);
            _lastState = _currentState;

#if FAST_LOOKAHEAD
            LookAhead.CalculateOrbit(ref LookAheadState, _currentState);
#else
            if (_currentState.Atmosphere.Pressure < 1000.0)
            {
                LookAhead.CalculateOrbit(ref LookAheadState, _currentState);
            }
            else
            {
                var  positions             = LookAheadState.FuturePositions;
                var  timestep              = LookAheadTime / (LookAheadMicroSteps * positions.Length);
                bool exited                = false;
                var  lookAheadCurrentState = _currentState;
                positions[0] = _currentState.Position;
                for (var i = 1; i < positions.Length; i++)
                {
                    positions[i] = positions[i - 1];
                    if (exited)
                    {
                        continue;
                    }
                    for (var j = 0; j < LookAheadMicroSteps; j++)
                    {
                        _integrator.Integrate(timestep, ref lookAheadCurrentState, out lookAheadCurrentState, ComputeCurrentNaturalAcceleration);
                        double radius = lookAheadCurrentState.Position.Length;
                        if (radius < Constants.EarthRadius)
                        {
                            positions[i] = lookAheadCurrentState.Position;
                            LookAhead.Intersect(positions, i, out positions[i]);
                            exited = true;
                            break;
                        }
                    }
                    if (!exited)
                    {
                        positions[i] = lookAheadCurrentState.Position;
                    }
                }
            }
#endif
        }