]> git.mxchange.org Git - simgear.git/blob - simgear/route/waypoint.hxx
29edf7397c24e44a184c76d8bbd5da378ed1f49a
[simgear.git] / simgear / route / waypoint.hxx
1 /** 
2  * \file waypoint.hxx
3  * Provides a class to manage waypoints
4  */
5
6 // Written by Curtis Olson, started September 2000.
7 //
8 // Copyright (C) 2000  Curtis L. Olson  - curt@hfrl.umn.edu
9 //
10 // This program is free software; you can redistribute it and/or
11 // modify it under the terms of the GNU General Public License as
12 // published by the Free Software Foundation; either version 2 of the
13 // License, or (at your option) any later version.
14 //
15 // This program is distributed in the hope that it will be useful, but
16 // WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18 // General Public License for more details.
19 //
20 // You should have received a copy of the GNU General Public License
21 // along with this program; if not, write to the Free Software
22 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
23 //
24 // $Id$
25
26
27 #ifndef _WAYPOINT_HXX
28 #define _WAYPOINT_HXX
29
30 #include <simgear/compiler.h>
31
32 #include <simgear/math/SGMath.hxx>
33 #include <simgear/math/SGGeod.hxx>
34
35 #include <string>
36
37
38 /**
39  * A class to manage waypoints.
40  */
41
42 class SGWayPoint {
43
44 public:
45
46     /**
47      * Waypoint mode.
48      * <li> WGS84 requests all bearing and distance math be done assuming a
49      *      WGS84 ellipsoid world.  This is the most expensive computationally,
50      *      but also the most accurate.
51      * <li> SPHERICAL requests all bearing and distance math be done assuming
52      *      the world is a perfect sphere.  This is less compuntationally
53      *      expensive than using wgs84 math and still a fairly good
54      *      approximation of the real world, especially over shorter distances.
55      */
56     enum modetype { 
57         WGS84 = 0,
58     };
59
60 private:
61     SGGeod pos;
62     std::string id;
63     std::string name;
64     
65   // route data associated with the waypoint
66     double _distance;
67     double _track;
68     double _speed;
69     
70 public:
71
72     /**
73      * Construct a waypoint
74      * @param lon destination longitude
75      * @param lat destination latitude
76      * @param alt target altitude
77      * @param mode type of coordinates/math to use
78      * @param s waypoint identifier
79      * @param n waypoint name
80      */
81     SGWayPoint( const double lon = 0.0, const double lat = 0.0,
82                 const double alt = 0.0, const modetype m = WGS84,
83                 const std::string& s = "", const std::string& n = "" );
84   
85     /**
86      * Construct from a geodetic position, in WGS84 coordinates
87      */
88     SGWayPoint(const SGGeod& pos, const std::string& s, const std::string& n);
89
90     /** Destructor */
91     ~SGWayPoint();
92
93     /**
94      * Calculate course and distances.  For WGS84 and SPHERICAL
95      * coordinates lat, lon, and course are in degrees, alt and
96      * distance are in meters.  For CARTESIAN coordinates x = lon, y =
97      * lat.  Course is in degrees and distance is in what ever units x
98      * and y are in.
99      * @param cur_lon (in) current longitude
100      * @param cur_lat (in) current latitude
101      * @param cur_alt (in) current altitude
102      * @param course (out) heading from current location to this waypoint
103      * @param dist (out) distance from current location to this waypoint
104      */
105     void CourseAndDistance( const double cur_lon, const double cur_lat,
106                             const double cur_alt,
107                             double *course, double *dist ) const;
108
109     void CourseAndDistance(const SGGeod& current,
110                             double& course, double& dist ) const;
111
112     /**
113      * Calculate course and distances between a specified starting waypoint
114      * and this waypoint.
115      * @param wp (in) original waypoint
116      * @param course (out) heading from current location to this waypoint
117      * @param dist (out) distance from current location to this waypoint
118      */
119     void CourseAndDistance( const SGWayPoint &wp,
120                             double *course, double *dist ) const;
121
122     /** @return waypoint longitude */
123     inline double get_target_lon() const { return pos.getLongitudeDeg(); }
124
125     /** @return waypoint latitude */
126     inline double get_target_lat() const { return pos.getLatitudeDeg(); }
127
128     /** @return waypoint altitude */
129     inline double get_target_alt() const { return pos.getElevationM(); }
130
131     inline const SGGeod& get_target() const { return pos; }
132
133     /**
134      * This value is not calculated by this class.  It is simply a
135      * placeholder for the user to stash a distance value.  This is useful
136      * when you stack waypoints together into a route.  You can calculate the
137      * distance from the previous waypoint once and save it here.  Adding up
138      * all the distances here plus the distance to the first waypoint gives you
139      * the total route length.  Note, you must update this value yourself, this
140      * is for your convenience only.
141      * @return waypoint distance holder (what ever the user has stashed here)
142      */
143     inline double get_distance() const { return _distance; }
144
145     /**
146      * Set the waypoint distance value to a value of our choice.
147      * @param d distance 
148      */
149     inline void set_distance( double d ) { _distance = d; }
150
151     inline double get_track() const { return _track; }
152     inline void set_track(double t) { _track = t; }
153
154     inline double get_speed() const { return _speed; }
155     inline void set_speed(double v) { _speed = v; }
156     
157     /** @return waypoint id */
158     inline const std::string& get_id() const { return id; }
159
160     /** @return waypoint name */
161     inline const std::string& get_name() const { return name; }
162
163 };
164
165
166 #endif // _WAYPOINT_HXX