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.
This commit is contained in:
parent
f83fbfdf9c
commit
c1e29d0998
4 changed files with 39 additions and 83 deletions
|
@ -54,7 +54,7 @@ public:
|
||||||
|
|
||||||
} waypoint;
|
} waypoint;
|
||||||
|
|
||||||
FGAIFlightPlan(const string& filename);
|
FGAIFlightPlan(const string& filename);
|
||||||
FGAIFlightPlan(const std::string& p,
|
FGAIFlightPlan(const std::string& p,
|
||||||
double course,
|
double course,
|
||||||
time_t start,
|
time_t start,
|
||||||
|
@ -83,26 +83,26 @@ public:
|
||||||
double getLeadDistance( void ) const {return lead_distance;}
|
double getLeadDistance( void ) const {return lead_distance;}
|
||||||
double getBearing(waypoint* previous, waypoint* next) const;
|
double getBearing(waypoint* previous, waypoint* next) const;
|
||||||
double getBearing(double lat, double lon, 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,
|
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);
|
bool firstLeg, double radius, const string& fltType, const string& aircraftType, const string& airline);
|
||||||
|
|
||||||
void setLeg(int val) { leg = val;};
|
void setLeg(int val) { leg = val;}
|
||||||
void setTime(time_t st) { start_time = st; };
|
void setTime(time_t st) { start_time = st; }
|
||||||
int getGate() const { return gateId; };
|
int getGate() const { return gateId; }
|
||||||
double getLeadInAngle() const { return leadInAngle; };
|
double getLeadInAngle() const { return leadInAngle; }
|
||||||
const string& getRunway() const { return rwy._rwy_no; };
|
const string& getRunway() const { return rwy._rwy_no; }
|
||||||
const string& getRunwayId() const { return rwy._id; };
|
const string& getRunwayId() const { return rwy._id; }
|
||||||
void setRepeat(bool r) { repeat = r; };
|
void setRepeat(bool r) { repeat = r; }
|
||||||
bool getRepeat(void) const { return repeat; };
|
bool getRepeat(void) const { return repeat; }
|
||||||
void restart(void);
|
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.
|
int getRouteIndex(int i); // returns the AI related index of this current routes.
|
||||||
FGTaxiRoute *getTaxiRoute() { return taxiRoute; };
|
FGTaxiRoute *getTaxiRoute() { return taxiRoute; }
|
||||||
void deleteTaxiRoute();
|
void deleteTaxiRoute();
|
||||||
string getRunway() { return activeRunway; };
|
string getRunway() { return activeRunway; }
|
||||||
bool isActive(time_t time) {return time >= this->getStartTime();};
|
bool isActive(time_t time) {return time >= this->getStartTime();}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
FGRunway rwy;
|
FGRunway rwy;
|
||||||
|
@ -116,22 +116,13 @@ private:
|
||||||
double distance_to_go;
|
double distance_to_go;
|
||||||
double lead_distance;
|
double lead_distance;
|
||||||
double leadInAngle;
|
double leadInAngle;
|
||||||
time_t start_time;
|
time_t start_time;
|
||||||
int leg;
|
int leg;
|
||||||
int gateId;
|
int gateId;
|
||||||
string activeRunway;
|
string activeRunway;
|
||||||
FGAirRoute airRoute;
|
FGAirRoute airRoute;
|
||||||
FGTaxiRoute *taxiRoute;
|
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 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 createTaxi(bool, int, FGAirport *, double, double, double, const string&, const string&, const string&);
|
||||||
void createTakeOff(bool, FGAirport *, double, const string&);
|
void createTakeOff(bool, FGAirport *, double, const string&);
|
||||||
|
@ -149,6 +140,4 @@ private:
|
||||||
void evaluateRoutePart(double deplat, double deplon, double arrlat, double arrlon);
|
void evaluateRoutePart(double deplat, double deplon, double arrlat, double arrlon);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif // _FG_AIFLIGHTPLAN_HXX
|
#endif // _FG_AIFLIGHTPLAN_HXX
|
||||||
|
|
|
@ -50,35 +50,22 @@ void FGAIFlightPlan::evaluateRoutePart(double deplat,
|
||||||
SGWayPoint sec (arrlon,
|
SGWayPoint sec (arrlon,
|
||||||
arrlat,
|
arrlat,
|
||||||
100);
|
100);
|
||||||
|
double course, distance;
|
||||||
first.CourseAndDistance(sec, &course, &distance);
|
first.CourseAndDistance(sec, &course, &distance);
|
||||||
distance *= SG_METER_TO_NM;
|
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 *
|
SGVec3d a = SGVec3d::fromGeoc(SGGeoc::fromDegM(deplon, deplat, 1));
|
||||||
SG_DEGREES_TO_RADIANS,
|
SGVec3d b = SGVec3d::fromGeoc(SGGeoc::fromDegM(arrlon, arrlat, 1));
|
||||||
arrlat *
|
SGVec3d _cross = cross(b, a);
|
||||||
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));
|
double angle = sgACos(dot(a, b));
|
||||||
tmpNode = 0;
|
tmpNode = 0;
|
||||||
for (double ang = 0.0; ang < angle; ang += 0.05)
|
for (double ang = 0.0; ang < angle; ang += 0.05)
|
||||||
{
|
{
|
||||||
|
sgdVec3 newPos;
|
||||||
|
sgdMat4 matrix;
|
||||||
//cerr << "Angle = " << ang << endl;
|
//cerr << "Angle = " << ang << endl;
|
||||||
sgdMakeRotMat4(matrix, ang, cross);
|
sgdMakeRotMat4(matrix, ang, _cross.sg());
|
||||||
for(int j = 0; j < 3; j++)
|
for(int j = 0; j < 3; j++)
|
||||||
{
|
{
|
||||||
newPos[j] =0.0;
|
newPos[j] =0.0;
|
||||||
|
@ -88,9 +75,9 @@ void FGAIFlightPlan::evaluateRoutePart(double deplat,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//cerr << "1"<< endl;
|
//cerr << "1"<< endl;
|
||||||
temp = sgCartToPolar3d(Point3D(newPos[0], newPos[1],newPos[2]));
|
SGGeoc geoc = SGGeoc::fromCart(SGVec3d(newPos[0], newPos[1], newPos[2]));
|
||||||
midlat = temp.lat() * SG_RADIANS_TO_DEGREES;
|
double midlat = geoc.getLatitudeDeg();
|
||||||
midlon = temp.lon() * SG_RADIANS_TO_DEGREES;
|
double midlon = geoc.getLongitudeDeg();
|
||||||
|
|
||||||
prevNode = tmpNode;
|
prevNode = tmpNode;
|
||||||
tmpNode = globals->get_airwaynet()->findNearestNode(midlat, midlon);
|
tmpNode = globals->get_airwaynet()->findNearestNode(midlat, midlon);
|
||||||
|
|
|
@ -79,4 +79,4 @@ void FGAITanker::update(double dt) {
|
||||||
FGAIAircraft::update(dt);
|
FGAIAircraft::update(dt);
|
||||||
Run(dt);
|
Run(dt);
|
||||||
Transform();
|
Transform();
|
||||||
}
|
}
|
||||||
|
|
|
@ -173,9 +173,6 @@ bool FGAISchedule::update(time_t now)
|
||||||
{
|
{
|
||||||
FGAirport *dep;
|
FGAirport *dep;
|
||||||
FGAirport *arr;
|
FGAirport *arr;
|
||||||
sgdVec3 a, b, cross;
|
|
||||||
sgdVec3 newPos;
|
|
||||||
sgdMat4 matrix;
|
|
||||||
double angle;
|
double angle;
|
||||||
|
|
||||||
FGAIManager *aimgr;
|
FGAIManager *aimgr;
|
||||||
|
@ -185,7 +182,6 @@ bool FGAISchedule::update(time_t now)
|
||||||
double distanceToDest;
|
double distanceToDest;
|
||||||
double speed;
|
double speed;
|
||||||
|
|
||||||
Point3D temp;
|
|
||||||
time_t
|
time_t
|
||||||
totalTimeEnroute,
|
totalTimeEnroute,
|
||||||
elapsedTimeEnroute,
|
elapsedTimeEnroute,
|
||||||
|
@ -272,28 +268,13 @@ bool FGAISchedule::update(time_t now)
|
||||||
if (!(dep && arr))
|
if (!(dep && arr))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
temp = sgPolarToCart3d(Point3D(dep->getLongitude() *
|
SGVec3d a = SGVec3d::fromGeoc(SGGeoc::fromDegM(dep->getLongitude(),
|
||||||
SG_DEGREES_TO_RADIANS,
|
dep->getLatitude(), 1));
|
||||||
dep->getLatitude() *
|
SGVec3d b = SGVec3d::fromGeoc(SGGeoc::fromDegM(arr->getLongitude(),
|
||||||
SG_DEGREES_TO_RADIANS,
|
arr->getLatitude(), 1));
|
||||||
1.0));
|
SGVec3d _cross = cross(b, a);
|
||||||
a[0] = temp.x();
|
|
||||||
a[1] = temp.y();
|
|
||||||
a[2] = temp.z();
|
|
||||||
|
|
||||||
temp = sgPolarToCart3d(Point3D(arr->getLongitude() *
|
angle = sgACos(dot(a, b));
|
||||||
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));
|
|
||||||
|
|
||||||
// Okay, at this point we have the angle between departure and
|
// Okay, at this point we have the angle between departure and
|
||||||
// arrival airport, in degrees. From here we can interpolate the
|
// 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]
|
//cout << "a = " << a[0] << " " << a[1] << " " << a[2]
|
||||||
// << "b = " << b[0] << " " << b[1] << " " << b[2] << endl;
|
// << "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++)
|
for(int j = 0; j < 3; j++)
|
||||||
{
|
{
|
||||||
newPos[j] =0.0;
|
|
||||||
for (int k = 0; k<3; k++)
|
for (int k = 0; k<3; k++)
|
||||||
{
|
{
|
||||||
newPos[j] += matrix[j][k]*a[k];
|
newPos[j] += matrix[j][k]*a[k];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
temp = sgCartToPolar3d(Point3D(newPos[0], newPos[1],newPos[2]));
|
|
||||||
if (now > (*i)->getDepartureTime())
|
if (now > (*i)->getDepartureTime())
|
||||||
{
|
{
|
||||||
//cerr << "Lat = " << lat << ", lon = " << lon << endl;
|
SGGeoc geoc = SGGeoc::fromCart(newPos);
|
||||||
//cerr << "Time diff: " << now-i->getDepartureTime() << endl;
|
lat = geoc.getLatitudeDeg();
|
||||||
lat = temp.lat() * SG_RADIANS_TO_DEGREES;
|
lon = geoc.getLongitudeDeg();
|
||||||
lon = temp.lon() * SG_RADIANS_TO_DEGREES;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Reference in a new issue