Debian Codegraph @

src/Environment/magvarmanager.cxx

raw symbols SCIP
1 // magvarmanager.cxx -- Wraps the SimGear SGMagVar in a subsystem
2 //
3 // Copyright (C) 2012 James Turner - [email protected]
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 #include <simgear/math/SGMath.hxx>
30
31 #include <Main/globals.hxx>
32 #include <Main/fg_props.hxx>
33
34 FGMagVarManager::FGMagVarManager() :
35 _magVar(new SGMagVar)
36 {
37 }
38
39 FGMagVarManager::~FGMagVarManager()
40 {
41 }
42
43 void FGMagVarManager::init()
44 {
45 update(0.0); // force an immediate update
46 }
47
48 void FGMagVarManager::bind()
49 {
50 _magVarNode = fgGetNode("/environment/magnetic-variation-deg", true);
51 _magDipNode = fgGetNode("/environment/magnetic-dip-deg", true);
52 }
53
54 void FGMagVarManager::unbind()
55 {
56 _magVarNode = SGPropertyNode_ptr();
57 _magDipNode = SGPropertyNode_ptr();
58 }
59
60 void FGMagVarManager::update(double dt)
61 {
62 SG_UNUSED(dt);
63
64 // update magvar model
65 _magVar->update( globals->get_aircraft_position(),
66 globals->get_time_params()->getJD() );
67
68 _magVarNode->setDoubleValue(_magVar->get_magvar() * SG_RADIANS_TO_DEGREES);
69 _magDipNode->setDoubleValue(_magVar->get_magdip() * SG_RADIANS_TO_DEGREES);
70
71 }
72
73
74 // Register the subsystem.
75 SGSubsystemMgr::Registrant<FGMagVarManager> registrantFGMagVarManager;