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