]> git.mxchange.org Git - flightgear.git/blobdiff - src/AIModel/AIFlightPlanCreateCruise.cxx
Give the FGAirport class a sane filename.
[flightgear.git] / src / AIModel / AIFlightPlanCreateCruise.cxx
old mode 100755 (executable)
new mode 100644 (file)
index d20a213..beecef8
@@ -14,7 +14,7 @@
  *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301, USA.
  *
  *
  **************************************************************************/
@@ -25,9 +25,8 @@
 
 #include <fstream>
 #include <iostream>
-#include <simgear/route/waypoint.hxx>
 
-#include <Navaids/awynet.hxx>
+#include <Airports/airport.hxx>
 #include <Airports/runways.hxx>
 #include <Airports/dynamics.hxx>
 
@@ -38,9 +37,9 @@
 #include "AIAircraft.hxx"
 #include "performancedata.hxx"
 
-
 using std::iostream;
 
+/*
 void FGAIFlightPlan::evaluateRoutePart(double deplat,
                                       double deplon,
                                       double arrlat,
@@ -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);
@@ -108,7 +97,7 @@ void FGAIFlightPlan::evaluateRoutePart(double deplat,
        }
 }
 
-
+*/
 /*
 void FGAIFlightPlan::createCruise(bool firstFlight, FGAirport *dep,
                                  FGAirport *arr, double latitude,
@@ -137,7 +126,7 @@ void FGAIFlightPlan::createCruise(bool firstFlight, FGAirport *dep,
     init_waypoint->flaps_down= false;
     init_waypoint->finished  = false;
     init_waypoint->on_ground = false;
-    waypoints.push_back(init_waypoint);
+    pushBackWaypoint(init_waypoint);
     routefile.append("Data/AI/FlightPlans");
     snprintf(buffer, 32, "%s-%s.txt",
             dep->getId().c_str(),
@@ -231,7 +220,7 @@ void FGAIFlightPlan::createCruise(bool firstFlight, FGAirport *dep,
            wpt->flaps_down= false;
            wpt->finished  = false;
            wpt->on_ground = false;
-           waypoints.push_back(wpt);
+           pushBackWaypoint(wpt);
          }
 
          if (!(routefile.exists()))
@@ -284,7 +273,7 @@ void FGAIFlightPlan::createCruise(bool firstFlight, FGAirport *dep,
     wpt->flaps_down= false;
     wpt->finished  = false;
     wpt->on_ground = false;
-    waypoints.push_back(wpt);
+    pushBackWaypoint(wpt);
 }
 */
 
@@ -296,23 +285,28 @@ void FGAIFlightPlan::createCruise(bool firstFlight, FGAirport *dep,
  * Note that this is the original version that does not 
  * do any dynamic route computation.
  ******************************************************************/
-void FGAIFlightPlan::createCruise(FGAIAircraft *ac, bool firstFlight, FGAirport *dep, 
+bool FGAIFlightPlan::createCruise(FGAIAircraft *ac, bool firstFlight, FGAirport *dep, 
                                  FGAirport *arr, double latitude, 
                                  double longitude, double speed, 
                                  double alt, const string& fltType)
 {
   double vCruise = ac->getPerformance()->vCruise();
-  waypoint *wpt;
+  FGAIWaypoint *wpt;
   wpt = createInAir(ac, "Cruise", SGGeod::fromDeg(longitude, latitude), alt, vCruise);
-  waypoints.push_back(wpt); 
+  pushBackWaypoint(wpt); 
   
-  string rwyClass = getRunwayClassFromTrafficType(fltType);
+  const string& rwyClass = getRunwayClassFromTrafficType(fltType);
   double heading = ac->getTrafficRef()->getCourse();
   arr->getDynamics()->getActiveRunway(rwyClass, 2, activeRunway, heading);
-  rwy = arr->getRunwayByIdent(activeRunway);
+  FGRunway* rwy = arr->getRunwayByIdent(activeRunway);
+  assert( rwy != NULL );
   // 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);
-  waypoints.push_back(wpt); 
+  wpt = createInAir(ac, "BOD", beginDescentPoint,  alt, vCruise);
+  pushBackWaypoint(wpt); 
+  wpt = createInAir(ac, "BOD2", secondaryDescentPoint, alt, vCruise);
+  pushBackWaypoint(wpt); 
+  return true;
 }