The "Add Waypoint" dialog should now accept a nav name as well.
To make it work, I used a (dead) code that seemed to be assuming
degree-based geodesic points (whereupon the CVS SG docs claim
that geodesic points are in radians).
(I know that in this case it must be radians because if you pass
degrees there, it doesn't find the VORs :) ).
I'm a bit confused though in general about using geodesic points
in flightgear. In AIManager it says
Point3D pos; // WGS84 lat & lon in degrees, elev above sea-level in meters
(I didn't dive into that code though, but it looks like things are
indeed bound to ..._deg properties).
Please review my patch below in the light of the above caveats
(it works, but I wonder if something needs to be re-written further to
match some uniform usage of geodesic points). It won't hurt applying
AFAIU because the Navaids code I'm touching doesn't seem to be called
at all (according to Doxygen), so please do.
Index: src/Autopilot/auto_gui.cxx
===================================================================
RCS file: /var/cvs/FlightGear-0.9/source/src/Autopilot/auto_gui.cxx,v
retrieving revision 1.12
diff -u -p -r1.12 auto_gui.cxx
--- src/Autopilot/auto_gui.cxx 10 Feb 2005 09:01:51 -0000 1.12
+++ src/Autopilot/auto_gui.cxx 18 Oct 2005 00:40:34 -0000
@@ -51,6 +51,8 @@
#include <Main/globals.hxx>
#include <Main/fg_props.hxx>
#include <Navaids/fixlist.hxx>
+#include <Navaids/navlist.hxx>
+#include <Navaids/navrecord.hxx>
#include "auto_gui.hxx"
#include "route_mgr.hxx"
@@ -691,7 +693,42 @@ int NewWaypoint( string Tgt_Alt )
fgSetString( "/autopilot/locks/heading", "true-heading-hold" );
return 2;
} else {
- return 0;
+ // Try finding a nav matching the ID
+ double lat, lon;
+ // The base lon/lat are determined by the last WP,
+ // or the current pos if the WP list is empty.
+ const int wps = rm->size();
+ if (wps > 0) {
+ SGWayPoint wp = rm->get_waypoint(wps-1);
+ lat = wp.get_target_lat();
+ lon = wp.get_target_lon();
+ }
+ else {
+ lat = fgGetNode("/position/latitude-deg")->getDoubleValue();
+ lon = fgGetNode("/position/longitude-deg")->getDoubleValue();
+ }
+
+ SG_LOG( SG_GENERAL, SG_INFO,
+ "Looking for nav " << TgtAptId << " at " << lon << "
" << lat);
+ if (FGNavRecord* nav =
+ globals->get_navlist()->findByIdent(TgtAptId.c_str(),
lon, lat))
+ {
+ SG_LOG( SG_GENERAL, SG_INFO,
+ "Adding waypoint (nav) = " << TgtAptId );
+
+ sprintf( NewTgtAirportId, "%s", TgtAptId.c_str() );
+
+ SGWayPoint wp( nav->get_lon(), nav->get_lat(), alt,
+ SGWayPoint::WGS84, TgtAptId );
+ rm->add_waypoint( wp );
+
+ /* and turn on the autopilot */
+ fgSetString( "/autopilot/locks/heading", "true-heading-hold"
);
+ return 3;
+ }
+ else {
+ return 0;
+ }
}
}
Index: src/Navaids/navlist.cxx
===================================================================
RCS file: /var/cvs/FlightGear-0.9/source/src/Navaids/navlist.cxx,v
retrieving revision 1.11
diff -u -p -r1.11 navlist.cxx
--- src/Navaids/navlist.cxx 1 Oct 2005 09:56:53 -0000 1.11
+++ src/Navaids/navlist.cxx 18 Oct 2005 00:40:40 -0000
@@ -150,7 +150,7 @@ bool FGTACANList::add( FGTACANRecord *c
FGNavRecord *FGNavList::findByFreq( double freq, double lon, double lat,
double elev )
{
nav_list_type stations = navaids[(int)(freq*100.0 + 0.5)];
- Point3D aircraft = sgGeodToCart( Point3D(lon, lat, elev) );
+ Point3D aircraft = sgGeodToCart( Point3D(lon * SG_DEGREES_TO_RADIANS, lat
* SG_DEGREES_TO_RADIANS, elev) );
SG_LOG( SG_INSTR, SG_DEBUG, "findbyFreq " << freq << " size " <<
stations.size() );
return findNavFromList( aircraft, stations );
@@ -161,7 +161,7 @@ FGNavRecord *FGNavList::findByIdent( con
const double lon, const double lat )
{
nav_list_type stations = ident_navaids[ident];
- Point3D aircraft = sgGeodToCart( Point3D(lon, lat, 0.0) );
+ Point3D aircraft = sgGeodToCart( Point3D(lon * SG_DEGREES_TO_RADIANS, lat
* SG_DEGREES_TO_RADIANS, 0.0) );
return findNavFromList( aircraft, stations );
}
_______________________________________________
Flightgear-devel mailing list
[email protected]
http://mail.flightgear.org/mailman/listinfo/flightgear-devel
2f585eeea02e2c79d7b1d8c4963bae2d