From c1e29d09981dfcd47ff213069fbe8fd5c8ccaf0c Mon Sep 17 00:00:00 2001 From: frohlich Date: Sun, 8 Jul 2007 08:46:29 +0000 Subject: [PATCH] Modified Files: src/AIModel/AIFlightPlan.hxx src/AIModel/AIFlightPlanCreateCruise.cxx src/AIModel/AITanker.cxx src/Traffic/Schedule.cxx: Move member variables that should better be in function local scope into the functions. Make more use of SGMath functions. --- src/AIModel/AIFlightPlan.hxx | 41 ++++++++-------------- src/AIModel/AIFlightPlanCreateCruise.cxx | 35 ++++++------------- src/AIModel/AITanker.cxx | 2 +- src/Traffic/Schedule.cxx | 44 +++++++----------------- 4 files changed, 39 insertions(+), 83 deletions(-) diff --git a/src/AIModel/AIFlightPlan.hxx b/src/AIModel/AIFlightPlan.hxx index d84007866..96fc03002 100644 --- a/src/AIModel/AIFlightPlan.hxx +++ b/src/AIModel/AIFlightPlan.hxx @@ -54,7 +54,7 @@ public: } waypoint; - FGAIFlightPlan(const string& filename); + FGAIFlightPlan(const string& filename); FGAIFlightPlan(const std::string& p, double course, time_t start, @@ -83,26 +83,26 @@ public: double getLeadDistance( void ) const {return lead_distance;} double getBearing(waypoint* previous, waypoint* next) const; double getBearing(double lat, double lon, waypoint* next) const; - time_t getStartTime() const { return start_time; }; + time_t getStartTime() const { return start_time; } void create(FGAirport *dep, FGAirport *arr, int leg, double alt, double speed, double lat, double lon, bool firstLeg, double radius, const string& fltType, const string& aircraftType, const string& airline); - void setLeg(int val) { leg = val;}; - void setTime(time_t st) { start_time = st; }; - int getGate() const { return gateId; }; - double getLeadInAngle() const { return leadInAngle; }; - const string& getRunway() const { return rwy._rwy_no; }; - const string& getRunwayId() const { return rwy._id; }; - void setRepeat(bool r) { repeat = r; }; - bool getRepeat(void) const { return repeat; }; + void setLeg(int val) { leg = val;} + void setTime(time_t st) { start_time = st; } + int getGate() const { return gateId; } + double getLeadInAngle() const { return leadInAngle; } + const string& getRunway() const { return rwy._rwy_no; } + const string& getRunwayId() const { return rwy._id; } + void setRepeat(bool r) { repeat = r; } + bool getRepeat(void) const { return repeat; } void restart(void); - int getNrOfWayPoints() { return waypoints.size(); }; + int getNrOfWayPoints() { return waypoints.size(); } int getRouteIndex(int i); // returns the AI related index of this current routes. - FGTaxiRoute *getTaxiRoute() { return taxiRoute; }; + FGTaxiRoute *getTaxiRoute() { return taxiRoute; } void deleteTaxiRoute(); - string getRunway() { return activeRunway; }; - bool isActive(time_t time) {return time >= this->getStartTime();}; + string getRunway() { return activeRunway; } + bool isActive(time_t time) {return time >= this->getStartTime();} private: FGRunway rwy; @@ -116,22 +116,13 @@ private: double distance_to_go; double lead_distance; double leadInAngle; - time_t start_time; + time_t start_time; int leg; int gateId; string activeRunway; FGAirRoute airRoute; FGTaxiRoute *taxiRoute; - - Point3D temp; - sgdVec3 a, b, cross; - sgdVec3 newPos; - sgdMat4 matrix; - double angle; - double midlat, midlon; - double course, distance; - void createPushBack(bool, FGAirport*, double, double, double, const string&, const string&, const string&); void createTaxi(bool, int, FGAirport *, double, double, double, const string&, const string&, const string&); void createTakeOff(bool, FGAirport *, double, const string&); @@ -149,6 +140,4 @@ private: void evaluateRoutePart(double deplat, double deplon, double arrlat, double arrlon); }; - - #endif // _FG_AIFLIGHTPLAN_HXX diff --git a/src/AIModel/AIFlightPlanCreateCruise.cxx b/src/AIModel/AIFlightPlanCreateCruise.cxx index 21767757e..f9f39a518 100755 --- a/src/AIModel/AIFlightPlanCreateCruise.cxx +++ b/src/AIModel/AIFlightPlanCreateCruise.cxx @@ -50,35 +50,22 @@ void FGAIFlightPlan::evaluateRoutePart(double deplat, SGWayPoint sec (arrlon, arrlat, 100); + double course, distance; first.CourseAndDistance(sec, &course, &distance); distance *= SG_METER_TO_NM; - temp = sgPolarToCart3d(Point3D(deplon * - SG_DEGREES_TO_RADIANS, - deplat * - SG_DEGREES_TO_RADIANS, - 1.0)); - a[0] = temp.x(); - a[1] = temp.y(); - a[2] = temp.z(); - temp = sgPolarToCart3d(Point3D(arrlon * - SG_DEGREES_TO_RADIANS, - arrlat * - 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(deplon, deplat, 1)); + SGVec3d b = SGVec3d::fromGeoc(SGGeoc::fromDegM(arrlon, arrlat, 1)); + SGVec3d _cross = cross(b, a); - angle = sgACos(sgdScalarProductVec3(a,b)); + double angle = sgACos(dot(a, b)); tmpNode = 0; for (double ang = 0.0; ang < angle; ang += 0.05) { + sgdVec3 newPos; + sgdMat4 matrix; //cerr << "Angle = " << ang << endl; - sgdMakeRotMat4(matrix, ang, cross); + sgdMakeRotMat4(matrix, ang, _cross.sg()); for(int j = 0; j < 3; j++) { newPos[j] =0.0; @@ -88,9 +75,9 @@ void FGAIFlightPlan::evaluateRoutePart(double deplat, } } //cerr << "1"<< endl; - temp = sgCartToPolar3d(Point3D(newPos[0], newPos[1],newPos[2])); - midlat = temp.lat() * SG_RADIANS_TO_DEGREES; - midlon = temp.lon() * SG_RADIANS_TO_DEGREES; + SGGeoc geoc = SGGeoc::fromCart(SGVec3d(newPos[0], newPos[1], newPos[2])); + double midlat = geoc.getLatitudeDeg(); + double midlon = geoc.getLongitudeDeg(); prevNode = tmpNode; tmpNode = globals->get_airwaynet()->findNearestNode(midlat, midlon); diff --git a/src/AIModel/AITanker.cxx b/src/AIModel/AITanker.cxx index b0e6db43f..b123c4512 100644 --- a/src/AIModel/AITanker.cxx +++ b/src/AIModel/AITanker.cxx @@ -79,4 +79,4 @@ void FGAITanker::update(double dt) { FGAIAircraft::update(dt); Run(dt); Transform(); -} \ No newline at end of file +} diff --git a/src/Traffic/Schedule.cxx b/src/Traffic/Schedule.cxx index 13b2dce5f..35a1e44c9 100644 --- a/src/Traffic/Schedule.cxx +++ b/src/Traffic/Schedule.cxx @@ -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, @@ -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(); + 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); - 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); - - 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 { -- 2.39.5