]> git.mxchange.org Git - flightgear.git/blobdiff - src/Traffic/Schedule.cxx
make --enable-osgviewer the default
[flightgear.git] / src / Traffic / Schedule.cxx
index c136dbfca14935fd3e851d580a8635250f7c0898..ac2a305c4f2b5cc2817c7b3a628a753728b1264b 100644 (file)
@@ -173,9 +173,6 @@ bool FGAISchedule::update(time_t now)
 {
   FGAirport *dep;
   FGAirport *arr;
-  sgdVec3 a, b, cross;
-  sgdVec3 newPos;
-  sgdMat4 matrix;
   double angle;
 
   FGAIManager *aimgr;
@@ -185,7 +182,6 @@ bool FGAISchedule::update(time_t now)
   double distanceToDest;
   double speed;
 
-  Point3D temp;
   time_t 
     totalTimeEnroute, 
     elapsedTimeEnroute,
@@ -235,6 +231,7 @@ bool FGAISchedule::update(time_t now)
   if (!deptime)
     deptime = (*flights.begin())->getDepartureTime();
   FGScheduledFlightVecIterator i = flights.begin();
+  SG_LOG (SG_GENERAL, SG_DEBUG,"Processing registration " << registration << " with callsign " << (*i)->getCallSign());
   if (AIManagerRef)
     {
       // Check if this aircraft has been released. 
@@ -263,7 +260,6 @@ bool FGAISchedule::update(time_t now)
       // object for it. 
       //if ((i->getDepartureTime() < now) && (i->getArrivalTime() > now))
       
-
       // Part of this flight is in the future.
       if ((*i)->getArrivalTime() > now)
        {
@@ -272,28 +268,13 @@ bool FGAISchedule::update(time_t now)
          if (!(dep && arr))
            return false;
          
-         temp = sgPolarToCart3d(Point3D(dep->getLongitude() * 
-                                        SG_DEGREES_TO_RADIANS, 
-                                        dep->getLatitude()  * 
-                                        SG_DEGREES_TO_RADIANS, 
-                                        1.0));
-         a[0] = temp.x();
-         a[1] = temp.y();
-         a[2] = temp.z();
-         
-         temp = sgPolarToCart3d(Point3D(arr->getLongitude() *
-                                        SG_DEGREES_TO_RADIANS,
-                                        arr->getLatitude()  *
-                                        SG_DEGREES_TO_RADIANS, 
-                                        1.0));
-         b[0] = temp.x();
-         b[1] = temp.y();
-         b[2] = temp.z();
-         sgdNormaliseVec3(a);
-         sgdNormaliseVec3(b);
-         sgdVectorProductVec3(cross,b,a);
+          SGVec3d a = SGVec3d::fromGeoc(SGGeoc::fromDegM(dep->getLongitude(),
+                                                dep->getLatitude(), 1));
+          SGVec3d b = SGVec3d::fromGeoc(SGGeoc::fromDegM(arr->getLongitude(),
+                                                arr->getLatitude(), 1));
+          SGVec3d _cross = cross(b, a);
          
-         angle = sgACos(sgdScalarProductVec3(a,b));
+         angle = sgACos(dot(a, b));
          
          // Okay, at this point we have the angle between departure and 
          // arrival airport, in degrees. From here we can interpolate the
@@ -321,23 +302,22 @@ bool FGAISchedule::update(time_t now)
          
          //cout << "a = " << a[0] << " " << a[1] << " " << a[2] 
          //     << "b = " << b[0] << " " << b[1] << " " << b[2] << endl;  
-         sgdMakeRotMat4(matrix, angle, cross); 
+          sgdMat4 matrix;
+         sgdMakeRotMat4(matrix, angle, _cross.sg()); 
+          SGVec3d newPos(0, 0, 0);
          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];
                }
            }
          
-         temp = sgCartToPolar3d(Point3D(newPos[0], newPos[1],newPos[2]));
          if (now > (*i)->getDepartureTime())
            {
-             //cerr << "Lat = " << lat << ", lon = " << lon << endl;
-             //cerr << "Time diff: " << now-i->getDepartureTime() << endl;
-             lat = temp.lat() * SG_RADIANS_TO_DEGREES;
-             lon = temp.lon() * SG_RADIANS_TO_DEGREES; 
+              SGGeoc geoc = SGGeoc::fromCart(newPos);
+             lat = geoc.getLatitudeDeg();
+             lon = geoc.getLongitudeDeg(); 
            }
          else
            {
@@ -348,13 +328,16 @@ bool FGAISchedule::update(time_t now)
          
          SGWayPoint current  (lon,
                               lat,
-                              (*i)->getCruiseAlt());
+                              (*i)->getCruiseAlt(), 
+                              SGWayPoint::SPHERICAL);
          SGWayPoint user (   userLongitude,
                              userLatitude,
-                             (*i)->getCruiseAlt());
+                             (*i)->getCruiseAlt(), 
+                             SGWayPoint::SPHERICAL);
          SGWayPoint dest (   arr->getLongitude(),
                              arr->getLatitude(),
-                             (*i)->getCruiseAlt());
+                             (*i)->getCruiseAlt(), 
+                             SGWayPoint::SPHERICAL);
          // We really only need distance to user
          // and course to destination 
          user.CourseAndDistance(current, &courseToUser, &distanceToUser);
@@ -374,7 +357,7 @@ bool FGAISchedule::update(time_t now)
            {
              string flightPlanName = dep->getId() + string("-") + arr->getId() + 
                string(".xml");
-             int alt;
+             //int alt;
              //if  ((i->getDepartureTime() < now))
              //{
              //          alt = i->getCruiseAlt() *100;
@@ -384,10 +367,15 @@ bool FGAISchedule::update(time_t now)
              //          alt = dep->_elevation+19;
              //        }
 
-             // Only allow traffic to be created when the model path exists
+             // Only allow traffic to be created when the model path (or the AI version of mp) exists
              SGPath mp(globals->get_fg_root());
+             SGPath mp_ai = mp;
+
              mp.append(modelPath);
-             if (mp.exists()) 
+             mp_ai.append("AI");
+             mp_ai.append(modelPath);
+
+             if (mp.exists() || mp_ai.exists())
              {
                  FGAIAircraft *aircraft = new FGAIAircraft(this);
                  aircraft->setPerformance(m_class); //"jet_transport";
@@ -456,8 +444,8 @@ void FGAISchedule::next()
 
 double FGAISchedule::getSpeed()
 {
-  double courseToUser,   courseToDest;
-  double distanceToUser, distanceToDest;
+  double courseToDest;
+  double distanceToDest;
   double speed, remainingTimeEnroute;
   FGAirport *dep, *arr;
 
@@ -469,10 +457,12 @@ double FGAISchedule::getSpeed()
  
   SGWayPoint dest (   dep->getLongitude(),
                      dep->getLatitude(),
-                     (*i)->getCruiseAlt()); 
+                     (*i)->getCruiseAlt(), 
+                     SGWayPoint::SPHERICAL); 
   SGWayPoint curr (    arr->getLongitude(),
                      arr->getLatitude(),
-                      (*i)->getCruiseAlt());
+                      (*i)->getCruiseAlt(), 
+                      SGWayPoint::SPHERICAL);
   remainingTimeEnroute     = (*i)->getArrivalTime() - (*i)->getDepartureTime();
   dest.CourseAndDistance(curr, &courseToDest, &distanceToDest);
   speed =  (distanceToDest*SG_METER_TO_NM) /