]> git.mxchange.org Git - flightgear.git/commitdiff
Ballistics fix from Vivian Meazza
authortimoore <timoore>
Fri, 28 Dec 2007 22:05:14 +0000 (22:05 +0000)
committertimoore <timoore>
Fri, 28 Dec 2007 22:05:14 +0000 (22:05 +0000)
src/AIModel/AIBallistic.cxx

index 556f20fc6d333ddd9c28ee57dee69ade1e7a39fb..6ade9f411e27c63e232f3dcbc6016a758966bc25 100644 (file)
@@ -375,12 +375,28 @@ void FGAIBallistic::Run(double dt) {
     if (_aero_stabilised) { // we simulate rotational moment of inertia by using a filter
         const double coeff = 0.9;
         double c = dt / (coeff + dt);
+        double recip;
 
+        // calculate the recip
+        if(hdg - 180 < 0){
+            recip = hdg + 180;
+        } else {
+            recip = hdg - 180;
+        }
+        //cout << "recip " << recip << endl;
+
+        // we assume a symetrical MI about the pitch and yaw axis
         pitch = (_elevation * c) + (pitch * (1 - c));
 
-        if (_azimuth - hdg > 180) {
-            hdg = (_azimuth * c) - (hdg * (1 - c));
+        //we need to ensure that we turn the short way to the new hdg
+        if (_azimuth < recip && _azimuth < hdg && hdg > 180) {
+            //cout <<  "_azimuth - hdg 1 " << _azimuth << " " << hdg << endl;
+            hdg = ((_azimuth + 360) * c) + (hdg * (1 - c));
+        } else if (_azimuth > recip && _azimuth > hdg && hdg <= 180){
+            //cout <<  "_azimuth - hdg 2 " << _azimuth <<" " << hdg << endl;
+            hdg = ((_azimuth - 360) * c) + (hdg * (1 - c));
         } else {
+            //cout <<  "_azimuth - hdg 3 " << _azimuth <<" " << hdg << endl;
             hdg = (_azimuth * c) + (hdg * (1 - c));
         }