]> git.mxchange.org Git - flightgear.git/blob - src/Environment/magvarmanager.cxx
Make magavr a regular subsystem.
[flightgear.git] / src / Environment / magvarmanager.cxx
1 // magvarmanager.cxx -- Wraps the SimGear SGMagVar in a subsystem
2 //
3 // Copyright (C) 2012  James Turner - zakalawe@mac.com
4 //
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License as
7 // published by the Free Software Foundation; either version 2 of the
8 // License, or (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful, but
11 // WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13 // General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
18 //
19
20 #ifdef HAVE_CONFIG_H
21 #  include <config.h>
22 #endif
23
24 #include "magvarmanager.hxx"
25
26 #include <simgear/sg_inlines.h>
27 #include <simgear/magvar/magvar.hxx>
28 #include <simgear/timing/sg_time.hxx>
29
30 #include <Main/globals.hxx>
31 #include <Main/fg_props.hxx>
32
33 FGMagVarManager::FGMagVarManager() :
34     _magVar(new SGMagVar)
35 {
36 }
37
38 FGMagVarManager::~FGMagVarManager()
39 {
40 }
41
42 void FGMagVarManager::init()
43 {
44     update(0.0); // force an immediate update
45 }
46
47 void FGMagVarManager::bind()
48 {
49   _magVarNode = fgGetNode("/environment/magnetic-variation-deg", true);
50   _magDipNode = fgGetNode("/environment/magnetic-dip-deg", true);
51 }
52
53 void FGMagVarManager::unbind()
54 {
55   _magVarNode = SGPropertyNode_ptr();
56   _magDipNode = SGPropertyNode_ptr();
57 }
58
59 void FGMagVarManager::update(double dt)
60 {
61   SG_UNUSED(dt);
62     
63   // update magvar model
64   _magVar->update( globals->get_aircraft_position(),
65                      globals->get_time_params()->getJD() );
66   
67   _magVarNode->setDoubleValue(_magVar->get_magvar() * SG_RADIANS_TO_DEGREES);
68   _magDipNode->setDoubleValue(_magVar->get_magdip() * SG_RADIANS_TO_DEGREES);
69     
70 }