]> git.mxchange.org Git - simgear.git/blobdiff - simgear/route/waypoint.cxx
Update the code a bit more, add a function to retreive the last error string and...
[simgear.git] / simgear / route / waypoint.cxx
index ec490744128b20ad6ff3fbf3021a7c430dff64e7..3de5941d399a9ec60737d776adfd009ff7e75bc1 100644 (file)
 
 
 // Constructor
-SGWayPoint::SGWayPoint( const double lon, const double lat,
-                       const modetype m, const string s ) {
+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;
-}
-
-
-SGWayPoint::SGWayPoint() {
-    SGWayPoint( 0.0, 0.0, WGS84, "" );
+    name = n;
 }
 
 
@@ -48,30 +45,41 @@ SGWayPoint::~SGWayPoint() {
 
 
 // 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,
-                                   double *course, double *distance ) {
+// 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 *dist ) const {
     if ( mode == WGS84 ) {
        double reverse;
-       geo_inverse_wgs_84( 0.0, cur_lat, cur_lon, target_lat, target_lon,
-                           course, &reverse, distance );
+       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 * DEG_TO_RAD, cur_lat * DEG_TO_RAD, 0.0 );
-       Point3D target( target_lon * DEG_TO_RAD, target_lat * DEG_TO_RAD, 0.0 );
-       calc_gc_course_dist( current, target, course, distance );
-       *course = 360.0 - *course * RAD_TO_DEG;
+       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 ) * RAD_TO_DEG - 90;
+       *course = -atan2( dy, dx ) * SGD_RADIANS_TO_DEGREES - 90;
        while ( *course < 0 ) {
            *course += 360.0;
        }
        while ( *course > 360.0 ) {
            *course -= 360.0;
        }
-       *distance = sqrt( dx * dx + dy * dy );
+       *dist = sqrt( dx * dx + dy * dy );
     }
 }
+
+// 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 );
+}