1 // magvarmanager.cxx -- Wraps the SimGear SGMagVar in a subsystem
3 // Copyright (C) 2012 James Turner - zakalawe@mac.com
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.
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.
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.
24 #include "magvarmanager.hxx"
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>
31 #include <Main/globals.hxx>
32 #include <Main/fg_props.hxx>
34 FGMagVarManager::FGMagVarManager() :
39 FGMagVarManager::~FGMagVarManager()
43 void FGMagVarManager::init()
45 update(0.0); // force an immediate update
48 void FGMagVarManager::bind()
50 _magVarNode = fgGetNode("/environment/magnetic-variation-deg", true);
51 _magDipNode = fgGetNode("/environment/magnetic-dip-deg", true);
54 void FGMagVarManager::unbind()
56 _magVarNode = SGPropertyNode_ptr();
57 _magDipNode = SGPropertyNode_ptr();
60 void FGMagVarManager::update(double dt)
64 // update magvar model
65 _magVar->update( globals->get_aircraft_position(),
66 globals->get_time_params()->getJD() );
68 _magVarNode->setDoubleValue(_magVar->get_magvar() * SG_RADIANS_TO_DEGREES);
69 _magDipNode->setDoubleValue(_magVar->get_magdip() * SG_RADIANS_TO_DEGREES);