lib_LIBRARIES = libsgroute.a
-include_HEADERS = waypoint.hxx
+include_HEADERS = route.hxx waypoint.hxx
libsgroute_a_SOURCES = \
+ route.cxx \
waypoint.cxx
INCLUDES += -I$(top_srcdir)
--- /dev/null
+// route.cxx -- Class to manage a list of waypoints (route)
+//
+// Written by Curtis Olson, started October 2000.
+//
+// Copyright (C) 2000 Curtis L. Olson - curt@hfrl.umn.edu
+//
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of the GNU General Public License as
+// published by the Free Software Foundation; either version 2 of the
+// License, or (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful, but
+// WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// 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.
+//
+// $Id$
+
+
+#include "route.hxx"
+
+
+// constructor
+SGRoute::SGRoute() {
+ route.clear();
+}
+
+
+// destructor
+SGRoute::~SGRoute() {
+}
--- /dev/null
+// route.hxx -- Class to manage a list of waypoints (route)
+//
+// Written by Curtis Olson, started October 2000.
+//
+// Copyright (C) 2000 Curtis L. Olson - curt@hfrl.umn.edu
+//
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of the GNU General Public License as
+// published by the Free Software Foundation; either version 2 of the
+// License, or (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful, but
+// WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// 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.
+//
+// $Id$
+
+
+#ifndef _ROUTE_HXX
+#define _ROUTE_HXX
+
+
+#ifndef __cplusplus
+# error This library requires C++
+#endif
+
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <simgear/compiler.h>
+
+#include STL_STRING
+#include <vector>
+
+FG_USING_STD(string);
+FG_USING_STD(vector);
+
+#include "waypoint.hxx"
+
+
+class SGRoute {
+
+private:
+
+ typedef vector < SGWayPoint > route_list;
+ route_list route;
+ int current_wp;
+
+public:
+
+ SGRoute();
+ ~SGRoute();
+
+ // clear the entire route
+ inline void clear() {
+ route.clear();
+ current_wp = 0;
+ }
+
+ // add a waypoint
+ inline void add_waypoint( const SGWayPoint &wp ) {
+ route.push_back( wp );
+ }
+
+ // get the number of waypoints
+ inline int size() const { return route.size(); }
+
+ // get the front waypoint
+ inline SGWayPoint get_first() const {
+ if ( route.size() ) {
+ return route[0];
+ } else {
+ return SGWayPoint( 0.0, 0.0, 0.0, SGWayPoint::WGS84, "invalid" );
+ }
+ }
+
+ // get the current waypoint
+ inline SGWayPoint get_current() const {
+ if ( current_wp < (int)route.size() ) {
+ return route[current_wp];
+ } else {
+ return SGWayPoint( 0.0, 0.0, 0.0, SGWayPoint::WGS84, "invalid" );
+ }
+ }
+
+ // set the current waypoint
+ inline void set_current( int n ) {
+ if ( n >= 0 && n < (int)route.size() ) {
+ current_wp = n;
+ }
+ }
+
+ // increment the current waypoint
+ inline void increment_current() {
+ if ( current_wp < (int)route.size() - 1 ) {
+ ++current_wp;
+ }
+ }
+
+ // get the nth waypoint
+ inline SGWayPoint get_waypoint( const int n ) const {
+ if ( n < (int)route.size() ) {
+ return route[n];
+ } else {
+ return SGWayPoint( 0.0, 0.0, 0.0, SGWayPoint::WGS84, "invalid" );
+ }
+ }
+
+ // delete the front waypoint
+ inline void delete_first() {
+ if ( route.size() ) {
+ route.erase( route.begin() );
+ }
+ }
+};
+
+
+#endif // _ROUTE_HXX
// Constructor
-SGWayPoint::SGWayPoint( const double lon, const double lat,
+SGWayPoint::SGWayPoint( const double lon, const double lat, const double alt,
const modetype m, const string s ) {
target_lon = lon;
target_lat = lat;
+ target_alt = alt;
mode = m;
id = s;
}
SGWayPoint::SGWayPoint() {
- SGWayPoint( 0.0, 0.0, WGS84, "" );
+ SGWayPoint( 0.0, 0.0, 0.0, WGS84, "" );
}
// Calculate course and distances. For WGS84 and SPHERICAL
-// coordinates lat, lon, and course are in degrees and distance in
-// meters. For CARTESIAN coordinates x = lon, y = lat. Course is in
-// degrees and distance is in what ever units x and y are in.
-void SGWayPoint::CourseAndDistance( const double cur_lon, const double cur_lat,
+// coordinates lat, lon, and course are in degrees, alt and distance
+// are in meters. For CARTESIAN coordinates x = lon, y = lat. Course
+// is in degrees and distance is in what ever units x and y are in.
+void SGWayPoint::CourseAndDistance( const double cur_lon,
+ const double cur_lat,
+ const double cur_alt,
double *course, double *distance ) {
if ( mode == WGS84 ) {
double reverse;
- geo_inverse_wgs_84( 0.0, cur_lat, cur_lon, target_lat, target_lon,
+ geo_inverse_wgs_84( cur_alt, cur_lat, cur_lon, target_lat, target_lon,
course, &reverse, distance );
} else if ( mode == SPHERICAL ) {
Point3D current( cur_lon * DEG_TO_RAD, cur_lat * DEG_TO_RAD, 0.0 );
double target_lon;
double target_lat;
+ double target_alt;
string id;
public:
SGWayPoint();
- SGWayPoint( const double lon, const double lat,
+ SGWayPoint( const double lon, const double lat, const double alt,
const modetype m = WGS84, const string s = "" );
~SGWayPoint();
- // Calculate course and distances. Lat, lon, and azimuth are in
- // degrees. distance in meters
+ // Calculate course and distances. For WGS84 and SPHERICAL
+ // coordinates lat, lon, and course are in degrees, alt and
+ // distance are in meters. For CARTESIAN coordinates x = lon, y =
+ // lat. Course is in degrees and distance is in what ever units x
+ // and y are in.
void CourseAndDistance( const double cur_lon, const double cur_lat,
+ const double cur_alt,
double *course, double *distance );
inline modetype get_mode() const { return mode; }
inline double get_target_lon() const { return target_lon; }
inline double get_target_lat() const { return target_lat; }
+ inline double get_target_alt() const { return target_alt; }
inline string get_id() const { return id; }
};
#include "waypoint.hxx"
int main() {
- SGWayPoint a1(-93.216923, 44.880547, SGWayPoint::WGS84, "KMSP");
- SGWayPoint a2(-93.216923, 44.880547, SGWayPoint::SPHERICAL, "KMSP");
+ SGWayPoint a1(-93.216923, 44.880547, 0.0, SGWayPoint::WGS84, "KMSP");
+ SGWayPoint a2(-93.216923, 44.880547, 0.0, SGWayPoint::SPHERICAL, "KMSP");
// KMSN (Madison)
double cur_lon = -89.336939;
double cur_lat = 43.139541;
+ double cur_alt = 0.0;
double course, distance;
- a1.CourseAndDistance( cur_lon, cur_lat, &course, &distance );
+ a1.CourseAndDistance( cur_lon, cur_lat, cur_alt, &course, &distance );
cout << "Course to " << a1.get_id() << " is " << course << endl;
cout << "Distance to " << a1.get_id() << " is " << distance * METER_TO_NM
<< endl;
- a2.CourseAndDistance( cur_lon, cur_lat, &course, &distance );
+ a2.CourseAndDistance( cur_lon, cur_lat, cur_alt, &course, &distance );
cout << "Course to " << a2.get_id() << " is " << course << endl;
cout << "Distance to " << a2.get_id() << " is " << distance * METER_TO_NM
<< endl;
cout << endl;
- SGWayPoint b1(-88.237037, 43.041038, SGWayPoint::WGS84, "KUES");
- SGWayPoint b2(-88.237037, 43.041038, SGWayPoint::SPHERICAL, "KUES");
+ SGWayPoint b1(-88.237037, 43.041038, 0.0, SGWayPoint::WGS84, "KUES");
+ SGWayPoint b2(-88.237037, 43.041038, 0.0, SGWayPoint::SPHERICAL, "KUES");
- b1.CourseAndDistance( cur_lon, cur_lat, &course, &distance );
+ b1.CourseAndDistance( cur_lon, cur_lat, cur_alt, &course, &distance );
cout << "Course to " << b1.get_id() << " is " << course << endl;
cout << "Distance to " << b1.get_id() << " is " << distance * METER_TO_NM
<< endl;
- b2.CourseAndDistance( cur_lon, cur_lat, &course, &distance );
+ b2.CourseAndDistance( cur_lon, cur_lat, cur_alt, &course, &distance );
cout << "Course to " << b2.get_id() << " is " << course << endl;
cout << "Distance to " << b2.get_id() << " is " << distance * METER_TO_NM
<< endl;
cur_lon = 10;
cur_lat = 10;
- SGWayPoint c1(-20, 10, SGWayPoint::CARTESIAN, "Due East");
- c1.CourseAndDistance( cur_lon, cur_lat, &course, &distance );
+ SGWayPoint c1(-20, 10, 0, SGWayPoint::CARTESIAN, "Due East");
+ c1.CourseAndDistance( cur_lon, cur_lat, cur_alt, &course, &distance );
cout << "Course to " << c1.get_id() << " is " << course << endl;
cout << "Distance to " << c1.get_id() << " is " << distance << endl;
- SGWayPoint c2(20, 20, SGWayPoint::CARTESIAN, "Due SW");
- c2.CourseAndDistance( cur_lon, cur_lat, &course, &distance );
+ SGWayPoint c2(20, 20, 0, SGWayPoint::CARTESIAN, "Due SW");
+ c2.CourseAndDistance( cur_lon, cur_lat, cur_alt, &course, &distance );
cout << "Course to " << c2.get_id() << " is " << course << endl;
cout << "Distance to " << c2.get_id() << " is " << distance << endl;
- SGWayPoint c3(20, 0, SGWayPoint::CARTESIAN, "Due NW");
- c3.CourseAndDistance( cur_lon, cur_lat, &course, &distance );
+ SGWayPoint c3(20, 0, 0, SGWayPoint::CARTESIAN, "Due NW");
+ c3.CourseAndDistance( cur_lon, cur_lat, cur_alt, &course, &distance );
cout << "Course to " << c3.get_id() << " is " << course << endl;
cout << "Distance to " << c3.get_id() << " is " << distance << endl;