//
// Written by Curtis Olson, started May 1997.
//
-// Copyright (C) 1997 Curtis L. Olson - curt@infoplane.com
+// Copyright (C) 1997 Curtis L. Olson - http://www.flightgear.org/~curt
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License as
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
-// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
//
// $Id$
*/
-#include <simgear/compiler.h>
-
#include <math.h>
#include <list>
#include <vector>
#include <string>
+#include <simgear/compiler.h>
#include <simgear/constants.h>
-#include <Main/fgfs.hxx>
+#include <simgear/structure/subsystem_mgr.hxx>
+#include <FDM/groundcache.hxx>
SG_USING_STD(list);
SG_USING_STD(vector);
SG_USING_STD(string);
-class FGAircraftModel;
-
-
typedef double FG_VECTOR_3[3];
// This is based heavily on LaRCsim/ls_generic.h
-class FGInterface : public FGSubsystem {
+class FGInterface : public SGSubsystem {
private:
// SGTimeStamp valid_stamp; // time this record is valid
// SGTimeStamp next_stamp; // time this record is valid
- // Model tied to FDM
- FGAircraftModel * _acmodel;
+ // the ground cache object itself.
+ FGGroundCache ground_cache;
protected:
void _busdump(void);
void _updateGeodeticPosition( double lat, double lon, double alt );
void _updateGeocentricPosition( double lat_geoc, double lon, double alt );
+ void _update_ground_elev_at_pos( void );
void _updateWeather( void );
inline void _set_Inertias( double m, double xx, double yy,
inline void _set_Density( double d ) { density = d; }
inline void _set_Mach_number( double m ) { mach_number = m; }
inline void _set_Static_pressure( double sp ) { static_pressure = sp; }
- inline void _set_Static_temperature( double t ) { static_temperature = t; }
+ inline void _set_Static_temperature( double t ) { static_temperature = t; }
+ inline void _set_Total_temperature( double tat ) { total_temperature = tat; } //JW
inline void _set_Sea_level_radius( double r ) { sea_level_radius = r; }
- inline void _set_Earth_position_angle(double a) {
- earth_position_angle = a;
- }
+ inline void _set_Earth_position_angle(double a) { earth_position_angle = a; }
inline void _set_Runway_altitude( double alt ) { runway_altitude = alt; }
inline void _set_Climb_Rate(double rate) { climb_rate = rate; }
inline void _set_sin_lat_geocentric(double parm) {
}
inline double get_Runway_altitude() const { return runway_altitude; }
+ inline double get_Runway_altitude_m() const { return SG_FEET_TO_METER * runway_altitude; }
// inline double get_Runway_latitude() const { return runway_latitude; }
// inline void set_Runway_latitude( double lat ) { runway_latitude = lat; }
// inline double get_Runway_longitude() const { return runway_longitude; }
inline float get_faux( int n ) const { return faux[n]; }
inline int get_iaux( int n ) const { return iaux[n]; }
- // Model tied to FDM
- FGAircraftModel * getACModel() const { return _acmodel; }
-
// Note that currently this is the "same" value runway altitude...
inline double get_ground_elev_ft() const { return runway_altitude; }
-};
+ //////////////////////////////////////////////////////////////////////////
+ // Ground handling routines
+ //////////////////////////////////////////////////////////////////////////
-typedef list < FGInterface > fdm_state_list;
-typedef fdm_state_list::iterator fdm_state_list_iterator;
-typedef fdm_state_list::const_iterator const_fdm_state_list_iterator;
-
+ enum GroundType {
+ Unknown = 0, //??
+ Solid, // Whatever we will roll on with infinite load factor.
+ Water, // For the beaver ...
+ Catapult, // Carrier cats.
+ Wire // Carrier wires.
+ };
-extern FGInterface * cur_fdm_state;
+ // Prepare the ground cache for the wgs84 position pt_*.
+ // That is take all vertices in the ball with radius rad around the
+ // position given by the pt_* and store them in a local scene graph.
+ bool prepare_ground_cache_m(double ref_time, const double pt[3],
+ double rad);
+ bool prepare_ground_cache_ft(double ref_time, const double pt[3],
+ double rad);
+
+
+ // Returns true if the cache is valid.
+ // Also the reference time, point and radius values where the cache
+ // is valid for are returned.
+ bool is_valid_m(double *ref_time, double pt[3], double *rad);
+ bool is_valid_ft(double *ref_time, double pt[3], double *rad);
+
+ // Return the nearest catapult to the given point
+ // pt in wgs84 coordinates.
+ double get_cat_m(double t, const double pt[3],
+ double end[2][3], double vel[2][3]);
+ double get_cat_ft(double t, const double pt[3],
+ double end[2][3], double vel[2][3]);
+
+ // Return the altitude above ground below the wgs84 point pt
+ // Search for the nearest triangle to pt.
+ // Return ground properties like the ground type, the maximum load
+ // this kind kind of ground can carry, the friction factor between
+ // 0 and 1 which can be used to model lower friction with wet runways
+ // and finally the altitude above ground.
+ bool get_agl_m(double t, const double pt[3],
+ double contact[3], double normal[3], double vel[3],
+ int *type, double *loadCapacity,
+ double *frictionFactor, double *agl);
+ bool get_agl_ft(double t, const double pt[3],
+ double contact[3], double normal[3], double vel[3],
+ int *type, double *loadCapacity,
+ double *frictionFactor, double *agl);
+
+ // Return the altitude above ground below the wgs84 point pt
+ // Search for the nearest triangle to pt.
+ // Return ground properties like the ground type, a pointer to the
+ // material and finally the altitude above ground.
+ bool get_agl_m(double t, const double pt[3], double max_altoff,
+ double contact[3], double normal[3], double vel[3],
+ int *type, const SGMaterial** material, double *agl);
+ bool get_agl_ft(double t, const double pt[3], double max_altoff,
+ double contact[3], double normal[3], double vel[3],
+ int *type, const SGMaterial** material, double *agl);
+ double get_groundlevel_m(double lat, double lon, double alt);
+
+
+ // Return 1 if the hook intersects with a wire.
+ // That test is done by checking if the quad spanned by the points pt*
+ // intersects with the line representing the wire.
+ // If the wire is caught, the cache will trace this wires endpoints until
+ // the FDM calls release_wire().
+ bool caught_wire_m(double t, const double pt[4][3]);
+ bool caught_wire_ft(double t, const double pt[4][3]);
+
+ // Return the location and speed of the wire endpoints.
+ bool get_wire_ends_m(double t, double end[2][3], double vel[2][3]);
+ bool get_wire_ends_ft(double t, double end[2][3], double vel[2][3]);
-// General interface to the flight model routines
+ // Tell the cache code that it does no longer need to care for
+ // the wire end position.
+ void release_wire(void);
+};
+extern FGInterface * cur_fdm_state;
// Toggle data logging on/off
void fgToggleFDMdataLogging(void);