From da02c09ec08cc357926ce6f06b3c6fc5925986d8 Mon Sep 17 00:00:00 2001 From: Torsten Dreyer Date: Tue, 20 Jul 2010 22:56:15 +0200 Subject: [PATCH 1/6] Bugfix: set temp and dewpoint from the gui This fix (re)enables the setting of temperature and dewpoint from the weather-conditions dialog and other sources for various altitude layers. These temperatures are reduced to the corresponding sea level temperatures according to ICAO standard atmosphere which is the inverse function of the calculation of temperature at altitude based on sea-level-temperature. Note: this only works for the troposphere. --- src/Environment/environment.cxx | 35 +++++++++++++++++----------- src/Environment/environment_ctrl.cxx | 9 +++++-- src/Environment/environment_ctrl.hxx | 2 +- 3 files changed, 30 insertions(+), 16 deletions(-) diff --git a/src/Environment/environment.cxx b/src/Environment/environment.cxx index 9a5755e3d..30354ffd9 100644 --- a/src/Environment/environment.cxx +++ b/src/Environment/environment.cxx @@ -211,20 +211,32 @@ FGEnvironment::read (const SGPropertyNode * node) maybe_copy_value(this, node, "visibility-m", &FGEnvironment::set_visibility_m); + maybe_copy_value(this, node, "elevation-ft", + &FGEnvironment::set_elevation_ft); + if (!maybe_copy_value(this, node, "temperature-sea-level-degc", - &FGEnvironment::set_temperature_sea_level_degc)) - maybe_copy_value(this, node, "temperature-degc", - &FGEnvironment::set_temperature_degc); + &FGEnvironment::set_temperature_sea_level_degc)) { + if( maybe_copy_value(this, node, "temperature-degc", + &FGEnvironment::set_temperature_degc)) { + _recalc_sl_temperature(); + } + } if (!maybe_copy_value(this, node, "dewpoint-sea-level-degc", - &FGEnvironment::set_dewpoint_sea_level_degc)) - maybe_copy_value(this, node, "dewpoint-degc", - &FGEnvironment::set_dewpoint_degc); + &FGEnvironment::set_dewpoint_sea_level_degc)) { + if( maybe_copy_value(this, node, "dewpoint-degc", + &FGEnvironment::set_dewpoint_degc)) { + _recalc_sl_dewpoint(); + } + } if (!maybe_copy_value(this, node, "pressure-sea-level-inhg", - &FGEnvironment::set_pressure_sea_level_inhg)) - maybe_copy_value(this, node, "pressure-inhg", - &FGEnvironment::set_pressure_inhg); + &FGEnvironment::set_pressure_sea_level_inhg)) { + if( maybe_copy_value(this, node, "pressure-inhg", + &FGEnvironment::set_pressure_inhg)) { + _recalc_sl_pressure(); + } + } maybe_copy_value(this, node, "wind-from-heading-deg", &FGEnvironment::set_wind_from_heading_deg); @@ -232,9 +244,6 @@ FGEnvironment::read (const SGPropertyNode * node) maybe_copy_value(this, node, "wind-speed-kt", &FGEnvironment::set_wind_speed_kt); - maybe_copy_value(this, node, "elevation-ft", - &FGEnvironment::set_elevation_ft); - maybe_copy_value(this, node, "turbulence/magnitude-norm", &FGEnvironment::set_turbulence_magnitude_norm); @@ -652,7 +661,7 @@ FGEnvironment::_recalc_sl_temperature () } #endif - if (elevation_ft >= ISA_def[1].height) { + if (elevation_ft * atmodel::foot >= ISA_def[1].height) { SG_LOG(SG_GENERAL, SG_ALERT, "recalc_sl_temperature: " << "valid only in troposphere, not " << elevation_ft); return; diff --git a/src/Environment/environment_ctrl.cxx b/src/Environment/environment_ctrl.cxx index ea9c9b628..ac870e5e2 100644 --- a/src/Environment/environment_ctrl.cxx +++ b/src/Environment/environment_ctrl.cxx @@ -132,7 +132,9 @@ void FGInterpolateEnvironmentCtrl::init () { read_table( boundary_n, _boundary_table); - read_table( aloft_n, _aloft_table); + // pass in a pointer to the environment of the last bondary layer as + // a starting point + read_table( aloft_n, _aloft_table, &(*(_boundary_table.end()-1))->environment); } void @@ -142,7 +144,7 @@ FGInterpolateEnvironmentCtrl::reinit () } void -FGInterpolateEnvironmentCtrl::read_table (const SGPropertyNode * node, vector &table) +FGInterpolateEnvironmentCtrl::read_table (const SGPropertyNode * node, vector &table, FGEnvironment * parent ) { double last_altitude_ft = 0.0; double sort_required = false; @@ -163,8 +165,11 @@ FGInterpolateEnvironmentCtrl::read_table (const SGPropertyNode * node, vectorenvironment.copy( *parent ); if (i > 0) b->environment.copy(table[i-1]->environment); + b->environment.read(child); b->altitude_ft = b->environment.get_elevation_ft(); diff --git a/src/Environment/environment_ctrl.hxx b/src/Environment/environment_ctrl.hxx index aec1442cb..1f81c0259 100644 --- a/src/Environment/environment_ctrl.hxx +++ b/src/Environment/environment_ctrl.hxx @@ -101,7 +101,7 @@ private: static bool lessThan(bucket *a, bucket *b); }; - void read_table (const SGPropertyNode * node, std::vector &table); + void read_table (const SGPropertyNode * node, std::vector &table, FGEnvironment * parent = NULL ); void do_interpolate (std::vector &table, double altitude_ft, FGEnvironment * environment); From 8dd39e773e14db4579cca324b6e6bd40eaaa24df Mon Sep 17 00:00:00 2001 From: James Turner Date: Thu, 22 Jul 2010 00:31:29 +0100 Subject: [PATCH 2/6] Thorsten: work around crashes when re-positioning, in the ATC-DCL code. --- src/ATCDCL/AILocalTraffic.cxx | 14 ++++++++++---- src/ATCDCL/ATCmgr.cxx | 7 ++++--- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/ATCDCL/AILocalTraffic.cxx b/src/ATCDCL/AILocalTraffic.cxx index 8a66eda6e..4c3e67c57 100644 --- a/src/ATCDCL/AILocalTraffic.cxx +++ b/src/ATCDCL/AILocalTraffic.cxx @@ -108,6 +108,12 @@ FGAILocalTraffic::FGAILocalTraffic() { _controlled = false; _invisible = false; + + ground = NULL; + tower = NULL; + ourGate = NULL; + nextTaxiNode = NULL; + holdShortNode = NULL; } FGAILocalTraffic::~FGAILocalTraffic() { @@ -1254,13 +1260,13 @@ void FGAILocalTraffic::ProcessCallback(int code) { if(code == 1) { ground->RequestDeparture(plane, this); } else if(code == 2) { - tower->ContactAtHoldShort(plane, this, CIRCUIT); + if (_controlled) tower->ContactAtHoldShort(plane, this, CIRCUIT); } else if(code == 3) { - tower->ReportRunwayVacated(plane.callsign); + if (_controlled) tower->ReportRunwayVacated(plane.callsign); } else if(code == 11) { - tower->ReportDownwind(plane.callsign); + if (_controlled) tower->ReportDownwind(plane.callsign); } else if(code == 13) { - tower->ReportFinal(plane.callsign); + if (_controlled) tower->ReportFinal(plane.callsign); } else if(code == 99) { // Flag this instance for deletion responseCounter = 0; _removeSelf = true; diff --git a/src/ATCDCL/ATCmgr.cxx b/src/ATCDCL/ATCmgr.cxx index 19053adef..2cb352a4f 100644 --- a/src/ATCDCL/ATCmgr.cxx +++ b/src/ATCDCL/ATCmgr.cxx @@ -273,8 +273,7 @@ typedef map MSI; void FGATCMgr::ZapOtherService(const string ncunit, const string svc_name){ for (atc_list_iterator svc = atc_list->begin(); svc != atc_list->end(); svc++) { - //cout << "Zapping " << navcomm - // << "[" << unit << "]" << " otherthan: " << svc_name << endl; + if (svc->first != svc_name) { MSI &actv = svc->second->active_on; // OK, we have found some OTHER service; @@ -286,7 +285,9 @@ void FGATCMgr::ZapOtherService(const string ncunit, const string svc_name){ //cout << "Eradicating service: '" << svc->first << "'" << endl; svc->second->SetNoDisplay(); svc->second->Update(0); // one last update - delete svc->second; + SG_LOG(SG_GENERAL, SG_INFO, "would have erased ATC service:" << svc->second->get_name()<< "/" + << svc->second->get_ident()); + // delete svc->second; atc_list->erase(svc); // ALL pointers into the ATC list are now invalid, // so let's reset them: From bf52c378a42aec382ff6d16e9b1af9bd1d95d831 Mon Sep 17 00:00:00 2001 From: James Turner Date: Thu, 22 Jul 2010 01:36:32 +0100 Subject: [PATCH 3/6] Clean up names in --show-aircraft; avoid -set.xml suffixes. --- src/Main/fg_init.cxx | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Main/fg_init.cxx b/src/Main/fg_init.cxx index 6f2f48411..4c2404dba 100644 --- a/src/Main/fg_init.cxx +++ b/src/Main/fg_init.cxx @@ -1777,6 +1777,11 @@ private: int maturity = 0; string descStr(" "); descStr += path.file(); + // trim common suffix from file names + int nPos = descStr.rfind("-set.xml"); + if (nPos == (int)(descStr.size() - 8)) { + descStr.resize(nPos); + } SGPropertyNode *node = root.getNode("sim"); if (node) { From 900fce637486f98b66cb5e4e17ee6bb641043952 Mon Sep 17 00:00:00 2001 From: James Turner Date: Fri, 23 Jul 2010 09:41:37 +0100 Subject: [PATCH 4/6] Fix issues exposed by PLIB-free SimGear. --- src/AIModel/AIFlightPlan.cxx | 18 ++++---------- src/AIModel/AIFlightPlanCreateCruise.cxx | 31 ++++++++---------------- src/Environment/fgclouds.cxx | 3 +-- src/Main/viewmgr.cxx | 2 +- 4 files changed, 17 insertions(+), 37 deletions(-) diff --git a/src/AIModel/AIFlightPlan.cxx b/src/AIModel/AIFlightPlan.cxx index 381f9e944..8f985ddcd 100644 --- a/src/AIModel/AIFlightPlan.cxx +++ b/src/AIModel/AIFlightPlan.cxx @@ -175,20 +175,12 @@ FGAIFlightPlan::FGAIFlightPlan(FGAIAircraft *ac, if (wpt->name == "END") wpt->finished = true; else wpt->finished = false; waypoints.push_back(wpt); - } - } - catch (const sg_exception &) { - SG_LOG(SG_GENERAL, SG_WARN, - "Error reading AI flight plan: "); - cerr << "Errno = " << errno << endl; - if (errno == ENOENT) - { - SG_LOG(SG_GENERAL, SG_WARN, "Reason: No such file or directory"); - } - } + } // of node loop + } catch (const sg_exception &e) { + SG_LOG(SG_GENERAL, SG_WARN, "Error reading AI flight plan: " << + e.getMessage() << " from " << e.getOrigin()); } - else - { + } else { // cout << path.str() << endl; // cout << "Trying to create this plan dynamically" << endl; // cout << "Route from " << dep->id << " to " << arr->id << endl; diff --git a/src/AIModel/AIFlightPlanCreateCruise.cxx b/src/AIModel/AIFlightPlanCreateCruise.cxx index d20a2134b..13df4b607 100644 --- a/src/AIModel/AIFlightPlanCreateCruise.cxx +++ b/src/AIModel/AIFlightPlanCreateCruise.cxx @@ -38,7 +38,6 @@ #include "AIAircraft.hxx" #include "performancedata.hxx" - using std::iostream; void FGAIFlightPlan::evaluateRoutePart(double deplat, @@ -55,28 +54,18 @@ void FGAIFlightPlan::evaluateRoutePart(double deplat, SGGeoc arr(SGGeoc::fromDegM(arrlon, arrlat, 100.0)); SGVec3d a = SGVec3d::fromGeoc(dep); - SGVec3d b = SGVec3d::fromGeoc(arr); - SGVec3d _cross = cross(b, a); + SGVec3d nb = normalize(SGVec3d::fromGeoc(arr)); + SGVec3d na = normalize(a); + + SGVec3d _cross = cross(nb, na); - double angle = sgACos(dot(a, b)); + double angle = acos(dot(na, nb)); + const double angleStep = 0.05 * SG_DEGREES_TO_RADIANS; tmpNode = 0; - for (double ang = 0.0; ang < angle; ang += 0.05) - { - sgdVec3 newPos; - sgdMat4 matrix; - //cerr << "Angle = " << ang << endl; - sgdMakeRotMat4(matrix, ang, _cross.data()); - for(int j = 0; j < 3; j++) - { - newPos[j] =0.0; - for (int k = 0; k<3; k++) - { - newPos[j] += matrix[j][k]*a[k]; - } - } - - //cerr << "1"<< endl; - SGGeod geod = SGGeod::fromCart(SGVec3d(newPos[0], newPos[1], newPos[2])); + for (double ang = 0.0; ang < angle; ang += angleStep) + { + SGQuatd q = SGQuatd::fromAngleAxis(ang, _cross); + SGGeod geod = SGGeod::fromCart(q.transform(a)); prevNode = tmpNode; tmpNode = globals->get_airwaynet()->findNearestNode(geod); diff --git a/src/Environment/fgclouds.cxx b/src/Environment/fgclouds.cxx index 606a4973e..f58d324f4 100644 --- a/src/Environment/fgclouds.cxx +++ b/src/Environment/fgclouds.cxx @@ -100,8 +100,7 @@ double FGClouds::buildCloud(SGPropertyNode *cloud_def_root, SGPropertyNode *box_ double y = sg_random() * SGCloudField::fieldSize - (SGCloudField::fieldSize / 2.0); double z = grid_z_rand * (sg_random() - 0.5); - sgVec3 pos={x,y,z}; - + SGVec3f pos(x,y,z); for(int i = 0; i < box_def->nChildren() ; i++) { SGPropertyNode *abox = box_def->getChild(i); diff --git a/src/Main/viewmgr.cxx b/src/Main/viewmgr.cxx index 270c579e0..6859c8f41 100644 --- a/src/Main/viewmgr.cxx +++ b/src/Main/viewmgr.cxx @@ -190,7 +190,7 @@ FGViewMgr::bind () fgTie("/sim/current-view/view-number", this, &FGViewMgr::getView, &FGViewMgr::setView); - fgSetArchivable("/sim/current-view/view-number", FALSE); + fgSetArchivable("/sim/current-view/view-number", false); fgTie("/sim/current-view/axes/long", this, (double_getter)0, &FGViewMgr::setViewAxisLong); From 9604908a8d38767345410447b75a13582158128e Mon Sep 17 00:00:00 2001 From: James Turner Date: Fri, 23 Jul 2010 13:26:07 +0100 Subject: [PATCH 5/6] Remove all (2) uses of simgear/math/vector.h from FlightGear. --- src/Instrumentation/HUD/HUD_ladder.cxx | 14 +++++----- src/Instrumentation/navradio.cxx | 1 - src/Main/viewer.cxx | 1 - src/Scenery/tilemgr.cxx | 1 - src/Time/tmp.cxx | 37 +++++++++++++++++++++++--- 5 files changed, 39 insertions(+), 15 deletions(-) diff --git a/src/Instrumentation/HUD/HUD_ladder.cxx b/src/Instrumentation/HUD/HUD_ladder.cxx index 75b2e3afc..478ffa1b1 100644 --- a/src/Instrumentation/HUD/HUD_ladder.cxx +++ b/src/Instrumentation/HUD/HUD_ladder.cxx @@ -24,11 +24,10 @@ #endif #include -#include +#include #include
#include "HUD.hxx" - // FIXME static float get__heading() { return fgGetFloat("/orientation/heading-deg") * M_PI / 180.0; } static float get__throttleval() { return fgGetFloat("/controls/engines/engine/throttle"); } @@ -424,12 +423,11 @@ void HUD::Ladder::draw(void) // however the horizon line should always stay on the horizon. We // project the alpha/beta offset onto the horizon line to get the // result we want. - sgdVec3 p1; // result - sgdVec3 p; sgdSetVec3(p, vel_x, vel_y, 0.0); - sgdVec3 p0; sgdSetVec3(p0, 0.0, 0.0, 0.0); - sgdVec3 d; sgdSetVec3(d, cos(roll_value), sin(roll_value), 0.0); - sgdClosestPointToLine(p1, p, p0, d); - glTranslatef(p1[0], p1[1], 0); + + SGVec3d d(cos(roll_value), sin(roll_value), 0.0); + SGRayd r(SGVec3d::zeros(), d); + SGVec3d p = r.getClosestPointTo(SGVec3d(vel_x, vel_y, 0.0)); + glTranslatef(p[0], p[1], 0); } } else { // ladder position is fixed relative to the center of the screen. diff --git a/src/Instrumentation/navradio.cxx b/src/Instrumentation/navradio.cxx index cdf617530..f8cc3bebb 100644 --- a/src/Instrumentation/navradio.cxx +++ b/src/Instrumentation/navradio.cxx @@ -31,7 +31,6 @@ #include #include -#include #include #include #include diff --git a/src/Main/viewer.cxx b/src/Main/viewer.cxx index ffa05fc3f..d7b51d859 100644 --- a/src/Main/viewer.cxx +++ b/src/Main/viewer.cxx @@ -34,7 +34,6 @@ #include #include #include -#include #include
#include diff --git a/src/Scenery/tilemgr.cxx b/src/Scenery/tilemgr.cxx index a7bbb388b..e5cd08bbb 100644 --- a/src/Scenery/tilemgr.cxx +++ b/src/Scenery/tilemgr.cxx @@ -32,7 +32,6 @@ #include #include -#include #include #include #include diff --git a/src/Time/tmp.cxx b/src/Time/tmp.cxx index 0e04d5b24..3b3ae2a38 100644 --- a/src/Time/tmp.cxx +++ b/src/Time/tmp.cxx @@ -26,7 +26,6 @@ #endif #include -#include #include #include @@ -39,6 +38,37 @@ #include "sunsolver.hxx" #include "tmp.hxx" +/** + * Map i.e. project a vector onto a plane. + * @param normal (in) normal vector for the plane + * @param v0 (in) a point on the plane + * @param vec (in) the vector to map onto the plane + */ +static SGVec3f map_vec_onto_cur_surface_plane(const SGVec3f& normal, + const SGVec3f& v0, + const SGVec3f& vec) +{ + // calculate a vector "u1" representing the shortest distance from + // the plane specified by normal and v0 to a point specified by + // "vec". "u1" represents both the direction and magnitude of + // this desired distance. + + // u1 = ( (normal vec) / (normal normal) ) * normal + SGVec3f u1 = (dot(normal, vec) / dot(normal, normal)) * normal; + + // calculate the vector "v" which is the vector "vec" mapped onto + // the plane specified by "normal" and "v0". + + // v = v0 + vec - u1 + SGVec3f v = v0 + vec - u1; + + // Calculate the vector "result" which is "v" - "v0" which is a + // directional vector pointing from v0 towards v + + // result = v - v0 + return v - v0; +} + // periodic time updater wrapper void fgUpdateLocalTime() { @@ -158,10 +188,9 @@ void fgUpdateSunPos( void ) { // local plane representing "horizontal". // surface direction to go to head towards sun - SGVec3f surface_to_sun; SGVec3f view_pos = toVec3f(v->get_view_pos()); - sgmap_vec_onto_cur_surface_plane( world_up.data(), view_pos.data(), - to_sun.data(), surface_to_sun.data() ); + SGVec3f surface_to_sun = map_vec_onto_cur_surface_plane(world_up, view_pos, to_sun); + surface_to_sun = normalize(surface_to_sun); // cout << "(sg) Surface direction to sun is " // << surface_to_sun[0] << "," From aa16a1e12ab30898f46f9a6e4142db7182376b27 Mon Sep 17 00:00:00 2001 From: "Cutis L. Olson" Date: Fri, 23 Jul 2010 12:37:17 -0500 Subject: [PATCH 6/6] Call the new particle wind setting function with wind direction and speed. The particle wind setting method then takes care of whatever logic and transformations are requred to convert to the proper OSG coordinate system. --- src/Environment/environment_mgr.cxx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Environment/environment_mgr.cxx b/src/Environment/environment_mgr.cxx index 15268f93e..fa23149ec 100644 --- a/src/Environment/environment_mgr.cxx +++ b/src/Environment/environment_mgr.cxx @@ -295,7 +295,9 @@ FGEnvironmentMgr::update (double dt) osg::Vec3 windVec(-_environment->get_wind_from_north_fps(), -_environment->get_wind_from_east_fps(), _environment->get_wind_from_down_fps()); - simgear::Particles::setWindVector(windVec * SG_FEET_TO_METER); + // simgear::Particles::setWindVector(windVec * SG_FEET_TO_METER); + simgear::Particles::setWindFrom( _environment->get_wind_from_heading_deg(), + _environment->get_wind_speed_kt() ); } FGEnvironment