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>
30 #include <Main/globals.hxx>
31 #include <Main/fg_props.hxx>
33 FGMagVarManager::FGMagVarManager() :
38 FGMagVarManager::~FGMagVarManager()
42 void FGMagVarManager::init()
44 update(0.0); // force an immediate update
47 void FGMagVarManager::bind()
49 _magVarNode = fgGetNode("/environment/magnetic-variation-deg", true);
50 _magDipNode = fgGetNode("/environment/magnetic-dip-deg", true);
53 void FGMagVarManager::unbind()
55 _magVarNode = SGPropertyNode_ptr();
56 _magDipNode = SGPropertyNode_ptr();
59 void FGMagVarManager::update(double dt)
63 // update magvar model
64 _magVar->update( globals->get_aircraft_position(),
65 globals->get_time_params()->getJD() );
67 _magVarNode->setDoubleValue(_magVar->get_magvar() * SG_RADIANS_TO_DEGREES);
68 _magDipNode->setDoubleValue(_magVar->get_magdip() * SG_RADIANS_TO_DEGREES);