]> git.mxchange.org Git - flightgear.git/blobdiff - src/Instrumentation/heading_indicator_fg.cxx
ADF: code clean-up/documentation
[flightgear.git] / src / Instrumentation / heading_indicator_fg.cxx
index 23d49da7446b598ea00fba18260e15d94db0cea9..406300f12f01b158fb1519cead55d11a6a2ad28d 100644 (file)
@@ -5,15 +5,24 @@
 //
 // This file is in the Public Domain and comes with no warranty.
 
+#ifdef HAVE_CONFIG_H
+#  include "config.h"
+#endif
+
 #include <simgear/compiler.h>
 #include <iostream>
 #include <string>
 #include <sstream>
 
-#include "heading_indicator_fg.hxx"
+#include <simgear/magvar/magvar.hxx>
+#include <simgear/math/SGMath.hxx>
+
 #include <Main/fg_props.hxx>
-#include <Main/util.hxx>                           
+#include <Main/util.hxx>
 
+#include "heading_indicator_fg.hxx"
+
+using std::string;
 
 HeadingIndicatorFG::HeadingIndicatorFG ( SGPropertyNode *node )
     :
@@ -55,7 +64,10 @@ HeadingIndicatorFG::init ()
        _heading_in_node = fgGetNode("/orientation/heading-deg", true);
 
     SGPropertyNode *node = fgGetNode(branch.c_str(), num, true );
-    _offset_node = node->getChild("offset-deg", 0, true);
+    if( NULL == (_offset_node = node->getChild("offset-deg", 0, false)) ) {
+      _offset_node = node->getChild("offset-deg", 0, true);
+      _offset_node->setDoubleValue( -globals->get_mag()->get_magvar() * SGD_RADIANS_TO_DEGREES );
+    }
     _serviceable_node = node->getChild("serviceable", 0, true);
        _error_node = node->getChild("heading-bug-error-deg", 0, true);
        _nav1_error_node = node->getChild("nav1-course-error-deg", 0, true);
@@ -117,7 +129,7 @@ HeadingIndicatorFG::update (double dt)
 
                                 // Next, calculate the indicated heading,
                                 // introducing errors.
-    double factor = 0.1 / (spin * spin * spin * spin * spin * spin);
+    double factor = 100 * (spin * spin * spin * spin * spin * spin);
     double heading = _heading_in_node->getDoubleValue();
 
                                 // Now, we have to get the current
@@ -128,7 +140,7 @@ HeadingIndicatorFG::update (double dt)
     if ((heading - _last_heading_deg) < -180)
         _last_heading_deg -= 360;
 
-    heading = fgGetLowPass(_last_heading_deg, heading, dt / factor);
+    heading = fgGetLowPass(_last_heading_deg, heading, dt * factor);
     _last_heading_deg = heading;
 
        heading += offset;