]> git.mxchange.org Git - simgear.git/blob - simgear/route/waypoint.hxx
Roy Vegard Ovesen:
[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., 675 Mass Ave, Cambridge, MA 02139, USA.
23 //
24 // $Id$
25
26
27 #ifndef _WAYPOINT_HXX
28 #define _WAYPOINT_HXX
29
30
31 #ifndef __cplusplus                                                          
32 # error This library requires C++
33 #endif                                   
34
35
36 #include <simgear/compiler.h>
37
38 #include STL_STRING
39
40 SG_USING_STD(string);
41
42
43 /**
44  * A class to manage waypoints.
45  */
46
47 class SGWayPoint {
48
49 public:
50
51     /**
52      * Waypoint mode.
53      * <li> WGS84 requests all bearing and distance math be done assuming a
54      *      WGS84 ellipsoid world.  This is the most expensive computationally,
55      *      but also the most accurate.
56      * <li> SPHERICAL requests all bearing and distance math be done assuming
57      *      the world is a perfect sphere.  This is less compuntationally
58      *      expensive than using wgs84 math and still a fairly good
59      *      approximation of the real world, especially over shorter distances.
60      * <li> CARTESIAN requests all math be done assuming the coordinates specify
61      *      position in a Z = up world.
62      */
63     enum modetype { 
64         WGS84 = 0,
65         SPHERICAL = 1,
66         CARTESIAN = 2
67     };
68
69 private:
70
71     modetype mode;
72
73     double target_lon;
74     double target_lat;
75     double target_alt;
76     double distance;
77
78     string id;
79     string name;
80
81 public:
82
83     /**
84      * Construct a waypoint
85      * @param lon destination longitude
86      * @param lat destination latitude
87      * @param alt target altitude
88      * @param mode type of coordinates/math to use
89      * @param s waypoint identifier
90      * @param n waypoint name
91      */
92     SGWayPoint( const double lon = 0.0, const double lat = 0.0,
93                 const double alt = 0.0, const modetype m = WGS84,
94                 const string s = "", const string n = "" );
95
96     /** Destructor */
97     ~SGWayPoint();
98
99     /**
100      * Calculate course and distances.  For WGS84 and SPHERICAL
101      * coordinates lat, lon, and course are in degrees, alt and
102      * distance are in meters.  For CARTESIAN coordinates x = lon, y =
103      * lat.  Course is in degrees and distance is in what ever units x
104      * and y are in.
105      * @param cur_lon (in) current longitude
106      * @param cur_lat (in) current latitude
107      * @param cur_alt (in) current altitude
108      * @param course (out) heading from current location to this waypoint
109      * @param dist (out) distance from current location to this waypoint
110      */
111     void CourseAndDistance( const double cur_lon, const double cur_lat,
112                             const double cur_alt,
113                             double *course, double *dist ) const;
114
115     /**
116      * Calculate course and distances between a specified starting waypoint
117      * and this waypoint.
118      * @param wp (in) original waypoint
119      * @param course (out) heading from current location to this waypoint
120      * @param dist (out) distance from current location to this waypoint
121      */
122     void CourseAndDistance( const SGWayPoint &wp,
123                             double *course, double *dist ) const;
124
125     /** @return waypoint mode */
126     inline modetype get_mode() const { return mode; }
127
128     /** @return waypoint longitude */
129     inline double get_target_lon() const { return target_lon; }
130
131     /** @return waypoint latitude */
132     inline double get_target_lat() const { return target_lat; }
133
134     /** @return waypoint altitude */
135     inline double get_target_alt() const { return target_alt; }
136
137     /**
138      * This value is not calculated by this class.  It is simply a
139      * placeholder for the user to stash a distance value.  This is useful
140      * when you stack waypoints together into a route.  You can calculate the
141      * distance from the previous waypoint once and save it here.  Adding up
142      * all the distances here plus the distance to the first waypoint gives you
143      * the total route length.  Note, you must update this value yourself, this
144      * is for your convenience only.
145      * @return waypoint distance holder (what ever the user has stashed here)
146      */
147     inline double get_distance() const { return distance; }
148
149     /**
150      * Set the waypoint distance value to a value of our choice.
151      * @param d distance 
152      */
153     inline void set_distance( double d ) { distance = d; }
154
155     /** @return waypoint id */
156     inline string get_id() const { return id; }
157
158     /** @return waypoint name */
159     inline string get_name() const { return name; }
160
161 };
162
163
164 #endif // _WAYPOINT_HXX