X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FAIModel%2FAIThermal.cxx;h=e9ad927a137e24fc4aedb4fda5364d63e9200dc1;hb=de35bbe4ed350bc3e90f66a11039e983587c5ea0;hp=812f5e01e9f0fe4099533177b75de5cf39266763;hpb=ed4509d8b5ad725a19b91bcfb841c56c2aa9de61;p=flightgear.git diff --git a/src/AIModel/AIThermal.cxx b/src/AIModel/AIThermal.cxx index 812f5e01e..e9ad927a1 100644 --- a/src/AIModel/AIThermal.cxx +++ b/src/AIModel/AIThermal.cxx @@ -16,44 +16,47 @@ // // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software -// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #ifdef HAVE_CONFIG_H # include #endif -#include #include
#include
#include #include #include -SG_USING_STD(string); +using std::string; #include "AIThermal.hxx" -FGAIThermal *FGAIThermal::_self = NULL; - -FGAIThermal::FGAIThermal(FGAIManager* mgr) { - manager = mgr; - _self = this; - _type_str = "thermal"; - strength = 6.0; +FGAIThermal::FGAIThermal() : FGAIBase(otThermal) { + max_strength = 6.0; diameter = 0.5; + strength = factor = 0.0; } - FGAIThermal::~FGAIThermal() { - _self = NULL; } +void FGAIThermal::readFromScenario(SGPropertyNode* scFileNode) { + if (!scFileNode) + return; -bool FGAIThermal::init() { - wind_from_down = fgGetNode("/environment/wind-from-down-fps", true); - scaler = 8.0 * strength / (diameter * diameter * diameter); - return FGAIBase::init(); + FGAIBase::readFromScenario(scFileNode); + + setMaxStrength(scFileNode->getDoubleValue("strength-fps", 8.0)); + setDiameter(scFileNode->getDoubleValue("diameter-ft", 0.0)/6076.11549); + setHeight(scFileNode->getDoubleValue("height-msl", 5000.0)); +} + +bool FGAIThermal::init(bool search_in_AI_path) { + factor = 8.0 * max_strength / (diameter * diameter * diameter); + setAltitude( height ); + return FGAIBase::init(search_in_AI_path); } void FGAIThermal::bind() { @@ -66,25 +69,14 @@ void FGAIThermal::unbind() { void FGAIThermal::update(double dt) { + FGAIBase::update(dt); Run(dt); Transform(); - FGAIBase::update(dt); } void FGAIThermal::Run(double 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 // //###########################// @@ -95,18 +87,29 @@ void FGAIThermal::Run(double dt) { double user_altitude = manager->get_user_altitude(); // 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 lat_range = fabs(pos.getLatitudeDeg() - user_latitude) * ft_per_deg_lat; + double lon_range = fabs(pos.getLongitudeDeg() - user_longitude) * ft_per_deg_lon; + 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); } }