]> git.mxchange.org Git - flightgear.git/blobdiff - src/AIModel/AIFlightPlanCreateCruise.cxx
Fix crashes (activating the route-manager) with a default GPS.
[flightgear.git] / src / AIModel / AIFlightPlanCreateCruise.cxx
old mode 100755 (executable)
new mode 100644 (file)
index 8d9cc8d..13df4b6
@@ -38,7 +38,6 @@
 #include "AIAircraft.hxx"
 #include "performancedata.hxx"
 
-
 using std::iostream;
 
 void FGAIFlightPlan::evaluateRoutePart(double deplat,
@@ -51,57 +50,31 @@ void FGAIFlightPlan::evaluateRoutePart(double deplat,
   intVec nodes;
   int tmpNode, prevNode;
 
+  SGGeoc dep(SGGeoc::fromDegM(deplon, deplat, 100.0));
+  SGGeoc arr(SGGeoc::fromDegM(arrlon, arrlat, 100.0));
+  
+  SGVec3d a = SGVec3d::fromGeoc(dep);
+  SGVec3d nb = normalize(SGVec3d::fromGeoc(arr));
+  SGVec3d na = normalize(a);
+  
+  SGVec3d _cross = cross(nb, na);
 
-  SGWayPoint first (deplon,
-                   deplat,
-                   100);
-  SGWayPoint sec (arrlon,
-                 arrlat,
-                 100);
-  double course, distance;
-  first.CourseAndDistance(sec, &course, &distance);
-  distance *= SG_METER_TO_NM;
-
-  SGVec3d a = SGVec3d::fromGeoc(SGGeoc::fromDegM(deplon, deplat, 1));
-  SGVec3d b = SGVec3d::fromGeoc(SGGeoc::fromDegM(arrlon, arrlat, 1));
-  SGVec3d _cross = cross(b, a);
-
-  double angle = sgACos(dot(a, b));
+  double angle = acos(dot(na, nb));
+  const double angleStep = 0.05 * SG_DEGREES_TO_RADIANS;
   tmpNode = 0;
-  for (double ang = 0.0; ang < angle; ang += 0.05)
-    {
-      sgdVec3 newPos;
-      sgdMat4 matrix;
-      //cerr << "Angle = " << ang << endl;
-      sgdMakeRotMat4(matrix, ang, _cross.sg());
-      for(int j = 0; j < 3; j++)
-       {
-         newPos[j] =0.0;
-         for (int k = 0; k<3; k++)
-           {
-             newPos[j] += matrix[j][k]*a[k];
-           }
-       }
-      //cerr << "1"<< endl;
-      SGGeoc geoc = SGGeoc::fromCart(SGVec3d(newPos[0], newPos[1], newPos[2]));
-
-      double midlat = geoc.getLatitudeDeg();
-      double midlon = geoc.getLongitudeDeg();
+  for (double ang = 0.0; ang < angle; ang += angleStep)
+  {  
+      SGQuatd q = SGQuatd::fromAngleAxis(ang, _cross);
+      SGGeod geod = SGGeod::fromCart(q.transform(a));
 
       prevNode = tmpNode;
-      tmpNode = globals->get_airwaynet()->findNearestNode(midlat, midlon);
+      tmpNode = globals->get_airwaynet()->findNearestNode(geod);
 
-      double nodelat = globals->get_airwaynet()->findNode(tmpNode)->getLatitude  ();
-      double nodelon = globals->get_airwaynet()->findNode(tmpNode)->getLongitude ();
-      SGWayPoint curr(midlat,
-                     midlon,
-                     100);
-      SGWayPoint node(nodelat,
-                     nodelon,
-                     100);
-      curr.CourseAndDistance(node, &course, &distance);
-      if ((distance < 25000) && (tmpNode != prevNode))
-       nodes.push_back(tmpNode);
+      FGNode* node = globals->get_airwaynet()->findNode(tmpNode);
+    
+      if ((tmpNode != prevNode) && (SGGeodesy::distanceM(geod, node->getPosition()) < 25000)) {
+        nodes.push_back(tmpNode);
+      }
     }
 
     intVecIterator i = nodes.begin();