FlightGear next
ephemeris.cxx
Go to the documentation of this file.
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
24
25#include <simgear/timing/sg_time.hxx>
26#include <simgear/ephemeris/ephemeris.hxx>
27
28#include <Main/globals.hxx>
29
30static void tieStar(const char* prop, Star* s, double (Star::*getter)() const)
31{
32 fgGetNode(prop, true)->tie(SGRawValueMethods<Star, double>(*s, getter, NULL));
33}
34
35static void tieMoonPos(const char* prop, MoonPos* s, double (MoonPos::*getter)() const)
36{
37 fgGetNode(prop, true)->tie(SGRawValueMethods<MoonPos, double>(*s, getter, NULL));
38}
39
43
47
48SGEphemeris* Ephemeris::data()
49{
50 return _impl.get();
51}
52
54{
55 SGPath ephem_data_path(globals->get_fg_root());
56 ephem_data_path.append("Astro");
57 _impl.reset(new SGEphemeris(ephem_data_path));
58
59 tieStar("/ephemeris/sun/xs", _impl->get_sun(), &Star::getxs);
60 tieStar("/ephemeris/sun/ys", _impl->get_sun(), &Star::getys);
61 tieStar("/ephemeris/sun/ze", _impl->get_sun(), &Star::getze);
62 tieStar("/ephemeris/sun/ye", _impl->get_sun(), &Star::getye);
63 tieStar("/ephemeris/sun/lat-deg", _impl->get_sun(), &Star::getLat);
64
65 tieMoonPos("/ephemeris/moon/xg", _impl->get_moon(), &MoonPos::getxg);
66 tieMoonPos("/ephemeris/moon/yg", _impl->get_moon(), &MoonPos::getyg);
67 tieMoonPos("/ephemeris/moon/ze", _impl->get_moon(), &MoonPos::getze);
68 tieMoonPos("/ephemeris/moon/ye", _impl->get_moon(), &MoonPos::getye);
69 tieMoonPos("/ephemeris/moon/lat-deg", _impl->get_moon(), &MoonPos::getLat);
70 tieMoonPos("/ephemeris/moon/distance", _impl->get_moon(), &MoonPos::getDistance);
71 tieMoonPos("/ephemeris/moon/phase", _impl->get_moon(), &MoonPos::getPhase);
72 tieMoonPos("/ephemeris/moon/phase-angle", _impl->get_moon(), &MoonPos::getPhaseAngle);
73
74 _latProp = fgGetNode("/position/latitude-deg", true);
75
76 update(0.0);
77}
78
80{
81 _impl.reset();
82}
83
85{
86}
87
89{
90}
91
93{
94 _latProp = 0;
95 _latProp.reset();
96}
97
99{
100 SGTime* st = globals->get_time_params();
101 _impl->update(st->getMjd(), st->getLst(), _latProp->getDoubleValue());
102}
103
104
105// Register the subsystem.
106SGSubsystemMgr::Registrant<Ephemeris> registrantEphemeris;
void bind() override
Definition ephemeris.cxx:88
void postinit() override
Definition ephemeris.cxx:84
void update(double dt) override
Definition ephemeris.cxx:98
SGEphemeris * data()
Definition ephemeris.cxx:48
void unbind() override
Definition ephemeris.cxx:92
void shutdown() override
Definition ephemeris.cxx:79
void init() override
Definition ephemeris.cxx:53
static void tieMoonPos(const char *prop, MoonPos *s, double(MoonPos::*getter)() const)
Definition ephemeris.cxx:35
static void tieStar(const char *prop, Star *s, double(Star::*getter)() const)
Definition ephemeris.cxx:30
SGSubsystemMgr::Registrant< Ephemeris > registrantEphemeris
FGGlobals * globals
Definition globals.cxx:142
SGPropertyNode * fgGetNode(const char *path, bool create)
Get a property node.
Definition proptest.cpp:27