X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=simgear%2Froute%2Fwaypoint.cxx;h=73669037e0f82d7d2fdb730ef1c5d54663e052c5;hb=7bdb530440d1dadc991f305edb1b70ec85f27451;hp=47487f0b72e7e601142a6aaad2f956edc2b8ffe5;hpb=1b51de08f5a5e415ae47fdaa48832c852d810d91;p=simgear.git diff --git a/simgear/route/waypoint.cxx b/simgear/route/waypoint.cxx index 47487f0b..73669037 100644 --- a/simgear/route/waypoint.cxx +++ b/simgear/route/waypoint.cxx @@ -16,7 +16,7 @@ // // 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. +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. // // $Id$ @@ -24,28 +24,42 @@ # include #endif -#include #include #include "waypoint.hxx" +using std::string; // Constructor SGWayPoint::SGWayPoint( const double lon, const double lat, const double alt, - const modetype m, const string s, const string n ) { - target_lon = lon; - target_lat = lat; - target_alt = alt; - mode = m; - id = s; - name = n; + const modetype, const string& s, const string& n ) : + pos(SGGeod::fromDegM(lon, lat, alt)), + id(s), + name(n), + _distance(0.0), + _track(0.0), + _speed(0.0) +{ } +SGWayPoint::SGWayPoint(const SGGeod& geod, const string& s, const string& n ) : + pos(geod), + id(s), + name(n), + _distance(0.0), + _track(0.0), + _speed(0.0) +{ +} // Destructor SGWayPoint::~SGWayPoint() { } +void SGWayPoint::CourseAndDistance(const SGGeod& cur, double& course, double& dist ) const { + double reverse; + SGGeodesy::inverse(cur, pos, course, reverse, dist); +} // Calculate course and distances. For WGS84 and SPHERICAL // coordinates lat, lon, and course are in degrees, alt and distance @@ -55,34 +69,11 @@ void SGWayPoint::CourseAndDistance( const double cur_lon, const double cur_lat, const double cur_alt, double *course, double *dist ) const { - if ( mode == WGS84 ) { - double reverse; - geo_inverse_wgs_84( cur_alt, cur_lat, cur_lon, target_lat, target_lon, - course, &reverse, dist ); - } else if ( mode == SPHERICAL ) { - Point3D current( cur_lon * SGD_DEGREES_TO_RADIANS, cur_lat * SGD_DEGREES_TO_RADIANS, 0.0 ); - Point3D target( target_lon * SGD_DEGREES_TO_RADIANS, target_lat * SGD_DEGREES_TO_RADIANS, 0.0 ); - calc_gc_course_dist( current, target, course, dist ); - *course = 360.0 - *course * SGD_RADIANS_TO_DEGREES; - } else if ( mode == CARTESIAN ) { - double dx = target_lon - cur_lon; - double dy = target_lat - cur_lat; - *course = -atan2( dy, dx ) * SGD_RADIANS_TO_DEGREES - 90; - while ( *course < 0 ) { - *course += 360.0; - } - while ( *course > 360.0 ) { - *course -= 360.0; - } - *dist = sqrt( dx * dx + dy * dy ); - } + CourseAndDistance(SGGeod::fromDegM(cur_lon, cur_lat, cur_alt), *course, *dist); } // Calculate course and distances between two waypoints void SGWayPoint::CourseAndDistance( const SGWayPoint &wp, double *course, double *dist ) const { - CourseAndDistance( wp.get_target_lon(), - wp.get_target_lat(), - wp.get_target_alt(), - course, dist ); + CourseAndDistance( wp.get_target(), *course, *dist ); }