From cd5765be1eb35f0608605de7a24f70a7bf5d0ba9 Mon Sep 17 00:00:00 2001 From: curt Date: Fri, 13 Oct 2000 21:32:51 +0000 Subject: [PATCH] Tweaks to waypoints and routing. Added distance_to field for each waypoint. --- simgear/route/route.hxx | 8 ++++++++ simgear/route/waypoint.cxx | 11 ++++++++++- simgear/route/waypoint.hxx | 10 +++++++++- 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/simgear/route/route.hxx b/simgear/route/route.hxx index 7ba46010..ead338d4 100644 --- a/simgear/route/route.hxx +++ b/simgear/route/route.hxx @@ -67,6 +67,14 @@ public: // add a waypoint inline void add_waypoint( const SGWayPoint &wp ) { route.push_back( wp ); + + int size = route.size(); + if ( size > 1 ) { + SGWayPoint next_to_last = route[ size - 2 ]; + double tmpd, tmpc; + wp.CourseAndDistance( next_to_last, &tmpc, &tmpd ); + route[size - 1].set_distance( tmpd ); + } } // get the number of waypoints diff --git a/simgear/route/waypoint.cxx b/simgear/route/waypoint.cxx index 50807ea9..316b70b3 100644 --- a/simgear/route/waypoint.cxx +++ b/simgear/route/waypoint.cxx @@ -55,7 +55,7 @@ SGWayPoint::~SGWayPoint() { void SGWayPoint::CourseAndDistance( const double cur_lon, const double cur_lat, const double cur_alt, - double *course, double *distance ) { + double *course, double *distance ) const { if ( mode == WGS84 ) { double reverse; geo_inverse_wgs_84( cur_alt, cur_lat, cur_lon, target_lat, target_lon, @@ -78,3 +78,12 @@ void SGWayPoint::CourseAndDistance( const double cur_lon, *distance = sqrt( dx * dx + dy * dy ); } } + +// Calculate course and distances between two waypoints +void SGWayPoint::CourseAndDistance( const SGWayPoint &wp, + double *course, double *distance ) const { + CourseAndDistance( wp.get_target_lon(), + wp.get_target_lat(), + wp.get_target_alt(), + course, distance ); +} diff --git a/simgear/route/waypoint.hxx b/simgear/route/waypoint.hxx index 913a6b6b..4f66f89f 100644 --- a/simgear/route/waypoint.hxx +++ b/simgear/route/waypoint.hxx @@ -58,6 +58,7 @@ private: double target_lon; double target_lat; double target_alt; + double distance; string id; @@ -75,13 +76,20 @@ public: // and y are in. void CourseAndDistance( const double cur_lon, const double cur_lat, const double cur_alt, - double *course, double *distance ); + double *course, double *distance ) const; + + // Calculate course and distances between two waypoints + void CourseAndDistance( const SGWayPoint &wp, + double *course, double *distance ) const; 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 double get_distance() const { return distance; } inline string get_id() const { return id; } + + inline void set_distance( double d ) { distance = d; } }; -- 2.39.5