]> git.mxchange.org Git - flightgear.git/blob - src/Environment/ephemeris.cxx
a6a1f5c9476d9d0c09e9576cd5fd8d826d2da08e
[flightgear.git] / src / Environment / ephemeris.cxx
1 #include <Environment/ephemeris.hxx>
2
3 #include <simgear/timing/sg_time.hxx>
4 #include <simgear/ephemeris/ephemeris.hxx>
5
6 #include <Main/globals.hxx>
7 #include <Main/fg_props.hxx>
8
9 Ephemeris::Ephemeris() :
10   _impl(NULL),
11   _latProp(NULL)
12 {
13 }
14
15 Ephemeris::~Ephemeris()
16 {
17   delete _impl;
18 }
19
20 void Ephemeris::init()
21 {
22   if (_impl) {
23     return;
24   }
25   
26   SGPath ephem_data_path(globals->get_fg_root());
27   ephem_data_path.append("Astro");
28   _impl = new SGEphemeris(ephem_data_path.c_str());
29   globals->set_ephem(_impl);
30 }
31
32 void Ephemeris::postinit()
33 {
34   update(0.0);
35 }
36
37 static void tieStar(const char* prop, Star* s, double (Star::*getter)() const)
38 {
39   fgGetNode(prop, true)->tie(SGRawValueMethods<Star, double>(*s, getter, NULL));
40
41
42 void Ephemeris::bind()
43 {
44   _latProp = fgGetNode("/position/latitude-deg", true);
45   
46   tieStar("/ephemeris/sun/xs", _impl->get_sun(), &Star::getxs);
47   tieStar("/ephemeris/sun/ys", _impl->get_sun(), &Star::getys);
48   tieStar("/ephemeris/sun/ze", _impl->get_sun(), &Star::getze);
49   tieStar("/ephemeris/sun/ye", _impl->get_sun(), &Star::getye);
50   
51   tieStar("/ephemeris/sun/lat-deg", _impl->get_sun(), &Star::getLat);
52 }
53
54 void Ephemeris::unbind()
55 {
56 }
57
58 void Ephemeris::update(double)
59 {
60   SGTime* st = globals->get_time_params();
61   _impl->update(st->getMjd(), st->getLst(), _latProp->getDoubleValue());
62 }