]> git.mxchange.org Git - flightgear.git/blob - src/Environment/ephemeris.cxx
e11827b30dc282dbdc2fd457934e2172b9329220
[flightgear.git] / src / Environment / ephemeris.cxx
1 // ephemeris.cxx -- wrap SGEphemeris code in a subsystem
2 //
3 // Written by James Turner, started June 2010.
4 //
5 // Copyright (C) 2010  Curtis L. Olson  - http://www.flightgear.org/~curt
6 //
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License as
9 // published by the Free Software Foundation; either version 2 of the
10 // License, or (at your option) any later version.
11 //
12 // This program is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 // General Public License for more details.
16 //
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
20 //
21 // $Id$
22
23 #include <Environment/ephemeris.hxx>
24
25 #include <simgear/timing/sg_time.hxx>
26 #include <simgear/ephemeris/ephemeris.hxx>
27
28 #include <Main/globals.hxx>
29 #include <Main/fg_props.hxx>
30
31 static void tieStar(const char* prop, Star* s, double (Star::*getter)() const)
32 {
33   fgGetNode(prop, true)->tie(SGRawValueMethods<Star, double>(*s, getter, NULL));
34 }
35
36 Ephemeris::Ephemeris() :
37   _impl(NULL),
38   _latProp(NULL)
39 {
40 }
41
42 Ephemeris::~Ephemeris()
43 {
44 }
45
46 SGEphemeris* Ephemeris::data()
47 {
48     return _impl;
49 }
50
51 void Ephemeris::init()
52 {
53   SGPath ephem_data_path(globals->get_fg_root());
54   ephem_data_path.append("Astro");
55   _impl = new SGEphemeris(ephem_data_path.c_str());
56
57   tieStar("/ephemeris/sun/xs", _impl->get_sun(), &Star::getxs);
58   tieStar("/ephemeris/sun/ys", _impl->get_sun(), &Star::getys);
59   tieStar("/ephemeris/sun/ze", _impl->get_sun(), &Star::getze);
60   tieStar("/ephemeris/sun/ye", _impl->get_sun(), &Star::getye);
61   tieStar("/ephemeris/sun/lat-deg", _impl->get_sun(), &Star::getLat);
62
63     _latProp = fgGetNode("/position/latitude-deg", true);
64
65     update(0.0);
66 }
67
68 void Ephemeris::shutdown()
69 {
70     delete _impl;
71     _impl = NULL;
72 }
73
74 void Ephemeris::postinit()
75 {
76 }
77
78 void Ephemeris::bind()
79 {
80 }
81
82 void Ephemeris::unbind()
83 {
84     _latProp = 0;
85 }
86
87 void Ephemeris::update(double)
88 {
89     SGTime* st = globals->get_time_params();
90     _impl->update(st->getMjd(), st->getLst(), _latProp->getDoubleValue());
91 }