X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FFDM%2FUFO.cxx;h=e2c1366dbd9570443558448addd254c20530473c;hb=44ce4cdb973461cd1c4d37c9e8d11fe96b238be1;hp=782f699f07a4326ee60d9ec0bb0f8757f32fc634;hpb=18e36a3302c1f0d4dc17387e981659e691ed9710;p=flightgear.git diff --git a/src/FDM/UFO.cxx b/src/FDM/UFO.cxx index 782f699f0..e2c1366db 100644 --- a/src/FDM/UFO.cxx +++ b/src/FDM/UFO.cxx @@ -31,9 +31,18 @@ #include "UFO.hxx" - -FGUFO::FGUFO( double dt ) { - set_delta_t( dt ); +const double throttle_damp = 0.2; +const double aileron_damp = 0.05; +const double elevator_damp = 0.05; +const double rudder_damp = 0.4; + +FGUFO::FGUFO( double dt ) + : Throttle(0.0), + Aileron(0.0), + Elevator(0.0), + Rudder(0.0) +{ +// set_delta_t( dt ); } @@ -49,17 +58,28 @@ void FGUFO::init() { // Run an iteration of the EOM (equations of motion) -void FGUFO::update( int multiloop ) { +void FGUFO::update( double dt ) { // cout << "FGLaRCsim::update()" << endl; - double time_step = get_delta_t() * multiloop; + if (is_suspended()) + return; + + double time_step = dt; // read the throttle - double Throttle = globals->get_controls()->get_throttle( 0 ); + double th = globals->get_controls()->get_throttle( 0 ); + if (globals->get_controls()->get_brake(0)) { + th = -th; + } + Throttle = th * throttle_damp + Throttle * (1 - throttle_damp); // read the state of the control surfaces - double Aileron = globals->get_controls()->get_aileron(); - double Elevator = globals->get_controls()->get_elevator(); + Aileron = globals->get_controls()->get_aileron() * aileron_damp + + Aileron * (1 - aileron_damp); + Elevator = globals->get_controls()->get_elevator() * elevator_damp + + Elevator * (1 - elevator_damp); + Rudder = globals->get_controls()->get_rudder() * rudder_damp + + Rudder * (1 - rudder_damp); // the velocity of the aircraft double velocity = Throttle * 2000; // meters/sec @@ -138,10 +158,11 @@ void FGUFO::update( int multiloop ) { // angle of turn double turn_rate = sin(roll) * SGD_PI_4; // radians/sec double turn = turn_rate * time_step; + double yaw = fabs(Rudder) < .2 ? 0.0 : Rudder / (25 + fabs(speed) * .1); // update (lon/lat) position double lat2, lon2, az2; - if ( speed > SG_EPSILON ) { + if ( fabs(speed) > SG_EPSILON ) { geo_direct_wgs_84 ( get_Altitude(), get_Latitude() * SGD_RADIANS_TO_DEGREES, get_Longitude() * SGD_RADIANS_TO_DEGREES, @@ -161,7 +182,7 @@ void FGUFO::update( int multiloop ) { // update euler angles _set_Euler_Angles( roll, pitch, - fmod(get_Psi() + turn, SGD_2PI) ); + fmod(get_Psi() + turn + yaw, SGD_2PI) ); _set_Euler_Rates(0,0,0); _set_Geocentric_Position( lat_geoc, get_Longitude(),