Convert SGTime users to pass SGGeod/SGPath instead of raw values.
#include <simgear/sg_inlines.h>
#include <simgear/magvar/magvar.hxx>
#include <simgear/timing/sg_time.hxx>
+#include <simgear/math/SGMath.hxx>
#include <Main/globals.hxx>
#include <Main/fg_props.hxx>
_lat = lat;
_alt = alt;
- lon *= SGD_DEGREES_TO_RADIANS;
- lat *= SGD_DEGREES_TO_RADIANS;
- alt *= SG_FEET_TO_METER;
- _time.update( lon, lat, 0, 0 );
+ SGGeod location(SGGeod::fromDegFt(lon, lat, alt));
+ _time.update( location, 0, 0 );
update( lon, lat, alt, _time.getJD() );
}
}
// Configuration Initialisation
// Should this be in kln89.cxx ?
_turnAnticipationEnabled = false;
-
- _time = new SGTime;
-
+
_messageStack.clear();
_dto = false;
}
DCLGPS::~DCLGPS() {
- delete _time;
delete _approachFP; // Don't need to delete the waypoints inside since they point to
// the waypoints in the approach database.
// TODO - may need to delete the approach database!!
_elapsedTime += dt;
}
- _time->update(_gpsLon * SG_DEGREES_TO_RADIANS, _gpsLat * SG_DEGREES_TO_RADIANS, 0, 0);
// FIXME - currently all the below assumes leg mode and no DTO or OBS cancelled.
if(_activeFP->IsEmpty()) {
// Not sure if we need to reset these each update or only when fp altered
h *= SG_RADIANS_TO_DEGREES;
// TODO - use the real altitude below instead of 0.0!
//cout << "MagVar = " << sgGetMagVar(_gpsLon, _gpsLat, 0.0, _time->getJD()) * SG_RADIANS_TO_DEGREES << '\n';
- h -= sgGetMagVar(_gpsLon, _gpsLat, 0.0, _time->getJD()) * SG_RADIANS_TO_DEGREES;
+ double jd = globals->get_time_params()->getJD();
+ h -= sgGetMagVar(_gpsLon, _gpsLat, 0.0, jd) * SG_RADIANS_TO_DEGREES;
while(h >= 360.0) h -= 360.0;
while(h < 0.0) h += 360.0;
return(h);
// Return a position on a radial from wp1 given distance d (nm) and magnetic heading h (degrees)
// Note that d should be less that 1/4 Earth diameter!
GPSWaypoint DCLGPS::GetPositionOnMagRadial(const GPSWaypoint& wp1, double d, double h) {
- h += sgGetMagVar(wp1.lon, wp1.lat, 0.0, _time->getJD()) * SG_RADIANS_TO_DEGREES;
+ double jd = globals->get_time_params()->getJD();
+ h += sgGetMagVar(wp1.lon, wp1.lat, 0.0, jd) * SG_RADIANS_TO_DEGREES;
return(GetPositionOnRadial(wp1, d, h));
}
// Configuration that affects flightplan operation
bool _turnAnticipationEnabled;
- // Magvar stuff. Might get some of this stuff (such as time) from FG in future.
- SGTime* _time;
-
std::list<std::string> _messageStack;
virtual void CreateFlightPlan(GPSFlightPlan* fp, std::vector<std::string> ids, std::vector<GPSWpType> wps);
int year,month,day,hour,minute,second;
char *argument, *date_str;
- SGTime CurrentTime = SGTime();
- CurrentTime.update(0,0,0,0);
+ SGTime CurrentTime;
+ CurrentTime.update(SGGeod(),0,0);
// FIXME This should obtain system/aircraft/GMT time depending on timeType
pCurrentTime = CurrentTime.getGmt();
#include <simgear/misc/sg_path.hxx>
#include <simgear/timing/lowleveltime.h>
#include <simgear/structure/commands.hxx>
+#include <simgear/math/SGMath.hxx>
#include <Main/fg_props.hxx>
#include <Main/globals.hxx>
_warpDelta = fgGetNode("/sim/time/warp-delta", true);
- _longitudeDeg = fgGetNode("/position/longitude-deg", true);
- _latitudeDeg = fgGetNode("/position/latitude-deg", true);
-
SGPath zone(globals->get_fg_root());
zone.append("Timezone");
- double lon = _longitudeDeg->getDoubleValue() * SG_DEGREES_TO_RADIANS;
- double lat = _latitudeDeg->getDoubleValue() * SG_DEGREES_TO_RADIANS;
- _impl = new SGTime(lon, lat, zone.str(), _timeOverride->getLongValue());
+ _impl = new SGTime(globals->get_aircraft_position(), zone, _timeOverride->getLongValue());
_warpDelta->setIntValue(0);
&TimeManager::updateLocalTime, 30*60 );
updateLocalTime();
- _impl->update(lon, lat, _timeOverride->getLongValue(),
+ _impl->update(globals->get_aircraft_position(), _timeOverride->getLongValue(),
_warp->getIntValue());
globals->set_time_params(_impl);
_adjustWarpOnUnfreeze = false;
}
- double lon = _longitudeDeg->getDoubleValue() * SG_DEGREES_TO_RADIANS;
- double lat = _latitudeDeg->getDoubleValue() * SG_DEGREES_TO_RADIANS;
- _impl->update(lon, lat,
+ _impl->update(globals->get_aircraft_position(),
_timeOverride->getLongValue(),
_warp->getIntValue());
}
}
_lastClockFreeze = freeze;
- double lon = _longitudeDeg->getDoubleValue() * SG_DEGREES_TO_RADIANS;
- double lat = _latitudeDeg->getDoubleValue() * SG_DEGREES_TO_RADIANS;
- _impl->update(lon, lat,
+ _impl->update(globals->get_aircraft_position(),
_timeOverride->getLongValue(),
_warp->getIntValue());
{
SGPath zone(globals->get_fg_root());
zone.append("Timezone");
-
- double lon = _longitudeDeg->getDoubleValue() * SG_DEGREES_TO_RADIANS;
- double lat = _latitudeDeg->getDoubleValue() * SG_DEGREES_TO_RADIANS;
-
- SG_LOG(SG_GENERAL, SG_INFO, "updateLocal(" << lon << ", " << lat << ", " << zone.str() << ")");
- _impl->updateLocal(lon, lat, zone.str());
+ _impl->updateLocal(globals->get_aircraft_position(), zone.str());
}
void TimeManager::initTimeOffset()
sgTimeGetGMT( fgLocaltime(&cur_time, _impl->get_zonename() ) );
// Okay, we now have several possible scenarios
- double lon = _longitudeDeg->getDoubleValue() * SG_DEGREES_TO_RADIANS;
- double lat = _latitudeDeg->getDoubleValue() * SG_DEGREES_TO_RADIANS;
+ SGGeod loc = globals->get_aircraft_position();
int warp = 0;
if ( offset_type == "real" ) {
warp = 0;
} else if ( offset_type == "dawn" ) {
- warp = fgTimeSecondsUntilSunAngle( cur_time, lon, lat, 90.0, true );
+ warp = fgTimeSecondsUntilSunAngle( cur_time, loc, 90.0, true );
} else if ( offset_type == "morning" ) {
- warp = fgTimeSecondsUntilSunAngle( cur_time, lon, lat, 75.0, true );
+ warp = fgTimeSecondsUntilSunAngle( cur_time, loc, 75.0, true );
} else if ( offset_type == "noon" ) {
- warp = fgTimeSecondsUntilSunAngle( cur_time, lon, lat, 0.0, true );
+ warp = fgTimeSecondsUntilSunAngle( cur_time, loc, 0.0, true );
} else if ( offset_type == "afternoon" ) {
- warp = fgTimeSecondsUntilSunAngle( cur_time, lon, lat, 75.0, false );
+ warp = fgTimeSecondsUntilSunAngle( cur_time, loc, 75.0, false );
} else if ( offset_type == "dusk" ) {
- warp = fgTimeSecondsUntilSunAngle( cur_time, lon, lat, 90.0, false );
+ warp = fgTimeSecondsUntilSunAngle( cur_time, loc, 90.0, false );
} else if ( offset_type == "evening" ) {
- warp = fgTimeSecondsUntilSunAngle( cur_time, lon, lat, 100.0, false );
+ warp = fgTimeSecondsUntilSunAngle( cur_time, loc, 100.0, false );
} else if ( offset_type == "midnight" ) {
- warp = fgTimeSecondsUntilSunAngle( cur_time, lon, lat, 180.0, false );
+ warp = fgTimeSecondsUntilSunAngle( cur_time, loc, 180.0, false );
} else if ( offset_type == "system-offset" ) {
warp = offset;
orig_warp = 0;
bool _lastClockFreeze;
bool _adjustWarpOnUnfreeze;
- SGPropertyNode_ptr _longitudeDeg;
- SGPropertyNode_ptr _latitudeDeg;
-
// frame-rate / worst-case latency / update-rate counters
SGPropertyNode_ptr _frameRate;
SGPropertyNode_ptr _frameRateWorst;
*lat = dec;
}
-static double sun_angle( const SGTime &t, const SGVec3d& world_up,
- double lon_rad, double lat_rad ) {
+static double sun_angle( const SGTime &t, const SGVec3d& world_up) {
SG_LOG( SG_EVENT, SG_DEBUG, " Updating Sun position" );
SG_LOG( SG_EVENT, SG_DEBUG, " Gst = " << t.getGst() );
* when the sun angle is 90 and ascending.
*/
time_t fgTimeSecondsUntilSunAngle( time_t cur_time,
- double lon_rad,
- double lat_rad,
+ const SGGeod& loc,
double target_angle_deg,
bool ascending )
{
- // cout << "location = " << lon_rad * SG_RADIANS_TO_DEGREES << ", "
- // << lat_rad * SG_RADIANS_TO_DEGREES << endl;
- SGVec3d world_up = SGVec3d::fromGeod(SGGeod::fromRad(lon_rad, lat_rad));
- SGTime t = SGTime( lon_rad, lat_rad, "", 0 );
+ SGVec3d world_up = SGVec3d::fromGeod(loc);
+ SGTime t = SGTime( loc, SGPath(), 0 );
double best_diff = 180.0;
double last_angle = -99999.0;
secs < cur_time + half_day_secs;
secs += step_secs )
{
- t.update( lon_rad, lat_rad, secs, 0 );
- double angle_deg = sun_angle( t, world_up, lon_rad, lat_rad );
+ t.update( loc, secs, 0 );
+ double angle_deg = sun_angle( t, world_up );
double diff = fabs( angle_deg - target_angle_deg );
if ( diff < best_diff ) {
if ( last_angle <= 180.0 && ascending
#include <ctime>
+class SGGeod;
+
/**
* Given the current unix time in seconds, calculate seconds to the
* specified sun angle (relative to straight up.) Also specify if we
* when the sun angle is 90 and ascending.
*/
time_t fgTimeSecondsUntilSunAngle( time_t cur_time,
- double lon_rad,
- double lat_rad,
+ const SGGeod& loc,
double target_angle_deg,
bool ascending );