#include "AIBallistic.hxx"
-
FGAIBallistic::FGAIBallistic(FGAIManager* mgr) {
manager = mgr;
_type_str = "ballistic";
}
void FGAIBallistic::Run(double dt) {
+
life_timer += dt;
if (life_timer > life) setDie(true);
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
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;
}
#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
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));
}
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;
if (!enabled)
return;
- _dt = dt;
+ _dt = dt;
ai_list_itr = ai_list.begin();
while(ai_list_itr != ai_list.end()) {
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;
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);
ai_storm->setLatitude(entity->latitude);
ai_storm->init();
ai_storm->bind();
+ ai_list.push_back(ai_storm);
return ai_storm;
}
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);
ai_thermal->setDiameter(entity->diameter / 6076.11549);
ai_thermal->init();
ai_thermal->bind();
+ ai_list.push_back(ai_thermal);
return ai_thermal;
}
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 );
FGAIStorm::FGAIStorm(FGAIManager* mgr) {
manager = mgr;
- _type_str = "thunderstorm";
+ _type_str = "storm";
_otype = otStorm;
}