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