]> git.mxchange.org Git - flightgear.git/blob - src/AIModel/AIBase.hxx
Use some C++ FOOmagic to get the lat and lon updated in the property tree properly
[flightgear.git] / src / AIModel / AIBase.hxx
1 // FGAIBase - abstract base class for AI objects
2 // Written by David Culp, started Nov 2003, based on
3 // David Luff's FGAIEntity class.
4 // - davidculp2@comcast.net
5 //
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License as
8 // published by the Free Software Foundation; either version 2 of the
9 // License, or (at your option) any later version.
10 //
11 // This program is distributed in the hope that it will be useful, but
12 // WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software
18 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19
20 #ifndef _FG_AIBASE_HXX
21 #define _FG_AIBASE_HXX
22
23 #include <simgear/constants.h>
24 #include <simgear/math/point3d.hxx>
25 #include <simgear/scene/model/placement.hxx>
26 #include <string>
27
28 SG_USING_STD(string);
29
30 class FGAIBase {
31
32 private:
33
34     static FGAIBase *_self;
35
36 public:
37
38     FGAIBase();
39     virtual ~FGAIBase();
40     virtual void update(double dt);
41     inline Point3D GetPos() { return(pos); }
42
43     virtual bool init();
44     virtual void bind();
45     virtual void unbind();
46
47     void setPath( const char* model );
48     void setSpeed( double speed_KTAS );
49     void setAltitude( double altitude_ft );
50     void setHeading( double heading );
51     void setLatitude( double latitude );
52     void setLongitude( double longitude );
53
54     void setDie( bool die );
55     bool getDie();
56
57 protected:
58
59     SGPropertyNode *props;
60
61     Point3D pos;        // WGS84 lat & lon in degrees, elev above sea-level in meters
62     double hdg;         // True heading in degrees
63     double roll;        // degrees, left is negative
64     double pitch;       // degrees, nose-down is negative
65     double speed;       // knots true airspeed
66     double altitude;    // meters above sea level
67     double vs;           // vertical speed, feet per minute   
68
69     double tgt_heading;  // target heading, degrees true
70     double tgt_altitude; // target altitude, *feet* above sea level
71     double tgt_speed;    // target speed, KTAS
72     double tgt_roll;
73     double tgt_pitch;
74     double tgt_yaw;
75     double tgt_vs;
76
77
78     string model_path;     //Path to the 3D model
79     SGModelPlacement aip;
80     bool delete_me;
81
82     void Transform();
83
84 private:
85     static void _setLongitude( double longitude );
86     static void _setLatitude ( double latitude );
87     static double _getLongitude();
88     static double _getLatitude ();
89 };
90
91
92 inline void FGAIBase::setPath( const char* model ) {
93   model_path.append(model);
94 }
95
96 inline void FGAIBase::setSpeed( double speed_KTAS ) {
97   speed = tgt_speed = speed_KTAS;
98 }
99
100 inline void FGAIBase::setAltitude( double altitude_ft ) {
101   altitude = tgt_altitude = altitude_ft;
102   pos.setelev(altitude * SG_FEET_TO_METER);
103 }
104
105 inline void FGAIBase::setHeading( double heading ) {
106   hdg = tgt_heading = heading;
107 }
108
109 inline void FGAIBase::setLongitude( double longitude ) {
110     pos.setlon( longitude );
111 }
112
113 inline void FGAIBase::setLatitude ( double latitude ) {
114     pos.setlat( latitude );
115 }
116
117 inline void FGAIBase::setDie( bool die ) { delete_me = die; }
118 inline bool FGAIBase::getDie() { return delete_me; }
119
120 #endif  // _FG_AIBASE_HXX
121