fgms 0.11.8
The
FlightGear MultiPlayer Server
project
fg_geometry.hxx
Go to the documentation of this file.
1 //
2 // This program is free software; you can redistribute it and/or
3 // modify it under the terms of the GNU General Public License as
4 // published by the Free Software Foundation; either version 2 of the
5 // License, or (at your option) any later version.
6 //
7 // This program is distributed in the hope that it will be useful, but
8 // WITHOUT ANY WARRANTY; without even the implied warranty of
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10 // General Public License for more details.
11 //
12 // You should have received a copy of the GNU General Public License
13 // along with this program; if not, write to the Free Software
14 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, U$
15 //
16 
17 //////////////////////////////////////////////////////////////////////
18 //
19 // Server for FlightGear, geometry functions
20 // taken from simgear and other sources
21 //
22 //////////////////////////////////////////////////////////////////////
23 
24 #if !defined FG_GEOMETRY_H
25 #define FG_GEOMETRY_H
26 
27 #include <simgear/math/SGMath.hxx>
28 
29 #define SG_180 180.0
30 #define SG_PI 3.1415926535
31 #define SG_RADIANS_TO_DEGREES (SG_180/SG_PI)
32 #define SG_DEGREES_TO_RADIANS (SG_PI/SG_180)
33 #define SG_FEET_TO_METER 0.3048
34 
35 typedef double t_Point3D;
36 
37 enum { X, Y, Z };
38 enum { Lat, Lon, Alt };
39 
40 class Point3D
41 {
42  public:
43  Point3D();
44  Point3D ( const Point3D& P );
45  Point3D ( const t_Point3D& X, const t_Point3D& Y, const t_Point3D& Z );
46  t_Point3D GetX () { return m_X; };
47  t_Point3D GetY () { return m_Y; };
48  t_Point3D GetZ () { return m_Z; };
49  void SetX ( const t_Point3D& nV ) { m_X = nV; };
50  void SetY ( const t_Point3D& nV ) { m_Y = nV; };
51  void SetZ ( const t_Point3D& nV ) { m_Z = nV; };
52  void Set ( const t_Point3D& X, const t_Point3D& Y, const t_Point3D& Z );
53  void CartToPolar();
54  void PolarToCart();
55  //////////////////////////////////////////////////
56  // operators
57  //////////////////////////////////////////////////
58  void operator = ( const Point3D& P );
59  void operator = ( const sgdVec3& P );
60  void operator += ( const Point3D& P );
61  void operator -= ( const Point3D& P );
62  void operator *= ( const Point3D& P );
63  void operator /= ( const Point3D& P );
64  void operator ^= ( const Point3D& P );
65  void operator *= ( const t_Point3D& nV );
66  void operator /= ( const t_Point3D& nV );
67  bool operator == ( const Point3D& P );
68  bool operator != ( const Point3D& P );
69  t_Point3D operator[] ( const int Index ) const;
70  t_Point3D& operator[] ( const int Index );
71  friend Point3D operator + ( const Point3D& P1, const Point3D& P2 );
72  friend Point3D operator - ( const Point3D& P1, const Point3D& P2 );
73  friend Point3D operator * ( const Point3D& P1, const Point3D& P2 );
74  friend Point3D operator / ( const Point3D& P1, const Point3D& P2 );
75  friend Point3D operator ^ ( const Point3D& P1, const Point3D& P2 );
76  friend Point3D operator * ( const t_Point3D& nV, const Point3D& P1 );
77  friend Point3D operator / ( const t_Point3D& nV, const Point3D& P1 );
78  //////////////////////////////////////////////////
79  // others
80  //////////////////////////////////////////////////
81  t_Point3D length () const;
82  friend t_Point3D length ( const Point3D& P );
83  void normalize ();
84  friend Point3D normalize ( const Point3D& P );
85  t_Point3D sqr ();
86  friend t_Point3D sqr ( const Point3D& P );
87  void invert ();
88  friend Point3D invert (const Point3D& P );
89  void clear ();
90 
91  private:
95 }; // class Point3D
96 
97 void CopyPos ( const Point3D& src, Point3D &dst );
98 void Mat4ToCoord ( const sgMat4& src, Point3D & dst );
99 float Distance ( const Point3D & P1, const Point3D & P2 );
100 void sgCartToPolar3d(const Point3D& cp, Point3D& Polar );
101 void CartToLatLon ( const Point3D& CartPoint , Point3D& LatLonAlt );
102 double
103 calc_gc_dist ( const Point3D& start, const Point3D& dest );
104 
105 bool IsWithinRMiles ( double lat1, double lon1, double lat2, double lon2,
106  double R );
107 
108 void sgCartToGeod ( const Point3D& CartPoint , Point3D& GeodPoint );
109 void sgGeodToCart(double lat, double lon, double alt, double* xyz);
110 
111 #endif
112 
t_Point3D sqr()
t_Point3D m_Y
Definition: fg_geometry.hxx:93
float Distance(const Point3D &P1, const Point3D &P2)
Calculate distance of clients.
void CartToLatLon(const Point3D &CartPoint, Point3D &LatLonAlt)
t_Point3D GetY()
Definition: fg_geometry.hxx:47
void operator*=(const Point3D &P)
bool operator!=(const Point3D &P)
friend Point3D operator*(const Point3D &P1, const Point3D &P2)
void SetY(const t_Point3D &nV)
Definition: fg_geometry.hxx:50
void CopyPos(const Point3D &src, Point3D &dst)
void sgGeodToCart(double lat, double lon, double alt, double *xyz)
Opposite of sgCartToGeod.
void sgCartToPolar3d(const Point3D &cp, Point3D &Polar)
friend Point3D operator/(const Point3D &P1, const Point3D &P2)
void operator=(const Point3D &P)
t_Point3D operator[](const int Index) const
t_Point3D length() const
void operator-=(const Point3D &P)
bool operator==(const Point3D &P)
friend Point3D operator^(const Point3D &P1, const Point3D &P2)
void operator^=(const Point3D &P)
double sgdVec3[3]
Definition: SGMath.hxx:8
float sgMat4[4][4]
Definition: SGMath.hxx:9
static char P[]
Definition: crypt-win.c:209
void SetX(const t_Point3D &nV)
Definition: fg_geometry.hxx:49
void PolarToCart()
Definition: fg_geometry.cxx:96
friend Point3D operator-(const Point3D &P1, const Point3D &P2)
bool IsWithinRMiles(double lat1, double lon1, double lat2, double lon2, double R)
void clear()
void Mat4ToCoord(const sgMat4 &src, Point3D &dst)
t_Point3D m_X
Definition: fg_geometry.hxx:92
t_Point3D m_Z
Definition: fg_geometry.hxx:94
void operator+=(const Point3D &P)
t_Point3D GetZ()
Definition: fg_geometry.hxx:48
void sgCartToGeod(const Point3D &CartPoint, Point3D &GeodPoint)
Convert a cartexian XYZ coordinate to a geodetic lat/lon/alt. This function is a copy of what's in Si...
static char R[32]
Definition: crypt-win.c:223
friend Point3D operator+(const Point3D &P1, const Point3D &P2)
void normalize()
void CartToPolar()
Definition: fg_geometry.cxx:83
void operator/=(const Point3D &P)
double t_Point3D
Definition: fg_geometry.hxx:35
void Set(const t_Point3D &X, const t_Point3D &Y, const t_Point3D &Z)
Definition: fg_geometry.cxx:74
t_Point3D GetX()
Definition: fg_geometry.hxx:46
void SetZ(const t_Point3D &nV)
Definition: fg_geometry.hxx:51
double calc_gc_dist(const Point3D &start, const Point3D &dest)
void invert()