From 907e2942bb25f1f0146312ef25c897f5c0661e16 Mon Sep 17 00:00:00 2001 From: david Date: Thu, 9 May 2002 21:56:31 +0000 Subject: [PATCH] Patch from Melchior Franz: Due to jumpy joystick read-outs the UFO jitters a lot in turns. This patch implements simple damping for aileron/elevator/throttle. Furthermore it lets the UFO fly backwards if brake[0] is active (by default associated with the joystick's fire button). After all, everyone knows that UFO's can fly backwards! --- src/FDM/UFO.cxx | 25 +++++++++++++++++++------ src/FDM/UFO.hxx | 4 +++- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/src/FDM/UFO.cxx b/src/FDM/UFO.cxx index 782f699f0..efa296d82 100644 --- a/src/FDM/UFO.cxx +++ b/src/FDM/UFO.cxx @@ -31,8 +31,15 @@ #include "UFO.hxx" - -FGUFO::FGUFO( double dt ) { +const double throttle_damp = 0.05; +const double aileron_damp = 0.01; +const double elevator_damp = 0.01; + +FGUFO::FGUFO( double dt ) + : Throttle(0.0), + Aileron(0.0), + Elevator(0.0) +{ set_delta_t( dt ); } @@ -55,11 +62,17 @@ void FGUFO::update( int multiloop ) { double time_step = get_delta_t() * multiloop; // 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); // the velocity of the aircraft double velocity = Throttle * 2000; // meters/sec @@ -141,7 +154,7 @@ void FGUFO::update( int multiloop ) { // 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, diff --git a/src/FDM/UFO.hxx b/src/FDM/UFO.hxx index aed107e75..8ceecf135 100644 --- a/src/FDM/UFO.hxx +++ b/src/FDM/UFO.hxx @@ -29,7 +29,9 @@ class FGUFO: public FGInterface { - + double Throttle; + double Aileron; + double Elevator; public: FGUFO( double dt ); ~FGUFO(); -- 2.39.5