]> git.mxchange.org Git - flightgear.git/blobdiff - src/FDM/UFO.cxx
Fix line endings
[flightgear.git] / src / FDM / UFO.cxx
index efa296d82af2000e5310e152a1c9c72b432a915d..ede9452d156d1f2bdbb78a7a27920d156f3d2f55 100644 (file)
@@ -3,7 +3,7 @@
 // Written by Curtis Olson, started October 1999.
 // Slightly modified from MagicCarpet.cxx by Jonathan Polley, April 2002
 //
-// Copyright (C) 1999-2002  Curtis L. Olson  - curt@flightgear.org
+// Copyright (C) 1999-2002  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
 //
 
 
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+
 #include <simgear/math/sg_geodesy.hxx>
 #include <simgear/math/point3d.hxx>
 #include <simgear/math/polar3d.hxx>
 
-#include <Controls/controls.hxx>
+#include <Aircraft/controls.hxx>
 #include <Main/globals.hxx>
 #include <Main/fg_props.hxx>
 
 #include "UFO.hxx"
 
-const double throttle_damp = 0.05;
-const double aileron_damp = 0.01;
-const double elevator_damp = 0.01;
+const double throttle_damp = 0.2;
+const double aileron_damp = 0.05;
+const double elevator_damp = 0.05;
+const double elevator_trim_damp = 0.05;
+const double rudder_damp = 0.4;
 
 FGUFO::FGUFO( double dt )
   : Throttle(0.0),
     Aileron(0.0),
-    Elevator(0.0)
+    Elevator(0.0),
+    Elevator_Trim(0.0),
+    Rudder(0.0)
 {
-    set_delta_t( dt );
+//     set_delta_t( dt );
 }
 
 
@@ -56,14 +64,19 @@ 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 th = globals->get_controls()->get_throttle( 0 );
-    if (globals->get_controls()->get_brake(0)) {
+    if ( globals->get_controls()->get_brake_left() > 0.0 
+         || globals->get_controls()->get_brake_right() > 0.0 )
+    {
         th = -th;
     }
     Throttle = th * throttle_damp + Throttle * (1 - throttle_damp);
@@ -73,13 +86,18 @@ void FGUFO::update( int multiloop ) {
                + Aileron * (1 - aileron_damp);
     Elevator = globals->get_controls()->get_elevator() * elevator_damp
                + Elevator * (1 - elevator_damp);
+    Elevator_Trim = globals->get_controls()->get_elevator_trim()
+                    * elevator_trim_damp
+                    + Elevator_Trim * (1 - elevator_trim_damp);
+    Rudder = globals->get_controls()->get_rudder() * rudder_damp
+               + Rudder * (1 - rudder_damp);
 
     // the velocity of the aircraft
     double velocity = Throttle * 2000; // meters/sec
 
     double old_pitch = get_Theta();
     double pitch_rate = SGD_PI_4; // assume I will be pitching up
-    double target_pitch = -Elevator * SGD_PI_2;
+    double target_pitch = (-Elevator - Elevator_Trim) * SGD_PI_2;
 
     // if I am pitching down
     if (old_pitch > target_pitch)
@@ -151,6 +169,7 @@ 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;
@@ -174,13 +193,14 @@ 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(), 
                             sl_radius + get_Altitude() + climb );
     // cout << "sea level radius (ft) = " << sl_radius << endl;
     // cout << "(setto) sea level radius (ft) = " << get_Sea_level_radius() << endl;
+    _update_ground_elev_at_pos();
     _set_Sea_level_radius( sl_radius * SG_METER_TO_FEET);
     _set_Altitude( get_Altitude() + climb );
 }