]> git.mxchange.org Git - flightgear.git/blobdiff - src/AIModel/AIFlightPlanCreateCruise.cxx
Merge branch 'next' of git://gitorious.org/fg/flightgear into next
[flightgear.git] / src / AIModel / AIFlightPlanCreateCruise.cxx
index d20a2134be25c086e7ac21b538d03a0744f5b61f..269acda945bec5bc919609a8d28f085ac319ec86 100644 (file)
@@ -38,7 +38,6 @@
 #include "AIAircraft.hxx"
 #include "performancedata.hxx"
 
-
 using std::iostream;
 
 void FGAIFlightPlan::evaluateRoutePart(double deplat,
@@ -55,28 +54,18 @@ void FGAIFlightPlan::evaluateRoutePart(double deplat,
   SGGeoc arr(SGGeoc::fromDegM(arrlon, arrlat, 100.0));
   
   SGVec3d a = SGVec3d::fromGeoc(dep);
-  SGVec3d b = SGVec3d::fromGeoc(arr);
-  SGVec3d _cross = cross(b, a);
+  SGVec3d nb = normalize(SGVec3d::fromGeoc(arr));
+  SGVec3d na = normalize(a);
+  
+  SGVec3d _cross = cross(nb, na);
 
-  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.data());
-      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;
-      SGGeod geod = SGGeod::fromCart(SGVec3d(newPos[0], newPos[1], newPos[2]));
+  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(geod);
@@ -311,8 +300,11 @@ void FGAIFlightPlan::createCruise(FGAIAircraft *ac, bool firstFlight, FGAirport
   arr->getDynamics()->getActiveRunway(rwyClass, 2, activeRunway, heading);
   rwy = arr->getRunwayByIdent(activeRunway);
   // begin descent 110km out
-  SGGeod beginDescentPoint = rwy->pointOnCenterline(-110000);
+  SGGeod beginDescentPoint     = rwy->pointOnCenterline(0);
+  SGGeod secondaryDescentPoint = rwy->pointOnCenterline(-10000);
   
-  wpt = createInAir(ac, "BOD", beginDescentPoint, alt, vCruise);
+  wpt = createInAir(ac, "BOD", beginDescentPoint,  alt, vCruise);
+  waypoints.push_back(wpt); 
+  wpt = createInAir(ac, "BOD2", secondaryDescentPoint, alt, vCruise);
   waypoints.push_back(wpt); 
 }