RelativePath="..\..\..\src\Environment\ridge_lift.hxx"
>
</File>
+ <File
+ RelativePath="..\..\..\src\Environment\ephemeris.cxx"
+ >
+ </File>
+ <File
+ RelativePath="..\..\..\src\Environment\ephemeris.hxx"
+ >
+ </File>
</Filter>
<Filter
Name="Lib_Model"
fgwind.cxx fgwind.hxx \
atmosphere.cxx atmosphere.hxx \
precipitation_mgr.cxx precipitation_mgr.hxx \
- ridge_lift.cxx ridge_lift.hxx
+ ridge_lift.cxx ridge_lift.hxx \
+ ephemeris.cxx ephemeris.hxx
INCLUDES = -I$(top_srcdir) -I$(top_srcdir)/src
--- /dev/null
+#include <Environment/ephemeris.hxx>
+
+#include <simgear/timing/sg_time.hxx>
+#include <simgear/ephemeris/ephemeris.hxx>
+
+#include <Main/globals.hxx>
+#include <Main/fg_props.hxx>
+
+Ephemeris::Ephemeris() :
+ _impl(NULL),
+ _latProp(NULL)
+{
+}
+
+Ephemeris::~Ephemeris()
+{
+ delete _impl;
+}
+
+void Ephemeris::init()
+{
+ if (_impl) {
+ return;
+ }
+
+ SGPath ephem_data_path(globals->get_fg_root());
+ ephem_data_path.append("Astro");
+ _impl = new SGEphemeris(ephem_data_path.c_str());
+ globals->set_ephem(_impl);
+}
+
+void Ephemeris::postinit()
+{
+ update(0.0);
+}
+
+static void tieStar(const char* prop, Star* s, double (Star::*getter)() const)
+{
+ fgGetNode(prop, true)->tie(SGRawValueMethods<Star, double>(*s, getter, NULL));
+}
+
+void Ephemeris::bind()
+{
+ _latProp = fgGetNode("/position/latitude-deg", true);
+
+ tieStar("/ephemeris/sun/xs", _impl->get_sun(), &Star::getxs);
+ tieStar("/ephemeris/sun/ys", _impl->get_sun(), &Star::getys);
+ tieStar("/ephemeris/sun/ze", _impl->get_sun(), &Star::getze);
+ tieStar("/ephemeris/sun/ye", _impl->get_sun(), &Star::getye);
+
+ tieStar("/ephemeris/sun/lat-deg", _impl->get_sun(), &Star::getLat);
+}
+
+void Ephemeris::unbind()
+{
+}
+
+void Ephemeris::update(double)
+{
+ SGTime* st = globals->get_time_params();
+ _impl->update(st->getMjd(), st->getLst(), _latProp->getDoubleValue());
+}
--- /dev/null
+#ifndef FG_ENVIRONMENT_EPHEMERIS_HXX
+#define FG_ENVIRONMENT_EPHEMERIS_HXX
+
+#include <simgear/structure/subsystem_mgr.hxx>
+
+class SGEphemeris;
+class SGPropertyNode;
+
+/**
+ * Wrap SGEphemeris in a susbsytem/property interface
+ */
+class Ephemeris : public SGSubsystem
+{
+public:
+
+ Ephemeris();
+ ~Ephemeris();
+
+ virtual void bind();
+ virtual void unbind();
+ virtual void update(double dt);
+ virtual void init();
+ virtual void postinit();
+
+private:
+ SGEphemeris* _impl;
+ SGPropertyNode* _latProp;
+};
+
+#endif // of FG_ENVIRONMENT_EPHEMERIS_HXX
+
delete subsystem_mgr;
delete event_mgr;
delete time_params;
- delete ephem;
delete mag;
delete matlib;
delete route_mgr;
#include <osgDB/Registry>
// Class references
-#include <simgear/ephemeris/ephemeris.hxx>
#include <simgear/scene/model/modellib.hxx>
#include <simgear/scene/material/matlib.hxx>
#include <simgear/scene/model/animation.hxx>
#include <ATCDCL/AIMgr.hxx>
#include <Time/tmp.hxx>
#include <Environment/environment_mgr.hxx>
+#include <Environment/ephemeris.hxx>
#include <GUI/new_gui.hxx>
#include <MultiPlayer/multiplaymgr.hxx>
} else {
// do nothing, fdm isn't inited yet
}
-
- // Update solar system
- globals->get_ephem()->update( globals->get_time_params()->getMjd(),
- globals->get_time_params()->getLst(),
- cur_fdm_state->get_Latitude() );
-
}
} else if ( idle_state == 6 ) {
idle_state++;
// Initialize the sky
- SGPath ephem_data_path( globals->get_fg_root() );
- ephem_data_path.append( "Astro" );
- SGEphemeris *ephem = new SGEphemeris( ephem_data_path.c_str() );
- ephem->update( globals->get_time_params()->getMjd(),
- globals->get_time_params()->getLst(),
- 0.0 );
- globals->set_ephem( ephem );
+
+ Ephemeris* eph = new Ephemeris;
+ globals->add_subsystem("ephmeris", eph);
+ eph->init(); // FIXME - remove this once SGSky code below is also a subsystem
// TODO: move to environment mgr
thesky = new SGSky;
#include <ctime>
#include <simgear/math/SGMath.hxx>
-#include <simgear/ephemeris/ephemeris.hxx>
#include <simgear/timing/sg_time.hxx>
#include <Main/globals.hxx>
+#include <Main/fg_props.hxx>
#include "tmp.hxx"
#include "sunsolver.hxx"
double alpha, delta;
double tmp;
- double beta = globals->get_ephem()->get_sun()->getLat();
+ SGPropertyNode* sun = fgGetNode("/ephemeris/sun");
+ assert(sun);
+ double beta = sun->getDoubleValue("lat-deg");
// double r = globals->get_ephem()->get_sun()->getDistance();
- double xs = globals->get_ephem()->get_sun()->getxs();
- double ys = globals->get_ephem()->get_sun()->getys();
- double ye = globals->get_ephem()->get_sun()->getye();
- double ze = globals->get_ephem()->get_sun()->getze();
+ double xs = sun->getDoubleValue("xs");
+ double ys = sun->getDoubleValue("ys");
+ double ye = sun->getDoubleValue("ye");
+ double ze = sun->getDoubleValue("ze");
alpha = atan2(ys - tan(beta)*ze/ys, xs);
delta = asin(sin(beta)*ye/ys + cos(beta)*ze);