More use of SGGeo[dc].
This commit is contained in:
parent
7327e35020
commit
c2d8dcc18b
13 changed files with 81 additions and 98 deletions
|
@ -180,7 +180,7 @@ void FGAIAircraft::Run(double dt) {
|
||||||
doGroundAltitude();
|
doGroundAltitude();
|
||||||
//cerr << " Actual altitude " << altitude << endl;
|
//cerr << " Actual altitude " << altitude << endl;
|
||||||
// Transform();
|
// Transform();
|
||||||
pos.setelev(altitude * SG_FEET_TO_METER);
|
pos.setElevationFt(altitude);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -219,8 +219,8 @@ void FGAIAircraft::Run(double dt) {
|
||||||
* speed * 1.686 / ft_per_deg_lon;
|
* speed * 1.686 / ft_per_deg_lon;
|
||||||
|
|
||||||
// set new position
|
// set new position
|
||||||
pos.setlat( pos.lat() + speed_north_deg_sec * dt);
|
pos.setLatitudeDeg( pos.getLatitudeDeg() + speed_north_deg_sec * dt);
|
||||||
pos.setlon( pos.lon() + speed_east_deg_sec * dt);
|
pos.setLongitudeDeg( pos.getLongitudeDeg() + speed_east_deg_sec * dt);
|
||||||
//if (!(finite(pos.lat()) && finite(pos.lon())))
|
//if (!(finite(pos.lat()) && finite(pos.lon())))
|
||||||
// {
|
// {
|
||||||
// cerr << "Position is not finite" << endl;
|
// cerr << "Position is not finite" << endl;
|
||||||
|
@ -361,7 +361,7 @@ void FGAIAircraft::Run(double dt) {
|
||||||
|
|
||||||
// adjust altitude (meters) based on current vertical speed (fpm)
|
// adjust altitude (meters) based on current vertical speed (fpm)
|
||||||
altitude += vs / 60.0 * dt;
|
altitude += vs / 60.0 * dt;
|
||||||
pos.setelev(altitude * SG_FEET_TO_METER);
|
pos.setElevationFt(altitude);
|
||||||
double altitude_ft = altitude;
|
double altitude_ft = altitude;
|
||||||
|
|
||||||
// adjust target Altitude, based on ground elevation when on ground
|
// adjust target Altitude, based on ground elevation when on ground
|
||||||
|
@ -564,7 +564,7 @@ void FGAIAircraft::ProcessFlightPlan( double dt, time_t now ) {
|
||||||
if (curr->crossat > -1000.0) { //use a calculated descent/climb rate
|
if (curr->crossat > -1000.0) { //use a calculated descent/climb rate
|
||||||
use_perf_vs = false;
|
use_perf_vs = false;
|
||||||
tgt_vs = (curr->crossat - prev->altitude)
|
tgt_vs = (curr->crossat - prev->altitude)
|
||||||
/ (fp->getDistanceToGo(pos.lat(), pos.lon(), curr)
|
/ (fp->getDistanceToGo(pos.getLatitudeDeg(), pos.getLongitudeDeg(), curr)
|
||||||
/ 6076.0 / prev->speed*60.0);
|
/ 6076.0 / prev->speed*60.0);
|
||||||
tgt_altitude = curr->crossat;
|
tgt_altitude = curr->crossat;
|
||||||
} else {
|
} else {
|
||||||
|
@ -597,7 +597,7 @@ void FGAIAircraft::ProcessFlightPlan( double dt, time_t now ) {
|
||||||
dt_count = 0;
|
dt_count = 0;
|
||||||
}
|
}
|
||||||
// check to see if we've reached the lead point for our next turn
|
// check to see if we've reached the lead point for our next turn
|
||||||
double dist_to_go = fp->getDistanceToGo(pos.lat(), pos.lon(), curr);
|
double dist_to_go = fp->getDistanceToGo(pos.getLatitudeDeg(), pos.getLongitudeDeg(), curr);
|
||||||
|
|
||||||
//cerr << "2" << endl;
|
//cerr << "2" << endl;
|
||||||
double lead_dist = fp->getLeadDistance();
|
double lead_dist = fp->getLeadDistance();
|
||||||
|
@ -666,7 +666,7 @@ void FGAIAircraft::ProcessFlightPlan( double dt, time_t now ) {
|
||||||
double userLatitude = fgGetDouble("/position/latitude-deg");
|
double userLatitude = fgGetDouble("/position/latitude-deg");
|
||||||
double userLongitude = fgGetDouble("/position/longitude-deg");
|
double userLongitude = fgGetDouble("/position/longitude-deg");
|
||||||
double course, distance;
|
double course, distance;
|
||||||
SGWayPoint current (pos.lon(), pos.lat(), 0);
|
SGWayPoint current(pos.getLongitudeDeg(), pos.getLatitudeDeg(), 0);
|
||||||
SGWayPoint user (userLongitude, userLatitude, 0);
|
SGWayPoint user (userLongitude, userLatitude, 0);
|
||||||
user.CourseAndDistance(current, &course, &distance);
|
user.CourseAndDistance(current, &course, &distance);
|
||||||
if ((distance * SG_METER_TO_NM) > TRAFFICTOAIDIST) {
|
if ((distance * SG_METER_TO_NM) > TRAFFICTOAIDIST) {
|
||||||
|
@ -736,7 +736,7 @@ void FGAIAircraft::ProcessFlightPlan( double dt, time_t now ) {
|
||||||
if (curr->crossat > -1000.0) {
|
if (curr->crossat > -1000.0) {
|
||||||
//cerr << "5.1a" << endl;
|
//cerr << "5.1a" << endl;
|
||||||
use_perf_vs = false;
|
use_perf_vs = false;
|
||||||
tgt_vs = (curr->crossat - altitude) / (fp->getDistanceToGo(pos.lat(), pos.lon(), curr)
|
tgt_vs = (curr->crossat - altitude) / (fp->getDistanceToGo(pos.getLatitudeDeg(), pos.getLongitudeDeg(), curr)
|
||||||
/ 6076.0 / speed*60.0);
|
/ 6076.0 / speed*60.0);
|
||||||
//cerr << "5.1b" << endl;
|
//cerr << "5.1b" << endl;
|
||||||
tgt_altitude = curr->crossat;
|
tgt_altitude = curr->crossat;
|
||||||
|
@ -757,7 +757,7 @@ void FGAIAircraft::ProcessFlightPlan( double dt, time_t now ) {
|
||||||
//cout << " Target heading: " << tgt_heading << endl << endl;
|
//cout << " Target heading: " << tgt_heading << endl << endl;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
double calc_bearing = fp->getBearing(pos.lat(), pos.lon(), curr);
|
double calc_bearing = fp->getBearing(pos.getLatitudeDeg(), pos.getLongitudeDeg(), curr);
|
||||||
//cerr << "Bearing = " << calc_bearing << endl;
|
//cerr << "Bearing = " << calc_bearing << endl;
|
||||||
if (speed < 0) {
|
if (speed < 0) {
|
||||||
calc_bearing +=180;
|
calc_bearing +=180;
|
||||||
|
@ -774,7 +774,7 @@ void FGAIAircraft::ProcessFlightPlan( double dt, time_t now ) {
|
||||||
} else {
|
} else {
|
||||||
cerr << "calc_bearing is not a finite number : "
|
cerr << "calc_bearing is not a finite number : "
|
||||||
<< "Speed " << speed
|
<< "Speed " << speed
|
||||||
<< "pos : " << pos.lat() << ", " << pos.lon()
|
<< "pos : " << pos.getLatitudeDeg() << ", " << pos.getLongitudeDeg()
|
||||||
<< "waypoint " << curr->latitude << ", " << curr->longitude << endl;
|
<< "waypoint " << curr->latitude << ", " << curr->longitude << endl;
|
||||||
cerr << "waypoint name " << curr->name;
|
cerr << "waypoint name " << curr->name;
|
||||||
exit(1); // FIXME
|
exit(1); // FIXME
|
||||||
|
@ -924,7 +924,7 @@ void FGAIAircraft::getGroundElev(double dt) {
|
||||||
|
|
||||||
//Point3D currView(vw->getLongitude_deg(),
|
//Point3D currView(vw->getLongitude_deg(),
|
||||||
// vw->getLatitude_deg(), 0.0);
|
// vw->getLatitude_deg(), 0.0);
|
||||||
SGWayPoint current (pos.lon(), pos.lat(), 0);
|
SGWayPoint current(pos.getLongitudeDeg(), pos.getLatitudeDeg(), 0);
|
||||||
SGWayPoint view (vw->getLongitude_deg(), vw->getLatitude_deg(), 0);
|
SGWayPoint view (vw->getLongitude_deg(), vw->getLatitude_deg(), 0);
|
||||||
view.CourseAndDistance(current, &course, &distance);
|
view.CourseAndDistance(current, &course, &distance);
|
||||||
if(distance > visibility_meters) {
|
if(distance > visibility_meters) {
|
||||||
|
@ -934,14 +934,14 @@ void FGAIAircraft::getGroundElev(double dt) {
|
||||||
|
|
||||||
// FIXME: make sure the pos.lat/pos.lon values are in degrees ...
|
// FIXME: make sure the pos.lat/pos.lon values are in degrees ...
|
||||||
double range = 500.0;
|
double range = 500.0;
|
||||||
if (!globals->get_tile_mgr()->scenery_available(pos.lat(), pos.lon(), range)) {
|
if (!globals->get_tile_mgr()->scenery_available(pos.getLatitudeDeg(), pos.getLongitudeDeg(), range)) {
|
||||||
// Try to shedule tiles for that position.
|
// Try to shedule tiles for that position.
|
||||||
globals->get_tile_mgr()->update( aip.getSGLocation(), range );
|
globals->get_tile_mgr()->update( aip.getSGLocation(), range );
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME: make sure the pos.lat/pos.lon values are in degrees ...
|
// FIXME: make sure the pos.lat/pos.lon values are in degrees ...
|
||||||
double alt;
|
double alt;
|
||||||
if (globals->get_scenery()->get_elevation_m(pos.lat(), pos.lon(), 20000.0, alt, 0))
|
if (globals->get_scenery()->get_elevation_m(pos.getLatitudeDeg(), pos.getLongitudeDeg(), 20000.0, alt, 0))
|
||||||
tgt_altitude = alt * SG_METER_TO_FEET;
|
tgt_altitude = alt * SG_METER_TO_FEET;
|
||||||
|
|
||||||
//cerr << "Target altitude : " << tgt_altitude << endl;
|
//cerr << "Target altitude : " << tgt_altitude << endl;
|
||||||
|
|
|
@ -169,7 +169,7 @@ void FGAIBallistic::Run(double dt) {
|
||||||
|
|
||||||
// calculate vertical and horizontal speed components
|
// calculate vertical and horizontal speed components
|
||||||
vs = sin( pitch * SG_DEGREES_TO_RADIANS ) * speed;
|
vs = sin( pitch * SG_DEGREES_TO_RADIANS ) * speed;
|
||||||
hs = cos( pitch * SG_DEGREES_TO_RADIANS ) * speed;
|
double hs = cos( pitch * SG_DEGREES_TO_RADIANS ) * speed;
|
||||||
|
|
||||||
// convert horizontal speed (fps) to degrees per second
|
// convert horizontal speed (fps) to degrees per second
|
||||||
speed_north_deg_sec = cos(hdg / SG_RADIANS_TO_DEGREES) * hs / ft_per_deg_lat;
|
speed_north_deg_sec = cos(hdg / SG_RADIANS_TO_DEGREES) * hs / ft_per_deg_lat;
|
||||||
|
@ -186,15 +186,15 @@ void FGAIBallistic::Run(double dt) {
|
||||||
wind_speed_from_east_deg_sec = wind_from_east / ft_per_deg_lon;
|
wind_speed_from_east_deg_sec = wind_from_east / ft_per_deg_lon;
|
||||||
|
|
||||||
// set new position
|
// set new position
|
||||||
pos.setlat( pos.lat() + (speed_north_deg_sec - wind_speed_from_north_deg_sec) * dt );
|
pos.setLatitudeDeg( pos.getLatitudeDeg() + (speed_north_deg_sec - wind_speed_from_north_deg_sec) * dt );
|
||||||
pos.setlon( pos.lon() + (speed_east_deg_sec - wind_speed_from_east_deg_sec) * dt );
|
pos.setLongitudeDeg( pos.getLongitudeDeg() + (speed_east_deg_sec - wind_speed_from_east_deg_sec) * dt );
|
||||||
|
|
||||||
// adjust vertical speed for acceleration of gravity and buoyancy
|
// adjust vertical speed for acceleration of gravity and buoyancy
|
||||||
vs -= (gravity - buoyancy) * dt;
|
vs -= (gravity - buoyancy) * dt;
|
||||||
|
|
||||||
// adjust altitude (feet)
|
// adjust altitude (feet)
|
||||||
altitude += vs * dt;
|
altitude += vs * dt;
|
||||||
pos.setelev(altitude * SG_FEET_TO_METER);
|
pos.setElevationFt(altitude);
|
||||||
|
|
||||||
// recalculate pitch (velocity vector) if aerostabilized
|
// recalculate pitch (velocity vector) if aerostabilized
|
||||||
// cout << "aero_stabilised " << aero_stabilised << endl ;
|
// cout << "aero_stabilised " << aero_stabilised << endl ;
|
||||||
|
|
|
@ -60,7 +60,6 @@ private:
|
||||||
double azimuth; // degrees true
|
double azimuth; // degrees true
|
||||||
double elevation; // degrees
|
double elevation; // degrees
|
||||||
double rotation; // degrees
|
double rotation; // degrees
|
||||||
double hs; // horizontal speed (fps)
|
|
||||||
bool aero_stabilised; // if true, object will align wit trajectory
|
bool aero_stabilised; // if true, object will align wit trajectory
|
||||||
double drag_area; // equivalent drag area in ft2
|
double drag_area; // equivalent drag area in ft2
|
||||||
double life_timer; // seconds
|
double life_timer; // seconds
|
||||||
|
|
|
@ -106,13 +106,13 @@ void FGAIBase::update(double dt) {
|
||||||
if (_otype == otBallistic)
|
if (_otype == otBallistic)
|
||||||
CalculateMach();
|
CalculateMach();
|
||||||
|
|
||||||
ft_per_deg_lat = 366468.96 - 3717.12 * cos(pos.lat()*SGD_DEGREES_TO_RADIANS);
|
ft_per_deg_lat = 366468.96 - 3717.12 * cos(pos.getLatitudeRad());
|
||||||
ft_per_deg_lon = 365228.16 * cos(pos.lat()*SGD_DEGREES_TO_RADIANS);
|
ft_per_deg_lon = 365228.16 * cos(pos.getLatitudeRad());
|
||||||
}
|
}
|
||||||
|
|
||||||
void FGAIBase::Transform() {
|
void FGAIBase::Transform() {
|
||||||
if (!invisible) {
|
if (!invisible) {
|
||||||
aip.setPosition(pos.lon(), pos.lat(), pos.elev() * SG_METER_TO_FEET);
|
aip.setPosition(pos);
|
||||||
if (no_roll) {
|
if (no_roll) {
|
||||||
aip.setOrientation(0.0, pitch, hdg);
|
aip.setOrientation(0.0, pitch, hdg);
|
||||||
} else {
|
} else {
|
||||||
|
@ -260,8 +260,8 @@ double FGAIBase::UpdateRadar(FGAIManager* manager)
|
||||||
|
|
||||||
double user_latitude = manager->get_user_latitude();
|
double user_latitude = manager->get_user_latitude();
|
||||||
double user_longitude = manager->get_user_longitude();
|
double user_longitude = manager->get_user_longitude();
|
||||||
double lat_range = fabs(pos.lat() - user_latitude) * ft_per_deg_lat;
|
double lat_range = fabs(pos.getLatitudeDeg() - user_latitude) * ft_per_deg_lat;
|
||||||
double lon_range = fabs(pos.lon() - user_longitude) * ft_per_deg_lon;
|
double lon_range = fabs(pos.getLongitudeDeg() - user_longitude) * ft_per_deg_lon;
|
||||||
double range_ft2 = lat_range*lat_range + lon_range*lon_range;
|
double range_ft2 = lat_range*lat_range + lon_range*lon_range;
|
||||||
|
|
||||||
//
|
//
|
||||||
|
@ -284,16 +284,16 @@ double FGAIBase::UpdateRadar(FGAIManager* manager)
|
||||||
range = range_ft / 6076.11549;
|
range = range_ft / 6076.11549;
|
||||||
|
|
||||||
// calculate bearing to target
|
// calculate bearing to target
|
||||||
if (pos.lat() >= user_latitude) {
|
if (pos.getLatitudeDeg() >= user_latitude) {
|
||||||
bearing = atan2(lat_range, lon_range) * SG_RADIANS_TO_DEGREES;
|
bearing = atan2(lat_range, lon_range) * SG_RADIANS_TO_DEGREES;
|
||||||
if (pos.lon() >= user_longitude) {
|
if (pos.getLongitudeDeg() >= user_longitude) {
|
||||||
bearing = 90.0 - bearing;
|
bearing = 90.0 - bearing;
|
||||||
} else {
|
} else {
|
||||||
bearing = 270.0 + bearing;
|
bearing = 270.0 + bearing;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
bearing = atan2(lon_range, lat_range) * SG_RADIANS_TO_DEGREES;
|
bearing = atan2(lon_range, lat_range) * SG_RADIANS_TO_DEGREES;
|
||||||
if (pos.lon() >= user_longitude) {
|
if (pos.getLongitudeDeg() >= user_longitude) {
|
||||||
bearing = 180.0 - bearing;
|
bearing = 180.0 - bearing;
|
||||||
} else {
|
} else {
|
||||||
bearing = 180.0 + bearing;
|
bearing = 180.0 + bearing;
|
||||||
|
@ -341,7 +341,8 @@ SGVec3d
|
||||||
FGAIBase::getCartPosAt(const SGVec3d& _off) const
|
FGAIBase::getCartPosAt(const SGVec3d& _off) const
|
||||||
{
|
{
|
||||||
// Transform that one to the horizontal local coordinate system.
|
// Transform that one to the horizontal local coordinate system.
|
||||||
SGQuatd hlTrans = SGQuatd::fromLonLatDeg(pos.lon(), pos.lat());
|
|
||||||
|
SGQuatd hlTrans = SGQuatd::fromLonLat(pos);
|
||||||
// and postrotate the orientation of the AIModel wrt the horizontal
|
// and postrotate the orientation of the AIModel wrt the horizontal
|
||||||
// local frame
|
// local frame
|
||||||
hlTrans *= SGQuatd::fromYawPitchRollDeg(hdg, pitch, roll);
|
hlTrans *= SGQuatd::fromYawPitchRollDeg(hdg, pitch, roll);
|
||||||
|
@ -351,7 +352,7 @@ FGAIBase::getCartPosAt(const SGVec3d& _off) const
|
||||||
SGVec3d off = hlTrans.backTransform(_off);
|
SGVec3d off = hlTrans.backTransform(_off);
|
||||||
|
|
||||||
// Add the position offset of the AIModel to gain the earth centered position
|
// Add the position offset of the AIModel to gain the earth centered position
|
||||||
SGVec3d cartPos = SGGeod::fromDegFt(pos.lon(), pos.lat(), pos.elev());
|
SGVec3d cartPos = SGVec3d::fromGeod(pos);
|
||||||
|
|
||||||
return cartPos + off;
|
return cartPos + off;
|
||||||
}
|
}
|
||||||
|
@ -360,17 +361,17 @@ FGAIBase::getCartPosAt(const SGVec3d& _off) const
|
||||||
* getters and Setters
|
* getters and Setters
|
||||||
*/
|
*/
|
||||||
void FGAIBase::_setLongitude( double longitude ) {
|
void FGAIBase::_setLongitude( double longitude ) {
|
||||||
pos.setlon(longitude);
|
pos.setLongitudeDeg(longitude);
|
||||||
}
|
}
|
||||||
void FGAIBase::_setLatitude ( double latitude ) {
|
void FGAIBase::_setLatitude ( double latitude ) {
|
||||||
pos.setlat(latitude);
|
pos.setLatitudeDeg(latitude);
|
||||||
}
|
}
|
||||||
|
|
||||||
double FGAIBase::_getLongitude() const {
|
double FGAIBase::_getLongitude() const {
|
||||||
return pos.lon();
|
return pos.getLongitudeDeg();
|
||||||
}
|
}
|
||||||
double FGAIBase::_getLatitude () const {
|
double FGAIBase::_getLatitude () const {
|
||||||
return pos.lat();
|
return pos.getLatitudeDeg();
|
||||||
}
|
}
|
||||||
double FGAIBase::_getRdot() const {
|
double FGAIBase::_getRdot() const {
|
||||||
return rdot;
|
return rdot;
|
||||||
|
|
|
@ -48,7 +48,6 @@ public:
|
||||||
|
|
||||||
FGAIBase(object_type ot);
|
FGAIBase(object_type ot);
|
||||||
virtual ~FGAIBase();
|
virtual ~FGAIBase();
|
||||||
inline const Point3D& GetPos() const { return(pos); }
|
|
||||||
|
|
||||||
virtual void readFromScenario(SGPropertyNode* scFileNode);
|
virtual void readFromScenario(SGPropertyNode* scFileNode);
|
||||||
|
|
||||||
|
@ -84,7 +83,7 @@ protected:
|
||||||
FGAIManager* manager;
|
FGAIManager* manager;
|
||||||
|
|
||||||
// these describe the model's actual state
|
// these describe the model's actual state
|
||||||
Point3D pos; // WGS84 lat & lon in degrees, elev above sea-level in meters
|
SGGeod pos; // WGS84 lat & lon in degrees, elev above sea-level in meters
|
||||||
double hdg; // True heading in degrees
|
double hdg; // True heading in degrees
|
||||||
double roll; // degrees, left is negative
|
double roll; // degrees, left is negative
|
||||||
double pitch; // degrees, nose-down is negative
|
double pitch; // degrees, nose-down is negative
|
||||||
|
@ -205,7 +204,7 @@ inline void FGAIBase::setHeading( double heading ) {
|
||||||
|
|
||||||
inline void FGAIBase::setAltitude( double altitude_ft ) {
|
inline void FGAIBase::setAltitude( double altitude_ft ) {
|
||||||
altitude = tgt_altitude = altitude_ft;
|
altitude = tgt_altitude = altitude_ft;
|
||||||
pos.setelev(altitude * SG_FEET_TO_METER);
|
pos.setElevationFt(altitude);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void FGAIBase::setBank( double bank ) {
|
inline void FGAIBase::setBank( double bank ) {
|
||||||
|
@ -218,10 +217,10 @@ inline void FGAIBase::setPitch( double newpitch ) {
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void FGAIBase::setLongitude( double longitude ) {
|
inline void FGAIBase::setLongitude( double longitude ) {
|
||||||
pos.setlon( longitude );
|
pos.setLongitudeDeg( longitude );
|
||||||
}
|
}
|
||||||
inline void FGAIBase::setLatitude ( double latitude ) {
|
inline void FGAIBase::setLatitude ( double latitude ) {
|
||||||
pos.setlat( latitude );
|
pos.setLatitudeDeg( latitude );
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void FGAIBase::setDie( bool die ) { delete_me = die; }
|
inline void FGAIBase::setDie( bool die ) { delete_me = die; }
|
||||||
|
|
|
@ -152,14 +152,14 @@ void FGAICarrier::update(double dt) {
|
||||||
// but by just apply discrete changes at its velocity variables.
|
// but by just apply discrete changes at its velocity variables.
|
||||||
// Update the velocity information stored in those nodes.
|
// Update the velocity information stored in those nodes.
|
||||||
// Transform that one to the horizontal local coordinate system.
|
// Transform that one to the horizontal local coordinate system.
|
||||||
SGQuatd ec2hl = SGQuatd::fromLonLatDeg(pos.lon(), pos.lat());
|
SGQuatd ec2hl = SGQuatd::fromLonLat(pos);
|
||||||
// The orientation of the carrier wrt the horizontal local frame
|
// The orientation of the carrier wrt the horizontal local frame
|
||||||
SGQuatd hl2body = SGQuatd::fromYawPitchRollDeg(hdg, pitch, roll);
|
SGQuatd hl2body = SGQuatd::fromYawPitchRollDeg(hdg, pitch, roll);
|
||||||
// and postrotate the orientation of the AIModel wrt the horizontal
|
// and postrotate the orientation of the AIModel wrt the horizontal
|
||||||
// local frame
|
// local frame
|
||||||
SGQuatd ec2body = ec2hl*hl2body;
|
SGQuatd ec2body = ec2hl*hl2body;
|
||||||
// The cartesian position of the carrier in the wgs84 world
|
// The cartesian position of the carrier in the wgs84 world
|
||||||
SGVec3d cartPos = SGGeod::fromDegFt(pos.lon(), pos.lat(), pos.elev());
|
SGVec3d cartPos = SGVec3d::fromGeod(pos);
|
||||||
// Store for later use by the groundcache
|
// Store for later use by the groundcache
|
||||||
rot_pivot_wrt_earth = cartPos;
|
rot_pivot_wrt_earth = cartPos;
|
||||||
|
|
||||||
|
@ -189,7 +189,7 @@ void FGAICarrier::update(double dt) {
|
||||||
// Now here is the finite difference ...
|
// Now here is the finite difference ...
|
||||||
|
|
||||||
// Transform that one to the horizontal local coordinate system.
|
// Transform that one to the horizontal local coordinate system.
|
||||||
SGQuatd ec2hlNew = SGQuatd::fromLonLatDeg(pos.lon(), pos.lat());
|
SGQuatd ec2hlNew = SGQuatd::fromLonLat(pos);
|
||||||
// compute the new orientation
|
// compute the new orientation
|
||||||
SGQuatd hl2bodyNew = SGQuatd::fromYawPitchRollDeg(hdg, pitch, roll);
|
SGQuatd hl2bodyNew = SGQuatd::fromYawPitchRollDeg(hdg, pitch, roll);
|
||||||
// The rotation difference
|
// The rotation difference
|
||||||
|
@ -287,7 +287,7 @@ bool FGAICarrier::init() {
|
||||||
turn_to_launch_hdg = false;
|
turn_to_launch_hdg = false;
|
||||||
returning = false;
|
returning = false;
|
||||||
|
|
||||||
initialpos = pos;
|
mOpBoxPos = pos;
|
||||||
base_course = hdg;
|
base_course = hdg;
|
||||||
base_speed = speed;
|
base_speed = speed;
|
||||||
|
|
||||||
|
@ -322,9 +322,9 @@ void FGAICarrier::bind() {
|
||||||
props->tie("controls/base-speed-kts",
|
props->tie("controls/base-speed-kts",
|
||||||
SGRawValuePointer<double>(&base_speed));
|
SGRawValuePointer<double>(&base_speed));
|
||||||
props->tie("controls/start-pos-lat-deg",
|
props->tie("controls/start-pos-lat-deg",
|
||||||
SGRawValuePointer<double>(&initialpos[1]));
|
SGRawValueMethods<SGGeod,double>(pos, &SGGeod::getLatitudeDeg));
|
||||||
props->tie("controls/start-pos-long-deg",
|
props->tie("controls/start-pos-long-deg",
|
||||||
SGRawValuePointer<double>(&initialpos[0]));
|
SGRawValueMethods<SGGeod,double>(pos, &SGGeod::getLongitudeDeg));
|
||||||
props->tie("velocities/speed-kts",
|
props->tie("velocities/speed-kts",
|
||||||
SGRawValuePointer<double>(&speed));
|
SGRawValuePointer<double>(&speed));
|
||||||
props->tie("environment/surface-wind-speed-true-kts",
|
props->tie("environment/surface-wind-speed-true-kts",
|
||||||
|
@ -402,7 +402,7 @@ bool FGAICarrier::getParkPosition(const string& id, SGGeod& geodPos,
|
||||||
if ((*it).name == id || id.empty()) {
|
if ((*it).name == id || id.empty()) {
|
||||||
ParkPosition ppos = *it;
|
ParkPosition ppos = *it;
|
||||||
SGVec3d cartPos = getCartPosAt(ppos.offset);
|
SGVec3d cartPos = getCartPosAt(ppos.offset);
|
||||||
geodPos = cartPos;
|
geodPos = SGGeod::fromCart(cartPos);
|
||||||
hdng = hdg + ppos.heading_deg;
|
hdng = hdg + ppos.heading_deg;
|
||||||
double shdng = sin(ppos.heading_deg * SGD_DEGREES_TO_RADIANS);
|
double shdng = sin(ppos.heading_deg * SGD_DEGREES_TO_RADIANS);
|
||||||
double chdng = cos(ppos.heading_deg * SGD_DEGREES_TO_RADIANS);
|
double chdng = cos(ppos.heading_deg * SGD_DEGREES_TO_RADIANS);
|
||||||
|
@ -579,14 +579,14 @@ bool FGAICarrier::mark_cat(ssgEntity* e, const list<string>& cat_objects, bool m
|
||||||
// care for transforms ...
|
// care for transforms ...
|
||||||
short v[2];
|
short v[2];
|
||||||
l->getLine(0, v, v+1 );
|
l->getLine(0, v, v+1 );
|
||||||
sgVec3 ends[2];
|
SGVec3f ends[2];
|
||||||
for (int k=0; k<2; ++k)
|
for (int k=0; k<2; ++k)
|
||||||
sgCopyVec3( ends[k], l->getVertex( v[k] ) );
|
sgCopyVec3( ends[k].sg(), l->getVertex( v[k] ) );
|
||||||
|
|
||||||
// When the 1 end is behind the 0 end, swap the coordinates.
|
// When the 1 end is behind the 0 end, swap the coordinates.
|
||||||
if (ends[0][0] < ends[1][0]) {
|
if (ends[0][0] < ends[1][0]) {
|
||||||
sgCopyVec3( l->getVertex( v[0] ), ends[1] );
|
sgCopyVec3( l->getVertex( v[0] ), ends[1].sg() );
|
||||||
sgCopyVec3( l->getVertex( v[1] ), ends[0] );
|
sgCopyVec3( l->getVertex( v[1] ), ends[0].sg() );
|
||||||
}
|
}
|
||||||
found = true;
|
found = true;
|
||||||
}
|
}
|
||||||
|
@ -685,18 +685,8 @@ void FGAICarrier::TurnToBase(){
|
||||||
void FGAICarrier::ReturnToBox(){
|
void FGAICarrier::ReturnToBox(){
|
||||||
double course, distance, az2;
|
double course, distance, az2;
|
||||||
|
|
||||||
//get the carrier position
|
|
||||||
carrierpos = pos;
|
|
||||||
|
|
||||||
//cout << "lat: " << carrierpos[1] << " lon: " << carrierpos[0] << endl;
|
|
||||||
|
|
||||||
//calculate the bearing and range of the initial position from the carrier
|
//calculate the bearing and range of the initial position from the carrier
|
||||||
geo_inverse_wgs_84(carrierpos[2],
|
geo_inverse_wgs_84(pos, mOpBoxPos, &course, &az2, &distance);
|
||||||
carrierpos[1],
|
|
||||||
carrierpos[0],
|
|
||||||
initialpos[1],
|
|
||||||
initialpos[0],
|
|
||||||
&course, &az2, &distance);
|
|
||||||
|
|
||||||
distance *= SG_METER_TO_NM;
|
distance *= SG_METER_TO_NM;
|
||||||
|
|
||||||
|
@ -720,33 +710,33 @@ bool FGAICarrier::OutsideBox() { //returns true if the carrier is outside operat
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (initialpos[1] >= 0) { //northern hemisphere
|
if (mOpBoxPos.getLatitudeDeg() >= 0) { //northern hemisphere
|
||||||
if (pos[1] >= initialpos[1] + max_lat)
|
if (pos.getLatitudeDeg() >= mOpBoxPos.getLatitudeDeg() + max_lat)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
if (pos[1] <= initialpos[1] - min_lat)
|
if (pos.getLatitudeDeg() <= mOpBoxPos.getLatitudeDeg() - min_lat)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
} else { //southern hemisphere
|
} else { //southern hemisphere
|
||||||
if (pos[1] <= initialpos[1] - max_lat)
|
if (pos.getLatitudeDeg() <= mOpBoxPos.getLatitudeDeg() - max_lat)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
if (pos[1] >= initialpos[1] + min_lat)
|
if (pos.getLatitudeDeg() >= mOpBoxPos.getLatitudeDeg() + min_lat)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (initialpos[0] >=0) { //eastern hemisphere
|
if (mOpBoxPos.getLongitudeDeg() >=0) { //eastern hemisphere
|
||||||
if (pos[0] >= initialpos[0] + max_long)
|
if (pos.getLongitudeDeg() >= mOpBoxPos.getLongitudeDeg() + max_long)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
if (pos[0] <= initialpos[0] - min_long)
|
if (pos.getLongitudeDeg() <= mOpBoxPos.getLongitudeDeg() - min_long)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
} else { //western hemisphere
|
} else { //western hemisphere
|
||||||
if (pos[0] <= initialpos[0] - max_long)
|
if (pos.getLongitudeDeg() <= mOpBoxPos.getLongitudeDeg() - max_long)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
if (pos[0] >= initialpos[0] + min_long)
|
if (pos.getLongitudeDeg() >= mOpBoxPos.getLongitudeDeg() + min_long)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -155,8 +155,7 @@ private:
|
||||||
bool wave_off_lights;
|
bool wave_off_lights;
|
||||||
|
|
||||||
// these are for maneuvering the carrier
|
// these are for maneuvering the carrier
|
||||||
Point3D carrierpos;
|
SGGeod mOpBoxPos;
|
||||||
Point3D initialpos;
|
|
||||||
|
|
||||||
double wind_speed_from_north_kts ;
|
double wind_speed_from_north_kts ;
|
||||||
double wind_speed_from_east_kts ;
|
double wind_speed_from_east_kts ;
|
||||||
|
|
|
@ -291,15 +291,12 @@ void FGAIMultiplayer::update(double dt)
|
||||||
}
|
}
|
||||||
|
|
||||||
// extract the position
|
// extract the position
|
||||||
SGGeod geod = ecPos;
|
pos = SGGeod::fromCart(ecPos);
|
||||||
pos.setlat(geod.getLatitudeDeg());
|
|
||||||
pos.setlon(geod.getLongitudeDeg());
|
|
||||||
pos.setelev(geod.getElevationM());
|
|
||||||
|
|
||||||
// The quaternion rotating from the earth centered frame to the
|
// The quaternion rotating from the earth centered frame to the
|
||||||
// horizontal local frame
|
// horizontal local frame
|
||||||
SGQuatf qEc2Hl = SGQuatf::fromLonLatRad((float)geod.getLongitudeRad(),
|
SGQuatf qEc2Hl = SGQuatf::fromLonLatRad((float)pos.getLongitudeRad(),
|
||||||
(float)geod.getLatitudeRad());
|
(float)pos.getLatitudeRad());
|
||||||
// The orientation wrt the horizontal local frame
|
// The orientation wrt the horizontal local frame
|
||||||
SGQuatf hlOr = conj(qEc2Hl)*ecOrient;
|
SGQuatf hlOr = conj(qEc2Hl)*ecOrient;
|
||||||
float hDeg, pDeg, rDeg;
|
float hDeg, pDeg, rDeg;
|
||||||
|
@ -309,7 +306,7 @@ void FGAIMultiplayer::update(double dt)
|
||||||
pitch = pDeg;
|
pitch = pDeg;
|
||||||
|
|
||||||
SG_LOG(SG_GENERAL, SG_DEBUG, "Multiplayer position and orientation: "
|
SG_LOG(SG_GENERAL, SG_DEBUG, "Multiplayer position and orientation: "
|
||||||
<< geod << ", " << hlOr);
|
<< ecPos << ", " << hlOr);
|
||||||
|
|
||||||
//###########################//
|
//###########################//
|
||||||
// do calculations for radar //
|
// do calculations for radar //
|
||||||
|
|
|
@ -135,8 +135,8 @@ void FGAIShip::Run(double dt) {
|
||||||
* speed * 1.686 / ft_per_deg_lon;
|
* speed * 1.686 / ft_per_deg_lon;
|
||||||
|
|
||||||
// set new position
|
// set new position
|
||||||
pos.setlat( pos.lat() + speed_north_deg_sec * dt);
|
pos.setLatitudeDeg( pos.getLatitudeDeg() + speed_north_deg_sec * dt);
|
||||||
pos.setlon( pos.lon() + speed_east_deg_sec * dt);
|
pos.setLongitudeDeg( pos.getLongitudeDeg() + speed_east_deg_sec * dt);
|
||||||
|
|
||||||
|
|
||||||
// adjust heading based on current rudder angle
|
// adjust heading based on current rudder angle
|
||||||
|
|
|
@ -106,8 +106,8 @@ void FGAIStorm::Run(double dt) {
|
||||||
* speed * 1.686 / ft_per_deg_lon;
|
* speed * 1.686 / ft_per_deg_lon;
|
||||||
|
|
||||||
// set new position
|
// set new position
|
||||||
pos.setlat( pos.lat() + speed_north_deg_sec * dt);
|
pos.setLatitudeDeg( pos.getLatitudeDeg() + speed_north_deg_sec * dt);
|
||||||
pos.setlon( pos.lon() + speed_east_deg_sec * dt);
|
pos.setLongitudeDeg( pos.getLongitudeDeg() + speed_east_deg_sec * dt);
|
||||||
|
|
||||||
// do calculations for weather radar display
|
// do calculations for weather radar display
|
||||||
UpdateRadar(manager);
|
UpdateRadar(manager);
|
||||||
|
@ -159,8 +159,8 @@ void FGAIStorm::Run(double dt) {
|
||||||
double user_altitude = manager->get_user_altitude();
|
double user_altitude = manager->get_user_altitude();
|
||||||
|
|
||||||
// calculate range to target in feet and nautical miles
|
// calculate range to target in feet and nautical miles
|
||||||
double lat_range = fabs(pos.lat() - user_latitude) * ft_per_deg_lat;
|
double lat_range = fabs(pos.getLatitudeDeg() - user_latitude) * ft_per_deg_lat;
|
||||||
double lon_range = fabs(pos.lon() - user_longitude) * ft_per_deg_lon;
|
double lon_range = fabs(pos.getLongitudeDeg() - user_longitude) * ft_per_deg_lon;
|
||||||
double range_ft = sqrt(lat_range*lat_range + lon_range*lon_range);
|
double range_ft = sqrt(lat_range*lat_range + lon_range*lon_range);
|
||||||
range = range_ft / 6076.11549;
|
range = range_ft / 6076.11549;
|
||||||
|
|
||||||
|
|
|
@ -88,8 +88,8 @@ void FGAIThermal::Run(double dt) {
|
||||||
double user_altitude = manager->get_user_altitude();
|
double user_altitude = manager->get_user_altitude();
|
||||||
|
|
||||||
// calculate range to target in feet and nautical miles
|
// calculate range to target in feet and nautical miles
|
||||||
double lat_range = fabs(pos.lat() - user_latitude) * ft_per_deg_lat;
|
double lat_range = fabs(pos.getLatitudeDeg() - user_latitude) * ft_per_deg_lat;
|
||||||
double lon_range = fabs(pos.lon() - user_longitude) * ft_per_deg_lon;
|
double lon_range = fabs(pos.getLongitudeDeg() - user_longitude) * ft_per_deg_lon;
|
||||||
double range_ft = sqrt(lat_range*lat_range + lon_range*lon_range);
|
double range_ft = sqrt(lat_range*lat_range + lon_range*lon_range);
|
||||||
range = range_ft / 6076.11549;
|
range = range_ft / 6076.11549;
|
||||||
|
|
||||||
|
|
|
@ -23,6 +23,7 @@
|
||||||
# include <config.h>
|
# include <config.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include <simgear/math/SGMath.hxx>
|
||||||
#include <simgear/math/sg_geodesy.hxx>
|
#include <simgear/math/sg_geodesy.hxx>
|
||||||
#include <Main/fg_props.hxx>
|
#include <Main/fg_props.hxx>
|
||||||
|
|
||||||
|
@ -78,9 +79,7 @@ void FGACMS::update( double dt ) {
|
||||||
double acc_down = _acc_down->getDoubleValue();
|
double acc_down = _acc_down->getDoubleValue();
|
||||||
_set_Accels_Local( acc_lon, acc_lat, acc_down );
|
_set_Accels_Local( acc_lon, acc_lat, acc_down );
|
||||||
|
|
||||||
sgVec3 accel_ned;
|
double accel = norm(SGVec3d(acc_lon, acc_lat, acc_down)) * SG_FEET_TO_METER;
|
||||||
sgSetVec3(accel_ned, acc_lon, acc_lat, acc_down);
|
|
||||||
double accel = sgLengthVec3 (accel_ned) * SG_FEET_TO_METER;
|
|
||||||
|
|
||||||
double velocity = (_speed->getDoubleValue() * SG_KT_TO_MPS) + accel * dt;
|
double velocity = (_speed->getDoubleValue() * SG_KT_TO_MPS) + accel * dt;
|
||||||
double dist = cos (pitch) * velocity * dt;
|
double dist = cos (pitch) * velocity * dt;
|
||||||
|
@ -89,16 +88,15 @@ void FGACMS::update( double dt ) {
|
||||||
_set_V_calibrated_kts( kts );
|
_set_V_calibrated_kts( kts );
|
||||||
_set_V_ground_speed( kts );
|
_set_V_ground_speed( kts );
|
||||||
|
|
||||||
|
SGGeod pos = SGGeod::fromDegM(get_Longitude(), get_Latitude(), get_Altitude());
|
||||||
// update (lon/lat) position
|
// update (lon/lat) position
|
||||||
double lat2, lon2, az2;
|
SGGeod pos2;
|
||||||
geo_direct_wgs_84 ( get_Altitude(),
|
double az2;
|
||||||
get_Latitude() * SGD_RADIANS_TO_DEGREES,
|
geo_direct_wgs_84 ( pos, heading * SGD_RADIANS_TO_DEGREES,
|
||||||
get_Longitude() * SGD_RADIANS_TO_DEGREES,
|
dist, pos2, &az2 );
|
||||||
heading * SGD_RADIANS_TO_DEGREES,
|
|
||||||
dist, &lat2, &lon2, &az2 );
|
|
||||||
|
|
||||||
_set_Longitude( lon2 * SGD_DEGREES_TO_RADIANS );
|
_set_Longitude( pos2.getLongitudeRad() );
|
||||||
_set_Latitude( lat2 * SGD_DEGREES_TO_RADIANS );
|
_set_Latitude( pos2.getLatitudeRad() );
|
||||||
|
|
||||||
double sl_radius, lat_geoc;
|
double sl_radius, lat_geoc;
|
||||||
sgGeodToGeoc( get_Latitude(), get_Altitude(), &sl_radius, &lat_geoc );
|
sgGeodToGeoc( get_Latitude(), get_Altitude(), &sl_radius, &lat_geoc );
|
||||||
|
|
|
@ -156,7 +156,7 @@ bool FGMultiplay::process() {
|
||||||
// first the aprioriate structure for the geodetic one
|
// first the aprioriate structure for the geodetic one
|
||||||
SGGeod geod = SGGeod::fromRadFt(lon, lat, ifce->get_Altitude());
|
SGGeod geod = SGGeod::fromRadFt(lon, lat, ifce->get_Altitude());
|
||||||
// Convert to cartesion coordinate
|
// Convert to cartesion coordinate
|
||||||
motionInfo.position = geod;
|
motionInfo.position = SGVec3d::fromGeod(geod);
|
||||||
|
|
||||||
// The quaternion rotating from the earth centered frame to the
|
// The quaternion rotating from the earth centered frame to the
|
||||||
// horizontal local frame
|
// horizontal local frame
|
||||||
|
|
Loading…
Reference in a new issue