X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=simgear%2Froute%2Fwaypoint.cxx;h=f9a9ab0b517cf0526cb480783aeab99468bd072b;hb=6d1d3173fef50d38244a652543dab3e275193533;hp=ec490744128b20ad6ff3fbf3021a7c430dff64e7;hpb=fdc55213894848a7f3dc4b2180a737afb2e1f2b2;p=simgear.git diff --git a/simgear/route/waypoint.cxx b/simgear/route/waypoint.cxx index ec490744..f9a9ab0b 100644 --- a/simgear/route/waypoint.cxx +++ b/simgear/route/waypoint.cxx @@ -16,62 +16,65 @@ // // 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$ +#ifdef HAVE_CONFIG_H +# include +#endif #include #include #include "waypoint.hxx" +using std::string; // Constructor -SGWayPoint::SGWayPoint( const double lon, const double lat, - const modetype m, const string s ) { - target_lon = lon; - target_lat = lat; - mode = m; - id = s; +SGWayPoint::SGWayPoint( const double lon, const double lat, const double alt, + 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() { - SGWayPoint( 0.0, 0.0, WGS84, "" ); +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 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 ) { - if ( mode == WGS84 ) { - double reverse; - geo_inverse_wgs_84( 0.0, 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 ); - 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; - } else if ( mode == CARTESIAN ) { - double dx = target_lon - cur_lon; - double dy = target_lat - cur_lat; - *course = -atan2( dy, dx ) * RAD_TO_DEG - 90; - while ( *course < 0 ) { - *course += 360.0; - } - while ( *course > 360.0 ) { - *course -= 360.0; - } - *distance = sqrt( dx * dx + dy * dy ); - } +// 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 { + 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(), *course, *dist ); }