- // Generate interpolated values between the METAR and the current
- // configuration.
-
- // Pick up the METAR wind values and convert them into a vector.
- double metar[2];
- double metar_speed = base_wind_speed_n->getDoubleValue();
- double metar_heading = base_wind_dir_n->getDoubleValue();
-
- metar[0] = metar_speed * sin(metar_heading * SG_DEGREES_TO_RADIANS );
- metar[1] = metar_speed * cos(metar_heading * SG_DEGREES_TO_RADIANS);
-
- // Convert the current wind values and convert them into a vector
- double current[2];
- double speed = boundary_wind_speed_n->getDoubleValue();
- double dir_from = boundary_wind_from_heading_n->getDoubleValue();;
-
- current[0] = speed * sin(dir_from * SG_DEGREES_TO_RADIANS );
- current[1] = speed * cos(dir_from * SG_DEGREES_TO_RADIANS );
-
- // Determine the maximum component-wise value that the wind can change.
- // First we determine the fraction in the X and Y component, then
- // factor by the maximum wind change.
- double x = fabs(current[0] - metar[0]);
- double y = fabs(current[1] - metar[1]);
-
- // only interpolate if we have a difference
- if (x + y > 0) {
- double dx = x / (x + y);
- double dy = 1 - dx;
-
- double maxdx = dx * MaxWindChangeKtsSec;
- double maxdy = dy * MaxWindChangeKtsSec;
-
- // Interpolate each component separately.
- current[0] = interpolate_val(current[0], metar[0], maxdx);
- current[1] = interpolate_val(current[1], metar[1], maxdy);
-
- // Now convert back to polar coordinates.
- if ((current[0] == 0.0) && (current[1] == 0.0)) {
- // Special case where there is no wind (otherwise atan2 barfs)
- speed = 0.0;
- } else {
- // Some real wind to convert back from. Work out the speed
- // and direction value in degrees.
- speed = sqrt((current[0] * current[0]) + (current[1] * current[1]));
- dir_from = (atan2(current[0], current[1]) * SG_RADIANS_TO_DEGREES );
-
- // Normalize the direction.
- if (dir_from < 0.0)
- dir_from += 360.0;
-
- SG_LOG( SG_GENERAL, SG_DEBUG, "Wind : " << dir_from << "@" << speed);
+ if( wind_interpolation_required ) {
+ // Generate interpolated values between the METAR and the current
+ // configuration.
+
+ // Pick up the METAR wind values and convert them into a vector.
+ double metar[2];
+ double metar_speed = base_wind_speed_n->getDoubleValue();
+ double metar_heading = base_wind_dir_n->getDoubleValue()+magnetic_variation_n->getDoubleValue();
+
+ metar[0] = metar_speed * sin(metar_heading * SG_DEGREES_TO_RADIANS );
+ metar[1] = metar_speed * cos(metar_heading * SG_DEGREES_TO_RADIANS);
+
+ // Convert the current wind values and convert them into a vector
+ double current[2];
+ double speed = boundary_wind_speed_n->getDoubleValue();
+ double dir_from = boundary_wind_from_heading_n->getDoubleValue();;
+
+ current[0] = speed * sin(dir_from * SG_DEGREES_TO_RADIANS );
+ current[1] = speed * cos(dir_from * SG_DEGREES_TO_RADIANS );
+
+ // Determine the maximum component-wise value that the wind can change.
+ // First we determine the fraction in the X and Y component, then
+ // factor by the maximum wind change.
+ double x = fabs(current[0] - metar[0]);
+ double y = fabs(current[1] - metar[1]);
+
+ // only interpolate if we have a difference
+ if (x + y > 0.01 ) {
+ double dx = x / (x + y);
+ double dy = 1 - dx;
+
+ double maxdx = dx * MaxWindChangeKtsSec;
+ double maxdy = dy * MaxWindChangeKtsSec;
+
+ // Interpolate each component separately.
+ current[0] = interpolate_val(current[0], metar[0], maxdx*dt);
+ current[1] = interpolate_val(current[1], metar[1], maxdy*dt);
+
+ // Now convert back to polar coordinates.
+ if ((fabs(current[0]) > 0.1) || (fabs(current[1]) > 0.1)) {
+ // Some real wind to convert back from. Work out the speed
+ // and direction value in degrees.
+ speed = sqrt((current[0] * current[0]) + (current[1] * current[1]));
+ dir_from = (atan2(current[0], current[1]) * SG_RADIANS_TO_DEGREES );
+
+ // Normalize the direction.
+ if (dir_from < 0.0)
+ dir_from += 360.0;
+
+ SG_LOG( SG_GENERAL, SG_DEBUG, "Wind : " << dir_from << "@" << speed);
+ } else {
+ // Special case where there is no wind (otherwise atan2 barfs)
+ speed = 0.0;
+ }
+ double gust = gust_wind_speed_n->getDoubleValue();
+ setupWind(setup_winds_aloft, dir_from, speed, gust);
+ reinit_required = true;
+ } else {
+ wind_interpolation_required = false;
+ }
+ } else { // if(wind_interpolation_required)
+ // interpolation of wind vector is finished, apply wind
+ // variations and gusts for the boundary layer only
+
+
+ bool wind_modulated = false;
+
+ // start with the main wind direction
+ double wind_dir = base_wind_dir_n->getDoubleValue()+magnetic_variation_n->getDoubleValue();
+ double min = convert_to_180(base_wind_range_from_n->getDoubleValue()+magnetic_variation_n->getDoubleValue());
+ double max = convert_to_180(base_wind_range_to_n->getDoubleValue()+magnetic_variation_n->getDoubleValue());
+ if( max > min ) {
+ // if variable winds configured, modulate the wind direction
+ double f = windModulator->get_direction_offset_norm();
+ wind_dir = min+(max-min)*f;
+ double old = convert_to_180(boundary_wind_from_heading_n->getDoubleValue());
+ wind_dir = convert_to_360(fgGetLowPass(old, wind_dir, dt ));
+ wind_modulated = true;
+ }
+
+ // start with main wind speed
+ double wind_speed = base_wind_speed_n->getDoubleValue();
+ max = gust_wind_speed_n->getDoubleValue();
+ if( max > wind_speed ) {
+ // if gusts are configured, modulate wind magnitude
+ double f = windModulator->get_magnitude_factor_norm();
+ wind_speed = wind_speed+(max-wind_speed)*f;
+ wind_speed = fgGetLowPass(boundary_wind_speed_n->getDoubleValue(), wind_speed, dt );
+ wind_modulated = true;
+ }
+ if( wind_modulated ) {
+ setupWind(false, wind_dir, wind_speed, max);
+ reinit_required = true;