]> git.mxchange.org Git - simgear.git/blob - simgear/timing/geocoord.h
Manage OSG object cache explicitly
[simgear.git] / simgear / timing / geocoord.h
1 /* -*- Mode: C++ -*- *****************************************************
2  * geocoord.h
3  * Written by Durk Talsma. Started July 1999.
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Library General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Library General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
18  *
19  **************************************************************************/
20
21 /*************************************************************************
22  *
23  * This file defines a small and simple class to store geocentric 
24  * coordinates. Basically, class GeoCoord is intended as a base class for
25  * any kind of of object, that can be categorized according to its 
26  * location on earth, be it navaids, or aircraft. This class for originally
27  * written for FlightGear, in order to store Timezone control points. 
28  *
29  ************************************************************************/
30
31
32 #ifndef _GEOCOORD_H_
33 #define _GEOCOORD_H_
34
35 #include <simgear/compiler.h>
36
37
38 #include <math.h>
39 #include <vector>
40
41 SG_USING_NAMESPACE(std);
42
43 #include <simgear/constants.h>
44
45 class SGGeoCoord
46 {
47 protected:
48   float lat;
49   float lon;
50
51 public:
52   SGGeoCoord() { lat = 0.0; lon = 0.0;};
53   SGGeoCoord(float la, float lo) { lat = la; lon = lo;};
54   SGGeoCoord(const SGGeoCoord& other);
55   virtual ~SGGeoCoord() {};
56   
57   void set(float la, float lo) { lat = la; lon = lo; }; 
58   float getLat() const { return lat; };
59   float getLon() const { return lon; };
60   float getX()   const { return cos(SGD_DEGREES_TO_RADIANS*lat) * cos(SGD_DEGREES_TO_RADIANS*lon); };
61   float getY()   const { return cos(SGD_DEGREES_TO_RADIANS*lat) * sin(SGD_DEGREES_TO_RADIANS*lon); };
62   float getZ()   const { return sin(SGD_DEGREES_TO_RADIANS*lat); };
63
64
65   virtual const char * getDescription() {return 0;};
66 };
67
68 typedef vector<SGGeoCoord*> SGGeoCoordVector;
69 typedef vector<SGGeoCoord*>::iterator SGGeoCoordVectorIterator;
70 typedef vector<SGGeoCoord*>::const_iterator SGGeoCoordVectorConstIterator;
71
72 /************************************************************************
73  * SGGeoCoordContainer is a simple container class, that stores objects
74  * derived from SGGeoCoord. Basically, it is a wrapper around an STL vector,
75  * with some added functionality
76  ***********************************************************************/
77
78 class SGGeoCoordContainer
79 {
80 protected:
81   SGGeoCoordVector data;
82
83 public:
84   SGGeoCoordContainer() {};
85   virtual ~SGGeoCoordContainer();
86
87   const SGGeoCoordVector& getData() const { return data; };
88   SGGeoCoord* getNearest(const SGGeoCoord& ref) const;
89 };
90
91
92 #endif // _GEO_COORD_H_