]> git.mxchange.org Git - flightgear.git/commitdiff
Patch from Melchior Franz:
authordavid <david>
Thu, 9 May 2002 21:56:31 +0000 (21:56 +0000)
committerdavid <david>
Thu, 9 May 2002 21:56:31 +0000 (21:56 +0000)
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
src/FDM/UFO.hxx

index 782f699f07a4326ee60d9ec0bb0f8757f32fc634..efa296d82af2000e5310e152a1c9c72b432a915d 100644 (file)
 
 #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,
index aed107e752a786e2ede2b03bdc7c1dc0cda0217b..8ceecf1357a1d1e63857510d3d6a892ed3714e22 100644 (file)
@@ -29,7 +29,9 @@
 
 
 class FGUFO: public FGInterface {
-
+    double Throttle;
+    double Aileron;
+    double Elevator;
 public:
     FGUFO( double dt );
     ~FGUFO();