X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FAIModel%2FAIFlightPlanCreateCruise.cxx;h=87592197b9ee5c476b29a95d9eb4de2026f1eda0;hb=1eb8d0caa4632b5c99d6a1889bfad60288c38772;hp=4f44ab1e25d3d160574ceef01bc09ab8e39306b9;hpb=c779c2ac21f9fcc58cd3cebc9a8f1c126e48d69c;p=flightgear.git diff --git a/src/AIModel/AIFlightPlanCreateCruise.cxx b/src/AIModel/AIFlightPlanCreateCruise.cxx index 4f44ab1e2..87592197b 100644 --- a/src/AIModel/AIFlightPlanCreateCruise.cxx +++ b/src/AIModel/AIFlightPlanCreateCruise.cxx @@ -27,7 +27,7 @@ #include #include -#include +#include #include #include @@ -38,9 +38,9 @@ #include "AIAircraft.hxx" #include "performancedata.hxx" - using std::iostream; +/* void FGAIFlightPlan::evaluateRoutePart(double deplat, double deplon, double arrlat, @@ -55,39 +55,25 @@ 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; - 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); FGNode* node = globals->get_airwaynet()->findNode(tmpNode); - SGGeoc nodePos(SGGeoc::fromGeod(node->getPosition())); - if ((tmpNode != prevNode) && (SGGeodesy::distanceM(geoc, nodePos) < 25000)) { + if ((tmpNode != prevNode) && (SGGeodesy::distanceM(geod, node->getPosition()) < 25000)) { nodes.push_back(tmpNode); } } @@ -112,7 +98,7 @@ void FGAIFlightPlan::evaluateRoutePart(double deplat, } } - +*/ /* void FGAIFlightPlan::createCruise(bool firstFlight, FGAirport *dep, FGAirport *arr, double latitude, @@ -141,7 +127,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(), @@ -235,7 +221,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())) @@ -288,7 +274,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); } */ @@ -300,23 +286,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); 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; }