#include "AIThermal.hxx"
-FGAIThermal *FGAIThermal::_self = NULL;
-
FGAIThermal::FGAIThermal(FGAIManager* mgr) {
manager = mgr;
- _self = this;
_type_str = "thermal";
- strength = 6.0;
+ _otype = otThermal;
+ max_strength = 6.0;
diameter = 0.5;
+ strength = factor = 0.0;
}
FGAIThermal::~FGAIThermal() {
- _self = NULL;
}
bool FGAIThermal::init() {
- wind_from_down = fgGetNode("/environment/wind-from-down-fps", true);
- scaler = 8.0 * strength / (diameter * diameter * diameter);
+ factor = 8.0 * max_strength / (diameter * diameter * diameter);
return FGAIBase::init();
}
void FGAIThermal::update(double dt) {
+ FGAIBase::update(dt);
Run(dt);
Transform();
- FGAIBase::update(dt);
}
FGAIThermal::dt = dt;
- double ft_per_deg_lon;
- double ft_per_deg_lat;
-
- // get size of a degree at this latitude
- ft_per_deg_lat = 366468.96 - 3717.12 * cos(pos.lat()/SG_RADIANS_TO_DEGREES);
- ft_per_deg_lon = 365228.16 * cos(pos.lat() / SG_RADIANS_TO_DEGREES);
-
- double altitude_ft = altitude * SG_METER_TO_FEET;
-
//###########################//
// do calculations for range //
//###########################//
// calculate range to target in feet and nautical miles
double lat_range = fabs(pos.lat() - user_latitude) * ft_per_deg_lat;
double lon_range = fabs(pos.lon() - user_longitude) * ft_per_deg_lon;
- double range_ft = sqrt( lat_range*lat_range + lon_range*lon_range );
+ double range_ft = sqrt(lat_range*lat_range + lon_range*lon_range);
range = range_ft / 6076.11549;
- // Set rising air if within range.
+ // Calculate speed of rising air if within range.
// Air vertical speed is maximum at center of thermal,
// and decreases to zero at the edge (as distance cubed).
if (range < (diameter * 0.5)) {
- wind_from_down->setDoubleValue( strength - (range * range * range * scaler) );
+ strength = max_strength - ( range * range * range * factor );
} else {
- wind_from_down->setDoubleValue( 0.0 );
+ strength = 0.0;
+ }
+
+ // Stop lift at the top of the thermal (smoothly)
+ if (user_altitude > (height + 100.0)) {
+ strength = 0.0;
+ }
+ else if (user_altitude < height) {
+ // do nothing
+ }
+ else {
+ strength -= (strength * (user_altitude - height) * 0.01);
}
}