X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FFDM%2Fflight.hxx;h=6965d30983e401c520e49eabaf8b0d8124439ef9;hb=38226af24ec01e8f0a20d7fd73ef838a69f6ef25;hp=4a47eeac3f0cd21870257ec580fe2564cb2ceca3;hpb=17262df51cc5a9a542a35d6126b55f08cb210f7e;p=flightgear.git diff --git a/src/FDM/flight.hxx b/src/FDM/flight.hxx index 4a47eeac3..6965d3098 100644 --- a/src/FDM/flight.hxx +++ b/src/FDM/flight.hxx @@ -40,12 +40,6 @@ `FGInterface::get_Psi ()' `FGInterface::get_V_equiv_kts ()' - `FGInterface::get_Mass ()' - `FGInterface::get_I_xx ()' - `FGInterface::get_I_yy ()' - `FGInterface::get_I_zz ()' - `FGInterface::get_I_xz ()' - `FGInterface::get_V_north ()' `FGInterface::get_V_east ()' `FGInterface::get_V_down ()' @@ -90,9 +84,37 @@ #include #include -SG_USING_STD(list); -SG_USING_STD(vector); -SG_USING_STD(string); +using std::list; +using std::vector; +using std::string; + +/** + * A little helper class to update the track if + * the position has changed. In the constructor, + * create a copy of the current position and store + * references to the position object and the track + * variable to update. + * The destructor, called at TrackComputer's end of + * life/visibility, computes the track if the + * position has changed. + */ +class TrackComputer { +public: + inline TrackComputer( double & track, const SGGeod & position ) : + _track( track ), + _position( position ), + _prevPosition( position ) { + } + + inline ~TrackComputer() { + if( _prevPosition == _position ) return; + _track = SGGeodesy::courseDeg( _prevPosition, _position ); + } +private: + double & _track; + const SGGeod & _position; + const SGGeod _prevPosition; +}; // This is based heavily on LaRCsim/ls_generic.h class FGInterface : public SGSubsystem { @@ -117,8 +139,6 @@ private: // next elapsed time. This yields a small amount of temporal // jitter ( < dt ) but in practice seems to work well. - double remainder; // remainder time from last run - // CG position w.r.t. ref. point SGVec3d d_cg_rp_body_v; @@ -146,9 +166,6 @@ private: SGGeoc geocentric_position_v; SGVec3d euler_angles_v; - // Inertias - double mass, i_xx, i_yy, i_zz, i_xz; - // Normal Load Factor double nlf; @@ -168,14 +185,20 @@ private: double runway_altitude; double climb_rate; // in feet per second double altitude_agl; - - double daux[16]; // auxilliary doubles - float faux[16]; // auxilliary floats - int iaux[16]; // auxilliary ints + double track; // the ground cache object itself. FGGroundCache ground_cache; + void set_A_X_pilot(double x) + { _set_Accels_Pilot_Body(x, a_pilot_body_v[1], a_pilot_body_v[2]); } + + void set_A_Y_pilot(double y) + { _set_Accels_Pilot_Body(a_pilot_body_v[0], y, a_pilot_body_v[2]); } + + void set_A_Z_pilot(double z) + { _set_Accels_Pilot_Body(a_pilot_body_v[0], a_pilot_body_v[1], z); } + protected: int _calc_multiloop (double dt); @@ -199,15 +222,6 @@ public: void _updateGeocentricPosition( double lat_geoc, double lon, double alt ); void _update_ground_elev_at_pos( void ); - inline void _set_Inertias( double m, double xx, double yy, - double zz, double xz) - { - mass = m; - i_xx = xx; - i_yy = yy; - i_zz = zz; - i_xz = xz; - } inline void _set_CG_Position( double dx, double dy, double dz ) { d_cg_rp_body_v[0] = dx; d_cg_rp_body_v[1] = dy; @@ -275,6 +289,22 @@ public: euler_rates_v[1] = theta; euler_rates_v[2] = psi; } + + void set_Phi_dot_degps(double x) + { + euler_rates_v[0] = x * SG_DEGREES_TO_RADIANS; + } + + void set_Theta_dot_degps(double x) + { + euler_rates_v[1] = x * SG_DEGREES_TO_RADIANS; + } + + void set_Psi_dot_degps(double x) + { + euler_rates_v[2] = x * SG_DEGREES_TO_RADIANS; + } + inline void _set_Geocentric_Rates( double lat, double lon, double rad ) { geocentric_rates_v[0] = lat; geocentric_rates_v[1] = lon; @@ -285,19 +315,27 @@ public: geocentric_position_v.setLongitudeRad(lon); geocentric_position_v.setRadiusFt(rad); } +/* Don't call _set_L[at|ong]itude() directly, use _set_Geodetic_Position() instead. + These methods can't update the track. + * inline void _set_Latitude(double lat) { geodetic_position_v.setLatitudeRad(lat); } inline void _set_Longitude(double lon) { geodetic_position_v.setLongitudeRad(lon); } +*/ inline void _set_Altitude(double altitude) { geodetic_position_v.setElevationFt(altitude); } inline void _set_Altitude_AGL(double agl) { altitude_agl = agl; } + inline void _set_Geodetic_Position( double lat, double lon ) { + _set_Geodetic_Position( lat, lon, geodetic_position_v.getElevationFt()); + } inline void _set_Geodetic_Position( double lat, double lon, double alt ) { + TrackComputer tracker( track, geodetic_position_v ); geodetic_position_v.setLatitudeRad(lat); geodetic_position_v.setLongitudeRad(lon); geodetic_position_v.setElevationFt(alt); @@ -311,6 +349,9 @@ public: inline void _set_T_Local_to_Body( int i, int j, double value) { } inline void _set_Alpha( double a ) { alpha = a; } inline void _set_Beta( double b ) { beta = b; } + + inline void set_Alpha_deg( double a ) { alpha = a * SG_DEGREES_TO_RADIANS; } + inline void _set_Gamma_vert_rad( double gv ) { gamma_vert_rad = gv; } inline void _set_Density( double d ) { density = d; } inline void _set_Mach_number( double m ) { mach_number = m; } @@ -322,10 +363,6 @@ public: inline void _set_Runway_altitude( double alt ) { runway_altitude = alt; } inline void _set_Climb_Rate(double rate) { climb_rate = rate; } - inline void _set_daux( int n, double value ) { daux[n] = value; } - inline void _set_faux( int n, float value ) { faux[n] = value; } - inline void _set_iaux( int n, int value ) { iaux[n] = value; } - public: FGInterface(); @@ -450,13 +487,6 @@ public: // ========== Mass properties and geometry values ========== - // Inertias - inline double get_Mass() const { return mass; } - inline double get_I_xx() const { return i_xx; } - inline double get_I_yy() const { return i_yy; } - inline double get_I_zz() const { return i_zz; } - inline double get_I_xz() const { return i_xz; } - // CG position w.r.t. ref. point inline double get_Dx_cg() const { return d_cg_rp_body_v[0]; } inline double get_Dy_cg() const { return d_cg_rp_body_v[1]; } @@ -568,6 +598,7 @@ public: return geodetic_position_v.getElevationFt(); } inline double get_Altitude_AGL(void) const { return altitude_agl; } + inline double get_Track(void) const { return track; } inline double get_Latitude_deg () const { return geodetic_position_v.getLatitudeDeg(); @@ -612,11 +643,6 @@ public: inline double get_Climb_Rate() const { return climb_rate; } - // Auxilliary variables - inline double get_daux( int n ) const { return daux[n]; } - inline float get_faux( int n ) const { return faux[n]; } - inline int get_iaux( int n ) const { return iaux[n]; } - // Note that currently this is the "same" value runway altitude... inline double get_ground_elev_ft() const { return runway_altitude; } @@ -625,21 +651,13 @@ public: // Ground handling routines ////////////////////////////////////////////////////////////////////////// - enum GroundType { - Unknown = 0, //?? - Solid, // Whatever we will roll on with infinite load factor. - Water, // For the beaver ... - Catapult, // Carrier cats. - Wire // Carrier wires. - }; - // 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); + bool prepare_ground_cache_m(double startSimTime, double endSimTime, + const double pt[3], double rad); + bool prepare_ground_cache_ft(double startSimTime, double endSimTime, + const double pt[3], double rad); // Returns true if the cache is valid. @@ -656,38 +674,42 @@ public: 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_m(double t, const double pt[3], - 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 contact[3], double normal[3], double vel[3], - int *type, double *loadCapacity, - double *frictionFactor, double *agl); + // Return the orientation and position matrix and the linear and angular + // velocity of that local coordinate systems origin for a given time and + // body id. The velocities are in the wgs84 frame at the bodys origin. + bool get_body_m(double t, simgear::BVHNode::Id id, double bodyToWorld[16], + double linearVel[3], double angularVel[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, a pointer to the - // material and finally the altitude above ground. + // Search for the nearest triangle to pt in downward direction. + // Return ground properties. The velocities are in the wgs84 frame at the + // contact point. 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); + double contact[3], double normal[3], double linearVel[3], + double angularVel[3], SGMaterial const*& material, + simgear::BVHNode::Id& id); 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 contact[3], double normal[3], double linearVel[3], + double angularVel[3], SGMaterial const*& material, + simgear::BVHNode::Id& id); double get_groundlevel_m(double lat, double lon, double alt); double get_groundlevel_m(const SGGeod& geod); + // Return the nearest point in any direction to the point pt with a maximum + // distance maxDist. The velocities are in the wgs84 frame at the query + // position pt. + bool get_nearest_m(double t, const double pt[3], double maxDist, + double contact[3], double normal[3], double linearVel[3], + double angularVel[3], SGMaterial const*& material, + simgear::BVHNode::Id& id); + bool get_nearest_ft(double t, const double pt[3], double maxDist, + double contact[3], double normal[3],double linearVel[3], + double angularVel[3], SGMaterial const*& material, + simgear::BVHNode::Id& id); + + // 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. @@ -705,10 +727,4 @@ public: void release_wire(void); }; -extern FGInterface * cur_fdm_state; - -// Toggle data logging on/off -void fgToggleFDMdataLogging(void); - - #endif // _FLIGHT_HXX