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
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.
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.
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.
20 #ifndef _FG_AIBASE_HXX
21 #define _FG_AIBASE_HXX
25 #include <simgear/constants.h>
26 #include <simgear/math/point3d.hxx>
27 #include <simgear/scene/model/placement.hxx>
29 #include <Main/fg_props.hxx>
39 virtual void update(double dt);
40 inline Point3D GetPos() { return(pos); }
44 virtual void unbind();
46 void setPath( const char* model );
47 void setSpeed( double speed_KTAS );
48 void setAltitude( double altitude_ft );
49 void setHeading( double heading );
50 void setLatitude( double latitude );
51 void setLongitude( double longitude );
52 void setBank( double bank );
54 void setDie( bool die );
59 SGPropertyNode *props;
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
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
78 string model_path; //Path to the 3D model
84 static FGAIBase *_self;
85 const char *_type_str;
89 static double _getVS_fps();
90 static void _setVS_fps( double _vs );
92 static double _getAltitude();
93 static void _setAltitude( double _alt );
95 static void _setLongitude( double longitude );
96 static void _setLatitude ( double latitude );
98 static double _getLongitude();
99 static double _getLatitude ();
101 static bool _isNight();
105 inline void FGAIBase::setPath( const char* model ) {
106 model_path.append(model);
109 inline void FGAIBase::setSpeed( double speed_KTAS ) {
110 speed = tgt_speed = speed_KTAS;
113 inline void FGAIBase::setHeading( double heading ) {
114 hdg = tgt_heading = heading;
117 inline void FGAIBase::setAltitude( double altitude_ft ) {
118 altitude = tgt_altitude = altitude_ft;
119 pos.setelev(altitude * SG_FEET_TO_METER);
122 inline void FGAIBase::setBank( double bank ) {
123 roll = tgt_roll = bank;
126 inline void FGAIBase::setLongitude( double longitude ) {
127 pos.setlon( longitude );
129 inline void FGAIBase::setLatitude ( double latitude ) {
130 pos.setlat( latitude );
133 inline void FGAIBase::setDie( bool die ) { delete_me = die; }
134 inline bool FGAIBase::getDie() { return delete_me; }
136 inline void FGAIBase::_setLongitude( double longitude ) {
137 _self->pos.setlon(longitude);
139 inline void FGAIBase::_setLatitude ( double latitude ) {
140 _self->pos.setlat(latitude);
143 inline double FGAIBase::_getLongitude() { return _self->pos.lon(); }
144 inline double FGAIBase::_getLatitude () { return _self->pos.lat(); }
146 inline double FGAIBase::_getVS_fps() { return _self->vs*60.0; }
147 inline void FGAIBase::_setVS_fps( double _vs ) { _self->vs = _vs/60.0; }
149 inline double FGAIBase::_getAltitude() {
150 return _self->altitude;
152 inline void FGAIBase::_setAltitude( double _alt ) {
153 _self->setAltitude( _alt );
156 inline bool FGAIBase::_isNight() {
157 return (fgGetFloat("/sim/time/sun-angle-rad") > 1.57);
160 #endif // _FG_AIBASE_HXX