]> git.mxchange.org Git - flightgear.git/blob - src/FDM/flight.hxx
change file permissions
[flightgear.git] / src / FDM / flight.hxx
1 // flight.hxx -- define shared flight model parameters
2 //
3 // Written by Curtis Olson, started May 1997.
4 //
5 // Copyright (C) 1997  Curtis L. Olson  - http://www.flightgear.org/~curt
6 //
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License as
9 // published by the Free Software Foundation; either version 2 of the
10 // License, or (at your option) any later version.
11 //
12 // This program is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 // General Public License for more details.
16 //
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
20 //
21 // $Id$
22
23
24 #ifndef _FLIGHT_HXX
25 #define _FLIGHT_HXX
26
27
28 #ifndef __cplusplus
29 # error This library requires C++
30 #endif
31
32
33 /* Required get_()
34
35    `FGInterface::get_Longitude ()'
36    `FGInterface::get_Latitude ()'
37    `FGInterface::get_Altitude ()'
38    `FGInterface::get_Phi ()'
39    `FGInterface::get_Theta ()'
40    `FGInterface::get_Psi ()'
41    `FGInterface::get_V_equiv_kts ()'
42
43    `FGInterface::get_V_north ()'
44    `FGInterface::get_V_east ()'
45    `FGInterface::get_V_down ()'
46
47    `FGInterface::get_P_Body ()'
48    `FGInterface::get_Q_Body ()'
49    `FGInterface::get_R_Body ()'
50
51    `FGInterface::get_Gamma_vert_rad ()'
52    `FGInterface::get_Climb_Rate ()'
53    `FGInterface::get_Alpha ()'
54    `FGInterface::get_Beta ()'
55
56    `FGInterface::get_Runway_altitude ()'
57
58    `FGInterface::get_Lon_geocentric ()'
59    `FGInterface::get_Lat_geocentric ()'
60    `FGInterface::get_Sea_level_radius ()'
61    `FGInterface::get_Earth_position_angle ()'
62
63    `FGInterface::get_Latitude_dot()'
64    `FGInterface::get_Longitude_dot()'
65    `FGInterface::get_Radius_dot()'
66
67    `FGInterface::get_Dx_cg ()'
68    `FGInterface::get_Dy_cg ()'
69    `FGInterface::get_Dz_cg ()'
70
71    `FGInterface::get_Radius_to_vehicle ()'
72
73  */
74
75
76 #include <math.h>
77
78 #include <list>
79 #include <vector>
80 #include <string>
81
82 #include <simgear/compiler.h>
83 #include <simgear/constants.h>
84 #include <simgear/structure/subsystem_mgr.hxx>
85 #include <simgear/props/tiedpropertylist.hxx>
86 #include <FDM/groundcache.hxx>
87
88 using std::list;
89 using std::vector;
90 using std::string;
91
92 /**
93  * A little helper class to update the track if
94  * the position has changed. In the constructor, 
95  * create a copy of the current position and store 
96  * references to the position object and the track
97  * variable to update.
98  * The destructor, called at TrackComputer's end of 
99  * life/visibility, computes the track if the 
100  * position has changed.
101  */
102 class TrackComputer {
103 public:
104   inline TrackComputer( double & track, const SGGeod & position ) : 
105     _track( track ),
106     _position( position ),
107     _prevPosition( position ) {
108   }
109
110   inline ~TrackComputer() {
111     if( _prevPosition == _position ) return;
112     _track = SGGeodesy::courseDeg( _prevPosition, _position );
113   }
114 private:
115   double & _track;
116   const SGGeod & _position;
117   const SGGeod _prevPosition;
118 };
119
120 // This is based heavily on LaRCsim/ls_generic.h
121 class FGInterface : public SGSubsystem {
122
123 private:
124   
125     // Has the init() method been called.  This is used to delay
126     // initialization until scenery can be loaded and we know the true
127     // ground elevation.
128     bool inited;
129
130     // Have we bound to the property system
131     bool bound;
132
133     // periodic update management variable.  This is a scheme to run
134     // the fdm with a fixed delta-t.  We control how many iteration of
135     // the fdm to run with the fixed dt based on the elapsed time from
136     // the last update.  This allows us to maintain sync with the real
137     // time clock, even though each frame could take a random amount
138     // of time.  Since "dt" is unlikely to divide evenly into the
139     // elapse time, we keep track of the remainder and add it into the
140     // next elapsed time.  This yields a small amount of temporal
141     // jitter ( < dt ) but in practice seems to work well.
142
143     // CG position w.r.t. ref. point
144     SGVec3d d_cg_rp_body_v;
145
146     // Accelerations
147     SGVec3d v_dot_local_v;
148     SGVec3d v_dot_body_v;
149     SGVec3d a_cg_body_v;
150     SGVec3d a_pilot_body_v;
151     SGVec3d n_cg_body_v;
152     SGVec3d omega_dot_body_v;
153
154     // Velocities
155     SGVec3d v_local_v;
156     SGVec3d v_local_rel_ground_v; // V rel w.r.t. earth surface
157     SGVec3d v_local_airmass_v;    // velocity of airmass (steady winds)
158     SGVec3d v_wind_body_v;        // Wind-relative velocities in body axis
159
160     SGVec3d omega_body_v;         // Angular B rates
161     SGVec3d euler_rates_v;
162     SGVec3d geocentric_rates_v;   // Geocentric linear velocities
163
164     // Positions
165     SGGeod geodetic_position_v;
166     SGVec3d cartesian_position_v;
167     SGGeoc geocentric_position_v;
168     SGVec3d euler_angles_v;
169
170     // Normal Load Factor
171     double nlf;
172
173     // Velocities
174     double v_rel_wind, v_true_kts;
175     double v_ground_speed, v_equiv_kts;
176     double v_calibrated_kts;
177
178     // Miscellaneious Quantities
179     double alpha, beta;  // in radians
180     double gamma_vert_rad;  // Flight path angles
181     double density, mach_number;
182     double static_pressure, total_pressure;
183     double dynamic_pressure;
184     double static_temperature, total_temperature;
185     double sea_level_radius, earth_position_angle;
186     double runway_altitude;
187     double climb_rate;                // in feet per second
188     double altitude_agl;
189     double track;
190
191     simgear::TiedPropertyList _tiedProperties;
192
193     // the ground cache object itself.
194     FGGroundCache ground_cache;
195
196     void set_A_X_pilot(double x)
197     { _set_Accels_Pilot_Body(x, a_pilot_body_v[1], a_pilot_body_v[2]); }
198     
199     void set_A_Y_pilot(double y)
200     { _set_Accels_Pilot_Body(a_pilot_body_v[0], y, a_pilot_body_v[2]); }
201     
202     void set_A_Z_pilot(double z)
203     { _set_Accels_Pilot_Body(a_pilot_body_v[0], a_pilot_body_v[1], z); }
204     
205 protected:
206
207     int _calc_multiloop (double dt);
208
209 public:
210
211                                 // deliberately not virtual so that
212                                 // FGInterface constructor will call
213                                 // the right version
214     void _setup();
215
216     void _busdump(void);
217     void _updatePositionM(const SGVec3d& cartPos);
218     void _updatePositionFt(const SGVec3d& cartPos) {
219         _updatePositionM(SG_FEET_TO_METER*cartPos);
220     }
221     void _updatePosition(const SGGeod& geod);
222     void _updatePosition(const SGGeoc& geoc);
223   
224     void _updateGeodeticPosition( double lat, double lon, double alt );
225     void _updateGeocentricPosition( double lat_geoc, double lon, double alt );
226     void _update_ground_elev_at_pos( void );
227
228     inline void _set_CG_Position( double dx, double dy, double dz ) {
229         d_cg_rp_body_v[0] = dx;
230         d_cg_rp_body_v[1] = dy;
231         d_cg_rp_body_v[2] = dz;
232     }
233     inline void _set_Accels_Local( double north, double east, double down ) {
234         v_dot_local_v[0] = north;
235         v_dot_local_v[1] = east;
236         v_dot_local_v[2] = down;
237     }
238     inline void _set_Accels_Body( double u, double v, double w ) {
239         v_dot_body_v[0] = u;
240         v_dot_body_v[1] = v;
241         v_dot_body_v[2] = w;
242     }
243     inline void _set_Accels_CG_Body( double x, double y, double z ) {
244         a_cg_body_v[0] = x;
245         a_cg_body_v[1] = y;
246         a_cg_body_v[2] = z;
247     }
248     inline void _set_Accels_Pilot_Body( double x, double y, double z ) {
249         a_pilot_body_v[0] = x;
250         a_pilot_body_v[1] = y;
251         a_pilot_body_v[2] = z;
252     }
253     inline void _set_Accels_CG_Body_N( double x, double y, double z ) {
254         n_cg_body_v[0] = x;
255         n_cg_body_v[1] = y;
256         n_cg_body_v[2] = z;
257     }
258     void _set_Nlf(double n) { nlf=n;  }
259     inline void _set_Velocities_Local( double north, double east, double down ){
260         v_local_v[0] = north;
261         v_local_v[1] = east;
262         v_local_v[2] = down;
263     }
264     inline void _set_Velocities_Ground(double north, double east, double down) {
265         v_local_rel_ground_v[0] = north;
266         v_local_rel_ground_v[1] = east;
267         v_local_rel_ground_v[2] = down;
268     }
269     inline void _set_Velocities_Local_Airmass( double north, double east, 
270                                               double down)
271     {
272         v_local_airmass_v[0] = north;
273         v_local_airmass_v[1] = east;
274         v_local_airmass_v[2] = down;
275     }
276     inline void _set_Velocities_Wind_Body( double u, double v, double w) {
277         v_wind_body_v[0] = u;
278         v_wind_body_v[1] = v;
279         v_wind_body_v[2] = w;
280     }
281     inline void _set_V_rel_wind(double vt) { v_rel_wind = vt; }
282     inline void _set_V_ground_speed( double v) { v_ground_speed = v; }
283     inline void _set_V_equiv_kts( double kts ) { v_equiv_kts = kts; }
284     inline void _set_V_calibrated_kts( double kts ) { v_calibrated_kts = kts; }
285     inline void _set_Omega_Body( double p, double q, double r ) {
286         omega_body_v[0] = p;
287         omega_body_v[1] = q;
288         omega_body_v[2] = r;
289     }
290     inline void _set_Euler_Rates( double phi, double theta, double psi ) {
291         euler_rates_v[0] = phi;
292         euler_rates_v[1] = theta;
293         euler_rates_v[2] = psi;
294     }
295     
296     void set_Phi_dot_degps(double x)
297     {
298       euler_rates_v[0] = x * SG_DEGREES_TO_RADIANS;
299     }
300     
301     void set_Theta_dot_degps(double x)
302     {
303       euler_rates_v[1] = x * SG_DEGREES_TO_RADIANS;
304     }
305     
306     void set_Psi_dot_degps(double x)
307     {
308       euler_rates_v[2] = x * SG_DEGREES_TO_RADIANS;
309     }
310     
311     inline void _set_Geocentric_Rates( double lat, double lon, double rad ) {
312         geocentric_rates_v[0] = lat;
313         geocentric_rates_v[1] = lon;
314         geocentric_rates_v[2] = rad;
315     }
316     inline void _set_Geocentric_Position( double lat, double lon, double rad ) {
317         geocentric_position_v.setLatitudeRad(lat);
318         geocentric_position_v.setLongitudeRad(lon);
319         geocentric_position_v.setRadiusFt(rad);
320     }
321 /*  Don't call _set_L[at|ong]itude() directly, use _set_Geodetic_Position() instead.
322     These methods can't update the track.
323  *
324     inline void _set_Latitude(double lat) {
325         geodetic_position_v.setLatitudeRad(lat);
326     }
327     inline void _set_Longitude(double lon) {
328         geodetic_position_v.setLongitudeRad(lon);
329     }
330 */
331     inline void _set_Altitude(double altitude) {
332         geodetic_position_v.setElevationFt(altitude);
333     }
334     inline void _set_Altitude_AGL(double agl) {
335         altitude_agl = agl;
336     }
337     inline void _set_Geodetic_Position( double lat, double lon ) {
338         _set_Geodetic_Position( lat, lon, geodetic_position_v.getElevationFt());
339     }
340     inline void _set_Geodetic_Position( double lat, double lon, double alt ) {
341         TrackComputer tracker( track, geodetic_position_v );
342         geodetic_position_v.setLatitudeRad(lat);
343         geodetic_position_v.setLongitudeRad(lon);
344         geodetic_position_v.setElevationFt(alt);
345     }
346     inline void _set_Euler_Angles( double phi, double theta, double psi ) {
347         euler_angles_v[0] = phi;
348         euler_angles_v[1] = theta;
349         euler_angles_v[2] = psi;
350     }
351     // FIXME, for compatibility with JSBSim
352     inline void _set_T_Local_to_Body( int i, int j, double value) { }
353     inline void _set_Alpha( double a ) { alpha = a; }
354     inline void _set_Beta( double b ) { beta = b; }
355     
356     inline void set_Alpha_deg( double a ) { alpha = a * SG_DEGREES_TO_RADIANS; }
357     
358     inline void _set_Gamma_vert_rad( double gv ) { gamma_vert_rad = gv; }
359     inline void _set_Density( double d ) { density = d; }
360     inline void _set_Mach_number( double m ) { mach_number = m; }
361     inline void _set_Static_pressure( double sp ) { static_pressure = sp; }
362     inline void _set_Static_temperature( double t ) { static_temperature = t; } 
363     inline void _set_Total_temperature( double tat ) { total_temperature = tat; } //JW
364     inline void _set_Sea_level_radius( double r ) { sea_level_radius = r; }
365     inline void _set_Earth_position_angle(double a) { earth_position_angle = a; }
366     inline void _set_Runway_altitude( double alt ) { runway_altitude = alt; }
367     inline void _set_Climb_Rate(double rate) { climb_rate = rate; }
368
369 public:
370   
371     FGInterface();
372     FGInterface( double dt );
373     virtual ~FGInterface();
374
375     virtual void init ();
376     virtual void bind ();
377     virtual void unbind ();
378     virtual void update(double dt);
379     virtual bool ToggleDataLogging(bool state) { return false; }
380     virtual bool ToggleDataLogging(void) { return false; }
381
382     // Define the various supported flight models (many not yet implemented)
383     enum {
384         // Magic Carpet mode
385         FG_MAGICCARPET = 0,
386
387         // The NASA LaRCsim (Navion) flight model
388         FG_LARCSIM = 1,
389
390         // Jon S. Berndt's new FDM written from the ground up in C++
391         FG_JSBSIM = 2,
392
393         // Christian's hot air balloon simulation
394         FG_BALLOONSIM = 3,
395
396         // Aeronautical DEvelopment AGEncy, Bangalore India
397         FG_ADA = 4,
398
399         // The following aren't implemented but are here to spark
400         // thoughts and discussions, and maybe even action.
401         FG_ACM = 5,
402         FG_SUPER_SONIC = 6,
403         FG_HELICOPTER = 7,
404         FG_AUTOGYRO = 8,
405         FG_PARACHUTE = 9,
406
407         // Driven externally via a serial port, net, file, etc.
408         FG_EXTERNAL = 10
409     };
410
411     // initialization
412     inline bool get_inited() const { return inited; }
413     inline void set_inited( bool value ) { inited = value; }
414
415     inline bool get_bound() const { return bound; }
416
417     //perform initializion that is common to all FDM's
418     void common_init();
419
420     // Positions
421     virtual void set_Latitude(double lat);       // geocentric
422     virtual void set_Longitude(double lon);    
423     virtual void set_Altitude(double alt);  // triggers re-calc of AGL altitude
424     virtual void set_AltitudeAGL(double altagl); // and vice-versa
425     virtual void set_Latitude_deg (double lat) {
426       set_Latitude(lat * SGD_DEGREES_TO_RADIANS);
427     }
428     virtual void set_Longitude_deg (double lon) {
429       set_Longitude(lon * SGD_DEGREES_TO_RADIANS);
430     }
431     
432     // Speeds -- setting any of these will trigger a re-calc of the rest
433     virtual void set_V_calibrated_kts(double vc);
434     virtual void set_Mach_number(double mach);
435     virtual void set_Velocities_Local( double north, double east, double down );
436     inline void set_V_north (double north) { 
437       set_Velocities_Local(north, v_local_v[1], v_local_v[2]);
438     }
439     inline void set_V_east (double east) { 
440       set_Velocities_Local(v_local_v[0], east, v_local_v[2]);
441     }
442     inline void set_V_down (double down) { 
443       set_Velocities_Local(v_local_v[0], v_local_v[1], down);
444     }
445     virtual void set_Velocities_Wind_Body( double u, double v, double w);
446     virtual void set_uBody (double uBody) { 
447       set_Velocities_Wind_Body(uBody, v_wind_body_v[1], v_wind_body_v[2]);
448     }
449     virtual void set_vBody (double vBody) { 
450       set_Velocities_Wind_Body(v_wind_body_v[0], vBody, v_wind_body_v[2]);
451     }
452     virtual void set_wBody (double wBody) {
453       set_Velocities_Wind_Body(v_wind_body_v[0], v_wind_body_v[1], wBody);
454     }
455     
456     // Euler angles 
457     virtual void set_Euler_Angles( double phi, double theta, double psi );
458     virtual void set_Phi (double phi) {
459       set_Euler_Angles(phi, get_Theta(), get_Psi());
460     }
461     virtual void set_Theta (double theta) {
462       set_Euler_Angles(get_Phi(), theta, get_Psi());
463     }
464     virtual void set_Psi (double psi) { 
465       set_Euler_Angles(get_Phi(), get_Theta(), psi);
466     }
467     virtual void set_Phi_deg (double phi) {
468       set_Phi(phi * SGD_DEGREES_TO_RADIANS);
469     }
470     virtual void set_Theta_deg (double theta) {
471       set_Theta(theta * SGD_DEGREES_TO_RADIANS); 
472     }
473     virtual void set_Psi_deg (double psi) {
474       set_Psi(psi * SGD_DEGREES_TO_RADIANS);
475     }
476     
477     // Flight Path
478     virtual void set_Climb_Rate( double roc);
479     virtual void set_Gamma_vert_rad( double gamma);
480     
481     // Earth
482     
483     virtual void set_Static_pressure(double p);
484     virtual void set_Static_temperature(double T);
485     virtual void set_Density(double rho);
486     
487     virtual void set_Velocities_Local_Airmass (double wnorth, 
488                                                double weast, 
489                                                double wdown );
490
491     // ========== Mass properties and geometry values ==========
492
493     // CG position w.r.t. ref. point
494     inline double get_Dx_cg() const { return d_cg_rp_body_v[0]; }
495     inline double get_Dy_cg() const { return d_cg_rp_body_v[1]; }
496     inline double get_Dz_cg() const { return d_cg_rp_body_v[2]; }
497
498     // ========== Accelerations ==========
499
500     inline double get_V_dot_north() const { return v_dot_local_v[0]; }
501     inline double get_V_dot_east() const { return v_dot_local_v[1]; }
502     inline double get_V_dot_down() const { return v_dot_local_v[2]; }
503
504     inline double get_U_dot_body() const { return v_dot_body_v[0]; }
505     inline double get_V_dot_body() const { return v_dot_body_v[1]; }
506     inline double get_W_dot_body() const { return v_dot_body_v[2]; }
507
508     inline double get_A_X_cg() const { return a_cg_body_v[0]; }
509     inline double get_A_Y_cg() const { return a_cg_body_v[1]; }
510     inline double get_A_Z_cg() const { return a_cg_body_v[2]; }
511
512     inline double get_A_X_pilot() const { return a_pilot_body_v[0]; }
513     inline double get_A_Y_pilot() const { return a_pilot_body_v[1]; }
514     inline double get_A_Z_pilot() const { return a_pilot_body_v[2]; }
515
516     inline double get_N_X_cg() const { return n_cg_body_v[0]; }
517     inline double get_N_Y_cg() const { return n_cg_body_v[1]; }
518     inline double get_N_Z_cg() const { return n_cg_body_v[2]; }
519
520     inline double get_Nlf(void) const { return nlf; }
521
522     // ========== Velocities ==========
523
524     inline double get_V_north() const { return v_local_v[0]; }
525     inline double get_V_east() const { return v_local_v[1]; }
526     inline double get_V_down() const { return v_local_v[2]; }
527     inline double get_uBody () const { return v_wind_body_v[0]; }
528     inline double get_vBody () const { return v_wind_body_v[1]; }
529     inline double get_wBody () const { return v_wind_body_v[2]; }
530
531     // Please dont comment these out. fdm=ada uses these (see
532     // cockpit.cxx) --->
533     inline double get_V_north_rel_ground() const {
534         return v_local_rel_ground_v[0];
535     }
536     inline double get_V_east_rel_ground() const {
537         return v_local_rel_ground_v[1];
538     }
539     inline double get_V_down_rel_ground() const {
540         return v_local_rel_ground_v[2];
541     }
542     // <--- fdm=ada uses these (see cockpit.cxx)
543
544     inline double get_V_north_airmass() const { return v_local_airmass_v[0]; }
545     inline double get_V_east_airmass() const { return v_local_airmass_v[1]; }
546     inline double get_V_down_airmass() const { return v_local_airmass_v[2]; }
547
548     inline double get_U_body() const { return v_wind_body_v[0]; }
549     inline double get_V_body() const { return v_wind_body_v[1]; }
550     inline double get_W_body() const { return v_wind_body_v[2]; }
551
552     inline double get_V_rel_wind() const { return v_rel_wind; }
553
554     inline double get_V_true_kts() const { return v_true_kts; }
555
556     inline double get_V_ground_speed() const { return v_ground_speed; }
557     inline double get_V_ground_speed_kt() const { return v_ground_speed * SG_FEET_TO_METER * 3600 * SG_METER_TO_NM; }
558     inline void   set_V_ground_speed_kt(double ground_speed) { v_ground_speed = ground_speed / ( SG_FEET_TO_METER * 3600 * SG_METER_TO_NM); }
559
560     inline double get_V_equiv_kts() const { return v_equiv_kts; }
561
562     inline double get_V_calibrated_kts() const { return v_calibrated_kts; }
563
564     inline double get_P_body() const { return omega_body_v[0]; }
565     inline double get_Q_body() const { return omega_body_v[1]; }
566     inline double get_R_body() const { return omega_body_v[2]; }
567
568     inline double get_Phi_dot() const { return euler_rates_v[0]; }
569     inline double get_Theta_dot() const { return euler_rates_v[1]; }
570     inline double get_Psi_dot() const { return euler_rates_v[2]; }
571     inline double get_Phi_dot_degps() const { return euler_rates_v[0] * SGD_RADIANS_TO_DEGREES; }
572     inline double get_Theta_dot_degps() const { return euler_rates_v[1] * SGD_RADIANS_TO_DEGREES; }
573     inline double get_Psi_dot_degps() const { return euler_rates_v[2] * SGD_RADIANS_TO_DEGREES; }
574
575     inline double get_Latitude_dot() const { return geocentric_rates_v[0]; }
576     inline double get_Longitude_dot() const { return geocentric_rates_v[1]; }
577     inline double get_Radius_dot() const { return geocentric_rates_v[2]; }
578
579     // ========== Positions ==========
580
581     inline double get_Lat_geocentric() const {
582         return geocentric_position_v.getLatitudeRad();
583     }
584     inline double get_Lon_geocentric() const {
585         return geocentric_position_v.getLongitudeRad();
586     }
587     inline double get_Radius_to_vehicle() const {
588         return geocentric_position_v.getRadiusFt();
589     }
590
591     const SGGeod& getPosition() const { return geodetic_position_v; }
592     const SGGeoc& getGeocPosition() const { return geocentric_position_v; }
593     const SGVec3d& getCartPosition() const { return cartesian_position_v; }
594
595     inline double get_Latitude() const {
596         return geodetic_position_v.getLatitudeRad();
597     }
598     inline double get_Longitude() const {
599         return geodetic_position_v.getLongitudeRad();
600     }
601     inline double get_Altitude() const {
602         return geodetic_position_v.getElevationFt();
603     }
604     inline double get_Altitude_AGL(void) const { return altitude_agl; }
605     inline double get_Track(void) const { return track; }
606
607     inline double get_Latitude_deg () const {
608       return geodetic_position_v.getLatitudeDeg();
609     }
610     inline double get_Longitude_deg () const {
611       return geodetic_position_v.getLongitudeDeg();
612     }
613
614     inline double get_Phi() const { return euler_angles_v[0]; }
615     inline double get_Theta() const { return euler_angles_v[1]; }
616     inline double get_Psi() const { return euler_angles_v[2]; }
617     inline double get_Phi_deg () const { return get_Phi() * SGD_RADIANS_TO_DEGREES; }
618     inline double get_Theta_deg () const { return get_Theta() * SGD_RADIANS_TO_DEGREES; }
619     inline double get_Psi_deg () const { return get_Psi() * SGD_RADIANS_TO_DEGREES; }
620
621
622     // ========== Miscellaneous quantities ==========
623
624     inline double get_Alpha() const { return alpha; }
625     inline double get_Alpha_deg() const { return alpha * SGD_RADIANS_TO_DEGREES; }
626     inline double get_Beta() const { return beta; }
627     inline double get_Beta_deg() const { return beta * SGD_RADIANS_TO_DEGREES; }
628     inline double get_Gamma_vert_rad() const { return gamma_vert_rad; }
629
630     inline double get_Density() const { return density; }
631     inline double get_Mach_number() const { return mach_number; }
632
633     inline double get_Static_pressure() const { return static_pressure; }
634     inline double get_Total_pressure() const { return total_pressure; }
635     inline double get_Dynamic_pressure() const { return dynamic_pressure; }
636
637     inline double get_Static_temperature() const { return static_temperature; }
638     inline double get_Total_temperature() const { return total_temperature; }
639
640     inline double get_Sea_level_radius() const { return sea_level_radius; }
641     inline double get_Earth_position_angle() const {
642         return earth_position_angle;
643     }
644
645     inline double get_Runway_altitude() const { return runway_altitude; }
646     inline double get_Runway_altitude_m() const { return SG_FEET_TO_METER * runway_altitude; }
647
648     inline double get_Climb_Rate() const { return climb_rate; }
649
650     // Note that currently this is the "same" value runway altitude...
651     inline double get_ground_elev_ft() const { return runway_altitude; }
652
653
654     //////////////////////////////////////////////////////////////////////////
655     // Ground handling routines
656     //////////////////////////////////////////////////////////////////////////
657
658     // Prepare the ground cache for the wgs84 position pt_*.
659     // That is take all vertices in the ball with radius rad around the
660     // position given by the pt_* and store them in a local scene graph.
661     bool prepare_ground_cache_m(double startSimTime, double endSimTime,
662                                 const double pt[3], double rad);
663     bool prepare_ground_cache_ft(double startSimTime, double endSimTime,
664                                  const double pt[3], double rad);
665
666
667     // Returns true if the cache is valid.
668     // Also the reference time, point and radius values where the cache
669     // is valid for are returned.
670     bool is_valid_m(double *ref_time, double pt[3], double *rad);
671     bool is_valid_ft(double *ref_time, double pt[3], double *rad);
672
673     // Return the nearest catapult to the given point
674     // pt in wgs84 coordinates.
675     double get_cat_m(double t, const double pt[3],
676                      double end[2][3], double vel[2][3]);
677     double get_cat_ft(double t, const double pt[3],
678                       double end[2][3], double vel[2][3]);
679   
680
681     // Return the orientation and position matrix and the linear and angular
682     // velocity of that local coordinate systems origin for a given time and
683     // body id. The velocities are in the wgs84 frame at the bodys origin.
684     bool get_body_m(double t, simgear::BVHNode::Id id, double bodyToWorld[16],
685                     double linearVel[3], double angularVel[3]);
686
687
688     // Return the altitude above ground below the wgs84 point pt
689     // Search for the nearest triangle to pt in downward direction.
690     // Return ground properties. The velocities are in the wgs84 frame at the
691     // contact point.
692     bool get_agl_m(double t, const double pt[3], double max_altoff,
693                    double contact[3], double normal[3], double linearVel[3],
694                    double angularVel[3], SGMaterial const*& material,
695                    simgear::BVHNode::Id& id);
696     bool get_agl_ft(double t, const double pt[3], double max_altoff,
697                     double contact[3], double normal[3], double linearVel[3],
698                     double angularVel[3], SGMaterial const*& material,
699                     simgear::BVHNode::Id& id);
700     double get_groundlevel_m(double lat, double lon, double alt);
701     double get_groundlevel_m(const SGGeod& geod);
702
703
704     // Return the nearest point in any direction to the point pt with a maximum
705     // distance maxDist. The velocities are in the wgs84 frame at the query
706     // position pt.
707     bool get_nearest_m(double t, const double pt[3], double maxDist,
708                        double contact[3], double normal[3], double linearVel[3],
709                        double angularVel[3], SGMaterial const*& material,
710                        simgear::BVHNode::Id& id);
711     bool get_nearest_ft(double t, const double pt[3], double maxDist,
712                         double contact[3], double normal[3],double linearVel[3],
713                         double angularVel[3], SGMaterial const*& material,
714                         simgear::BVHNode::Id& id);
715
716
717     // Return 1 if the hook intersects with a wire.
718     // That test is done by checking if the quad spanned by the points pt*
719     // intersects with the line representing the wire.
720     // If the wire is caught, the cache will trace this wires endpoints until
721     // the FDM calls release_wire().
722     bool caught_wire_m(double t, const double pt[4][3]);
723     bool caught_wire_ft(double t, const double pt[4][3]);
724   
725     // Return the location and speed of the wire endpoints.
726     bool get_wire_ends_m(double t, double end[2][3], double vel[2][3]);
727     bool get_wire_ends_ft(double t, double end[2][3], double vel[2][3]);
728
729     // Tell the cache code that it does no longer need to care for
730     // the wire end position.
731     void release_wire(void);
732 };
733
734 #endif // _FLIGHT_HXX