diff --git a/src/AIModel/AIBallistic.cxx b/src/AIModel/AIBallistic.cxx index d3ea25a1b..590177c31 100644 --- a/src/AIModel/AIBallistic.cxx +++ b/src/AIModel/AIBallistic.cxx @@ -27,7 +27,6 @@ #include "AIBallistic.hxx" - FGAIBallistic::FGAIBallistic(FGAIManager* mgr) { manager = mgr; _type_str = "ballistic"; @@ -122,6 +121,7 @@ void FGAIBallistic::setWeight(double w) { } void FGAIBallistic::Run(double dt) { + life_timer += dt; if (life_timer > life) setDie(true); @@ -130,7 +130,7 @@ void FGAIBallistic::Run(double dt) { double wind_speed_from_north_deg_sec; double wind_speed_from_east_deg_sec; double mass; - + // the drag calculations below assume sea-level density, // rho = 0.023780 slugs/ft3 // calculate mass @@ -153,7 +153,7 @@ void FGAIBallistic::Run(double dt) { speed_east_deg_sec = sin(hdg / SG_RADIANS_TO_DEGREES) * hs / ft_per_deg_lon; // if wind not required, set to zero - if (!wind){ + if (!wind) { wind_from_north = 0; wind_from_east = 0; } diff --git a/src/AIModel/AIBase.cxx b/src/AIModel/AIBase.cxx index 057f3bc84..f082f5176 100644 --- a/src/AIModel/AIBase.cxx +++ b/src/AIModel/AIBase.cxx @@ -44,7 +44,7 @@ #include "AIManager.hxx" -const double FGAIBase::rho = 0.023780; // sea level air density slugs/ft3 +const double FGAIBase::e = 2.71828183; const double FGAIBase::lbs_to_slugs = 0.031080950172; //conversion factor @@ -80,6 +80,24 @@ FGAIBase::~FGAIBase() { void FGAIBase::update(double dt) { 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); + + // Calculate rho at altitude, using standard atmosphere + // For the temperature T and the pressure p, + + if (altitude < 36152) { // curve fits for the troposphere + T = 59 - 0.00356 * altitude; + p = 2116 * pow( ((T + 459.7) / 518.6) , 5.256); + + } else if ( 36152 < altitude < 82345 ) { // lower stratosphere + T = -70; + p = 473.1 * pow( e , 1.73 - (0.000048 * altitude) ); + + } else { // upper stratosphere + T = -205.05 + (0.00164 * altitude); + p = 51.97 * pow( ((T + 459.7) / 389.98) , -11.388); + } + + rho = p / (1718 * (T + 459.7)); } diff --git a/src/AIModel/AIBase.hxx b/src/AIModel/AIBase.hxx index 89c798152..6b71e2c86 100644 --- a/src/AIModel/AIBase.hxx +++ b/src/AIModel/AIBase.hxx @@ -179,7 +179,10 @@ public: double _getY_shift() const; double _getRotation() const; - static const double rho; + double rho; + double T; // temperature, degs farenheit + double p; // pressure lbs/sq ft + static const double e; static const double lbs_to_slugs; int _getID() const; diff --git a/src/AIModel/AIManager.cxx b/src/AIModel/AIManager.cxx index 3c25f276e..d6839cf85 100644 --- a/src/AIModel/AIManager.cxx +++ b/src/AIModel/AIManager.cxx @@ -90,7 +90,7 @@ void FGAIManager::update(double dt) { if (!enabled) return; - _dt = dt; + _dt = dt; ai_list_itr = ai_list.begin(); while(ai_list_itr != ai_list.end()) { @@ -203,8 +203,8 @@ FGAIManager::createBallistic( FGAIModelEntity *entity ) { ai_ballistic->setWind_from_north(entity->wind_from_north); ai_ballistic->setWind(entity->wind); ai_ballistic->setRoll(entity->roll); - ai_ballistic->setCd(entity->cd); - ai_ballistic->setWeight(entity->weight); + ai_ballistic->setCd(entity->cd); + ai_ballistic->setWeight(entity->weight); ai_ballistic->init(); ai_ballistic->bind(); return ai_ballistic; @@ -214,7 +214,6 @@ void* FGAIManager::createStorm( FGAIModelEntity *entity ) { FGAIStorm* ai_storm = new FGAIStorm(this); - ai_list.push_back(ai_storm); ++numObjects[0]; ++numObjects[FGAIBase::otStorm]; ai_storm->setHeading(entity->heading); @@ -225,6 +224,7 @@ FGAIManager::createStorm( FGAIModelEntity *entity ) { ai_storm->setLatitude(entity->latitude); ai_storm->init(); ai_storm->bind(); + ai_list.push_back(ai_storm); return ai_storm; } @@ -232,7 +232,6 @@ void* FGAIManager::createThermal( FGAIModelEntity *entity ) { FGAIThermal* ai_thermal = new FGAIThermal(this); - ai_list.push_back(ai_thermal); ++numObjects[0]; ++numObjects[FGAIBase::otThermal]; ai_thermal->setLongitude(entity->longitude); @@ -241,6 +240,7 @@ FGAIManager::createThermal( FGAIModelEntity *entity ) { ai_thermal->setDiameter(entity->diameter / 6076.11549); ai_thermal->init(); ai_thermal->bind(); + ai_list.push_back(ai_thermal); return ai_thermal; } diff --git a/src/AIModel/AIManager.hxx b/src/AIModel/AIManager.hxx index fd3357f5b..1e430e819 100644 --- a/src/AIModel/AIManager.hxx +++ b/src/AIModel/AIManager.hxx @@ -78,7 +78,9 @@ public: inline double get_user_yaw() { return user_yaw; } inline double get_user_speed() {return user_speed; } - inline int getNum( FGAIBase::object_type ot ) { return numObjects[ot]; } + inline int getNum( FGAIBase::object_type ot ) { + return (0 < ot < FGAIBase::MAX_OBJECTS) ? numObjects[ot] : numObjects[0]; + } void processScenario( string filename ); diff --git a/src/AIModel/AIStorm.cxx b/src/AIModel/AIStorm.cxx index edba9038d..896253614 100644 --- a/src/AIModel/AIStorm.cxx +++ b/src/AIModel/AIStorm.cxx @@ -36,7 +36,7 @@ SG_USING_STD(string); FGAIStorm::FGAIStorm(FGAIManager* mgr) { manager = mgr; - _type_str = "thunderstorm"; + _type_str = "storm"; _otype = otStorm; }