]> git.mxchange.org Git - flightgear.git/blobdiff - src/Instrumentation/wxradar.cxx
Projection matrix and texture size should be coherent
[flightgear.git] / src / Instrumentation / wxradar.cxx
index d039ba63191337b87bf8f9887cc0c42f9d4dd640..968db833a4f32ee59ccf396a004075c3118a354a 100644 (file)
@@ -32,6 +32,8 @@
 #include <osg/Matrixf>
 #include <osg/PrimitiveSet>
 #include <osg/StateSet>
+#include <osg/Version>
+#include <osgDB/ReaderWriter>
 #include <osgDB/WriteFile>
 
 #include <simgear/constants.h>
 #include <simgear/misc/sg_path.hxx>
 #include <simgear/math/sg_geodesy.hxx>
 
+#include <sstream>
+#include <iomanip>
+using std::stringstream;
+using std::endl;
+using std::setprecision;
+using std::fixed;
+using std::setw;
+using std::setfill;
+
 #include <Main/fg_props.hxx>
 #include <Main/globals.hxx>
 #include <Cockpit/panel.hxx>
 #include <Cockpit/hud.hxx>
-#include <AIModel/AIBase.hxx>
-#include <AIModel/AIManager.hxx>
-#include <AIModel/AIBallistic.hxx>
 
+#include <Include/general.hxx>
 #include "instrument_mgr.hxx"
 #include "od_gauge.hxx"
 #include "wxradar.hxx"
 
 
-typedef list <SGSharedPtr<FGAIBase> > radar_list_type;
-typedef radar_list_type::iterator radar_list_iterator;
-typedef radar_list_type::const_iterator radar_list_const_iterator;
-
 
-// texture name to use in 2D and 3D instruments
-static const char *ODGAUGE_NAME = "Aircraft/Instruments/Textures/od_wxradar.rgb";
 static const float UNIT = 1.0f / 8.0f;  // 8 symbols in a row/column in the texture
+static const char *DEFAULT_FONT = "typewriter.txf";
 
 
-wxRadarBg::wxRadarBg ( SGPropertyNode *node) :
+wxRadarBg::wxRadarBg(SGPropertyNode *node) :
     _name(node->getStringValue("name", "radar")),
     _num(node->getIntValue("number", 0)),
     _interval(node->getDoubleValue("update-interval-sec", 1.0)),
-    _time( 0.0 ),
-    _last_switchKnob( "off" ),
-    _sim_init_done ( false ),
-    _resultTexture( 0 ),
-    _wxEcho( 0 ),
-    _odg( 0 )
+    _time(0.0),
+    _sim_init_done(false),
+    _odg(0),
+    _last_switchKnob("off"),
+    _resultTexture(0),
+    _wxEcho(0)
 {
-    const char *tacan_source = node->getStringValue("tacan-source",
-            "/instrumentation/tacan");
+    string branch;
+    branch = "/instrumentation/" + _name;
+    _Instrument = fgGetNode(branch.c_str(), _num, true);
+
+    const char *tacan_source = node->getStringValue("tacan-source", "/instrumentation/tacan");
     _Tacan = fgGetNode(tacan_source, true);
+
+    _font_node = _Instrument->getNode("font", true);
+
+#define INITFONT(p, val, type) if (!_font_node->hasValue(p)) _font_node->set##type##Value(p, val)
+    INITFONT("name", DEFAULT_FONT, String);
+    INITFONT("size", 8, Float);
+    INITFONT("line-spacing", 0.25, Float);
+    INITFONT("color/red", 0, Float);
+    INITFONT("color/green", 0.8, Float);
+    INITFONT("color/blue", 0, Float);
+    INITFONT("color/alpha", 1, Float);
+#undef INITFONT
+
+    _font_node->addChangeListener(this, true);
 }
 
 
 wxRadarBg::~wxRadarBg ()
 {
+    _font_node->removeChangeListener(this);
 }
 
 
 void
 wxRadarBg::init ()
 {
-    string branch;
-    branch = "/instrumentation/" + _name;
-
-    _Instrument = fgGetNode(branch.c_str(), _num, true );
     _serviceable_node = _Instrument->getNode("serviceable", true);
-    _resultTexture = FGTextureManager::createTexture( ODGAUGE_NAME );
+
+    // texture name to use in 2D and 3D instruments
+    _texture_path = _Instrument->getStringValue("radar-texture-path",
+            "Aircraft/Instruments/Textures/od_wxradar.rgb");
+    _resultTexture = FGTextureManager::createTexture(_texture_path.c_str(), false);
 
     SGPath tpath(globals->get_fg_root());
     string path = _Instrument->getStringValue("echo-texture-path",
@@ -103,11 +125,12 @@ wxRadarBg::init ()
     tpath.append(path);
 
     // no mipmap or else alpha will mix with pixels on the border of shapes, ruining the effect
-    _wxEcho = SGLoadTexture2D(tpath.c_str(), false, false);
+    _wxEcho = SGLoadTexture2D(tpath, false, false);
+
 
     _Instrument->setFloatValue("trk", 0.0);
     _Instrument->setFloatValue("tilt", 0.0);
-    _Instrument->setStringValue("status","");
+    _Instrument->setStringValue("status", "");
     // those properties are used by a radar instrument of a MFD
     // input switch = OFF | TST | STBY | ON
     // input mode = WX | WXA | MAP
@@ -119,11 +142,10 @@ wxRadarBg::init ()
     // input range = n nm (20/40/80)
     // input display-mode = arc | rose | map | plan
 
-    FGInstrumentMgr *imgr = (FGInstrumentMgr *) globals->get_subsystem("instrumentation");
-    _odg = (FGODGauge *) imgr->get_subsystem("od_gauge");
-    _odg->setSize(256);
+    FGInstrumentMgr *imgr = (FGInstrumentMgr *)globals->get_subsystem("instrumentation");
+    _odg = (FGODGauge *)imgr->get_subsystem("od_gauge");
+    _odg->setSize(512);
 
-    _ai = (FGAIManager*)globals->get_subsystem("ai_model");
     _ai_enabled_node = fgGetNode("/sim/ai/enabled", true);
 
     _user_lat_node = fgGetNode("/position/latitude-deg", true);
@@ -148,14 +170,16 @@ wxRadarBg::init ()
     _radar_weather_node     = n->getNode("WX", true);
     _radar_position_node    = n->getNode("pos", true);
     _radar_data_node        = n->getNode("data", true);
+    _radar_symbol_node      = n->getNode("symbol", true);
     _radar_centre_node      = n->getNode("centre", true);
+    _radar_rotate_node      = n->getNode("rotate", true);
 
     _radar_centre_node->setBoolValue(false);
-    if (_radar_coverage_node->getType() == SGPropertyNode::NONE)
+    if (!_radar_coverage_node->hasValue())
         _radar_coverage_node->setFloatValue(120);
-    if (_radar_ref_rng_node->getType() == SGPropertyNode::NONE)
+    if (!_radar_ref_rng_node->hasValue())
         _radar_ref_rng_node->setDoubleValue(35);
-    if (_radar_hdg_marker_node->getType() == SGPropertyNode::NONE)
+    if (!_radar_hdg_marker_node->hasValue())
         _radar_hdg_marker_node->setBoolValue(true);
 
     _x_offset = 0;
@@ -166,7 +190,7 @@ wxRadarBg::init ()
     // primitive sets so we can have different kinds of polys and
     // choose a different overall color for each set.
     _radarGeode = new osg::Geode;
-    osg::StateSetstateSet = _radarGeode->getOrCreateStateSet();
+    osg::StateSet *stateSet = _radarGeode->getOrCreateStateSet();
     stateSet->setTextureAttributeAndModes(0, _wxEcho.get());
     _geom = new osg::Geometry;
     _geom->setUseDisplayList(false);
@@ -179,13 +203,13 @@ wxRadarBg::init ()
     _texCoords->setDataVariance(osg::Object::DYNAMIC);
     _texCoords->reserve(128 * 4);
     _geom->setTexCoordArray(0, _texCoords);
-    osg::Vec3Arraycolors = new osg::Vec3Array;
+    osg::Vec3Array *colors = new osg::Vec3Array;
     colors->push_back(osg::Vec3(1.0f, 1.0f, 1.0f)); // color of echos
     colors->push_back(osg::Vec3(1.0f, 0.0f, 0.0f)); // arc mask
     colors->push_back(osg::Vec3(0.0f, 0.0f, 0.0f)); // rest of mask
     _geom->setColorBinding(osg::Geometry::BIND_PER_PRIMITIVE_SET);
     _geom->setColorArray(colors);
-    osg::PrimitiveSetpset = new osg::DrawArrays(osg::PrimitiveSet::QUADS);
+    osg::PrimitiveSet *pset = new osg::DrawArrays(osg::PrimitiveSet::QUADS);
     pset->setDataVariance(osg::Object::DYNAMIC);
     _geom->addPrimitiveSet(pset);
     pset = new osg::DrawArrays(osg::PrimitiveSet::QUADS);
@@ -199,10 +223,13 @@ wxRadarBg::init ()
     _radarGeode->addDrawable(_geom);
     _odg->allocRT();
     // Texture in the 2D panel system
-    FGTextureManager::addTexture(ODGAUGE_NAME, _odg->getTexture());
+    FGTextureManager::addTexture(_texture_path.c_str(), _odg->getTexture());
+
+    _textGeode = new osg::Geode;
 
-    osg::Cameracamera = _odg->getCamera();
+    osg::Camera *camera = _odg->getCamera();
     camera->addChild(_radarGeode.get());
+    camera->addChild(_textGeode.get());
 }
 
 
@@ -221,7 +248,7 @@ const osg::Vec2f echoTexCoords[4] = {
 
 // helper
 static void
-addQuad(osg::Vec2Array* vertices, osg::Vec2Array* texCoords,
+addQuad(osg::Vec2Array *vertices, osg::Vec2Array *texCoords,
         const osg::Matrixf& transform, const osg::Vec2f& texBase)
 {
     for (int i = 0; i < 4; i++) {
@@ -243,14 +270,14 @@ osg::Matrixf wxRotate(float angle)
 void
 wxRadarBg::update (double delta_time_sec)
 {
-    if ( ! _sim_init_done ) {
-        if ( ! fgGetBool("sim/sceneryloaded", false) )
+    if (!_sim_init_done) {
+        if (!fgGetBool("sim/sceneryloaded", false))
             return;
 
         _sim_init_done = true;
     }
-    if ( !_odg || ! _serviceable_node->getBoolValue() ) {
-        _Instrument->setStringValue("status","");
+    if (!_odg || !_serviceable_node->getBoolValue()) {
+        _Instrument->setStringValue("status", "");
         return;
     }
     _time += delta_time_sec;
@@ -272,21 +299,22 @@ wxRadarBg::update (double delta_time_sec)
     }
 
     string switchKnob = _Instrument->getStringValue("switch", "on");
-    if ( _last_switchKnob != switchKnob ) {
+    if (_last_switchKnob != switchKnob) {
         // since 3D models don't share textures with the rest of the world
         // we must locate them and replace their handle by hand
         // only do that when the instrument is turned on
-        //if ( _last_switchKnob == "off" )
-        //_odg->set_texture( ODGAUGE_NAME, _resultTexture->getHandle());
+        //if (_last_switchKnob == "off")
+        //_odg->set_texture(_texture_path.c_str(), _resultTexture->getHandle());
+
         _last_switchKnob = switchKnob;
     }
 
-    if ( switchKnob == "off" ) {
-        _Instrument->setStringValue("status","");
-    } else if ( switchKnob == "stby" ) {
-        _Instrument->setStringValue("status","STBY");
-    } else if ( switchKnob == "tst" ) {
-        _Instrument->setStringValue("status","TST");
+    if (switchKnob == "off") {
+        _Instrument->setStringValue("status", "");
+    } else if (switchKnob == "stby") {
+        _Instrument->setStringValue("status", "STBY");
+    } else if (switchKnob == "tst") {
+        _Instrument->setStringValue("status", "TST");
         // find something interesting to do...
     } else {
         float r = _Instrument->getFloatValue("range", 40.0);
@@ -302,12 +330,12 @@ wxRadarBg::update (double delta_time_sec)
         _scale = 200.0 / _range_nm;
         _angle_offset = 0;
 
-        if ( _display_mode == ARC ) {
+        if (_display_mode == ARC) {
             _scale = 2*200.0f / _range_nm;
             _angle_offset = -_view_heading;
             _centerTrans.makeTranslate(0.0f, -200.0f, 0.0f);
 
-        } else if ( _display_mode == MAP ) {
+        } else if (_display_mode == MAP) {
             apply_map_offset();
 
             bool centre = _radar_centre_node->getBoolValue();
@@ -326,20 +354,23 @@ wxRadarBg::update (double delta_time_sec)
 
             _centerTrans.makeTranslate(_x_offset, _y_offset, 0.0f);
 
-        } else if ( _display_mode == PLAN ) {
-            // no sense I presume
+        } else if (_display_mode == PLAN) {
+            if (_radar_rotate_node->getBoolValue()) {
+                _angle_offset = -_view_heading;
+            }
         } else {
             // rose
         }
 
         _vertices->clear();
         _texCoords->clear();
+        _textGeode->removeDrawables(0, _textGeode->getNumDrawables());
 
 
         update_weather();
 
 
-        osg::DrawArraysquadPSet
+        osg::DrawArrays *quadPSet
                 = static_cast<osg::DrawArrays*>(_geom->getPrimitiveSet(0));
         quadPSet->set(osg::PrimitiveSet::QUADS, 0, _vertices->size());
         quadPSet->dirty();
@@ -355,12 +386,12 @@ wxRadarBg::update (double delta_time_sec)
             ---------
         */
 
-        osg::DrawArraysmaskPSet
+        osg::DrawArrays *maskPSet
                 = static_cast<osg::DrawArrays*>(_geom->getPrimitiveSet(1));
-        osg::DrawArraystrimaskPSet
+        osg::DrawArrays *trimaskPSet
                 = static_cast<osg::DrawArrays*>(_geom->getPrimitiveSet(2));
 
-        if ( _display_mode == ARC ) {
+        if (_display_mode == ARC) {
             float xOffset = 256.0f;
             float yOffset = 200.0f;
 
@@ -400,8 +431,7 @@ wxRadarBg::update (double delta_time_sec)
             for (int i = 0; i < 3 * 4; i++)
                 _texCoords->push_back(whiteSpot);
 
-            trimaskPSet->set(osg::PrimitiveSet::TRIANGLES, firstQuadVert + 4,
-                    3 * 4);
+            trimaskPSet->set(osg::PrimitiveSet::TRIANGLES, firstQuadVert + 4, 3 * 4);
 
         } else {
             maskPSet->set(osg::PrimitiveSet::QUADS, 0, 0);
@@ -496,7 +526,7 @@ wxRadarBg::update_weather()
 
     // draw lightning echos
     bool drawLightning = _Instrument->getBoolValue("lightning", true);
-    if ( drawLightning ) {
+    if (drawLightning) {
         const osg::Vec2f texBase(3 * UNIT, 4 * UNIT);
 
         for (iradarEcho = radarEcho->begin(); iradarEcho != end; ++iradarEcho) {
@@ -518,6 +548,41 @@ wxRadarBg::update_weather()
 }
 
 
+void
+wxRadarBg::update_data(const SGPropertyNode *ac, double altitude, double heading,
+        double radius, double bearing, bool selected)
+{
+    osgText::Text *callsign = new osgText::Text;
+    callsign->setFont(_font.get());
+    callsign->setFontResolution(12, 12);
+    callsign->setCharacterSize(_font_size);
+    callsign->setColor(selected ? osg::Vec4(1, 1, 1, 1) : _font_color);
+    osg::Matrixf m(wxRotate(-bearing)
+            * osg::Matrixf::translate(0.0f, radius, 0.0f)
+            * wxRotate(bearing) * _centerTrans);
+
+    osg::Vec3 pos = m.preMult(osg::Vec3(16, 16, 0));
+    // cast to int's, otherwise text comes out ugly
+    callsign->setPosition(osg::Vec3((int)pos.x(), (int)pos.y(), 0));
+    callsign->setAlignment(osgText::Text::LEFT_BOTTOM_BASE_LINE);
+    callsign->setLineSpacing(_font_spacing);
+
+    const char *identity = ac->getStringValue("transponder-id");
+    if (!identity[0])
+        identity = ac->getStringValue("callsign");
+
+    stringstream text;
+    text << identity << endl
+            << setprecision(0) << fixed
+            << setw(3) << setfill('0') << heading * SG_RADIANS_TO_DEGREES << "\xB0 "
+            << setw(0) << altitude << "ft" << endl
+            << ac->getDoubleValue("velocities/true-airspeed-kt") << "kts";
+
+    callsign->setText(text.str());
+    _textGeode->addDrawable(callsign);
+}
+
+
 void
 wxRadarBg::update_aircraft()
 {
@@ -525,51 +590,75 @@ wxRadarBg::update_aircraft()
         return;
 
     bool draw_echoes = _radar_position_node->getBoolValue();
-    bool draw_symbols = _radar_data_node->getBoolValue();
-    if (!draw_echoes && !draw_symbols)
-        return;
-
-    radar_list_type radar_list = _ai->get_ai_list();
-    SG_LOG(SG_GENERAL, SG_DEBUG, "Radar: AI submodel list size" << radar_list.size());
-    if (radar_list.empty())
+    bool draw_symbols = _radar_symbol_node->getBoolValue();
+    bool draw_data = _radar_data_node->getBoolValue();
+    if (!draw_echoes && !draw_symbols && !draw_data)
         return;
 
-    SG_LOG(SG_GENERAL, SG_DEBUG, "Radar: Loading AI submodels ");
-    const double echo_radii[] = {0, 1, 1.5, 1.5, 0.001, 0.1, 1.5, 2, 1.5, 1.5};
-
     double user_lat = _user_lat_node->getDoubleValue();
     double user_lon = _user_lon_node->getDoubleValue();
     double user_alt = _user_alt_node->getDoubleValue();
 
-    radar_list_iterator it = radar_list.begin();
-    radar_list_iterator end = radar_list.end();
+    float limit = _radar_coverage_node->getFloatValue();
+    if (limit > 180)
+        limit = 180;
+    else if (limit < 0)
+        limit = 0;
+    limit *= SG_DEGREES_TO_RADIANS;
 
-    for (; it != end; ++it) {
-        FGAIBase *ac = *it;
-        int type       = ac->getType();
-        double lat     = ac->_getLatitude();
-        double lon     = ac->_getLongitude();
-        double alt     = ac->_getAltitude();
-        double heading = ac->_getHeading();
+    int selected_id = fgGetInt("/instrumentation/radar/selected-id", -1);
+
+    const SGPropertyNode *selected_ac = 0;
+    const SGPropertyNode *ai = fgGetNode("/ai/models", true);
+
+    for (int i = ai->nChildren() - 1; i >= -1; i--) {
+        const SGPropertyNode *model;
+
+        if (i < 0) { // last iteration: selected model
+            model = selected_ac;
+        } else {
+            model = ai->getChild(i);
+            if (!model->nChildren())
+                continue;
+            if (model->getIntValue("id") == selected_id) {
+                selected_ac = model;  // save selected model for last iteration
+                continue;
+            }
+        }
+        if (!model)
+            continue;
+
+        double echo_radius, sigma;
+        const string name = model->getName();
+        if (name == "aircraft" || name == "tanker")
+            echo_radius = 1, sigma = 1;
+        else if (name == "multiplayer" || name == "wingman" || name == "static")
+            echo_radius = 1.5, sigma = 1;
+        else if (name == "ship" || name == "carrier" || name == "storm")
+            echo_radius = 1.5, sigma = 100;
+        else if (name == "thermal")
+            echo_radius = 2, sigma = 100;
+        else if (name == "rocket")
+            echo_radius = 0.1, sigma = 0.1;
+        else if (name == "ballistic")
+            echo_radius = 0.001, sigma = 0.001;
+        else
+             continue;
+
+        double lat = model->getDoubleValue("position/latitude-deg");
+        double lon = model->getDoubleValue("position/longitude-deg");
+        double alt = model->getDoubleValue("position/altitude-ft");
+        double heading = model->getDoubleValue("orientation/true-heading-deg");
 
         double range, bearing;
         calcRangeBearing(user_lat, user_lon, lat, lon, range, bearing);
 
-        //SG_LOG(SG_GENERAL, SG_DEBUG,
-        //        "Radar: ID=" << ac->getID() << "(" << radar_list.size() << ")"
-        //        << " type=" << type
-        //        << " view_heading=" << _view_heading * SG_RADIANS_TO_DEGREES
-        //        << " alt=" << alt
-        //        << " heading=" << heading
-        //        << " range=" << range
-        //        << " bearing=" << bearing);
-
         bool isVisible = withinRadarHorizon(user_alt, alt, range);
-        SG_LOG(SG_GENERAL, SG_DEBUG, "Radar: visible " << isVisible);
+
         if (!isVisible)
             continue;
 
-        if (!inRadarRange(type, range))
+        if (!inRadarRange(sigma, range))
             continue;
 
         bearing *= SG_DEGREES_TO_RADIANS;
@@ -578,12 +667,6 @@ wxRadarBg::update_aircraft()
         float radius = range * _scale;
         float angle = calcRelBearing(bearing, _view_heading);
 
-        float limit = _radar_coverage_node->getFloatValue();
-        if (limit > 180)
-            limit = 180;
-        else if (limit < 0)
-            limit = 0;
-        limit *= SG_DEGREES_TO_RADIANS;
         if (angle > limit || angle < -limit)
             continue;
 
@@ -592,19 +675,13 @@ wxRadarBg::update_aircraft()
 
         // pos mode
         if (draw_echoes) {
-            float echo_radius = echo_radii[type] * 120;
-            float size = echo_radius * UNIT;
+            float size = echo_radius * 120 * UNIT;
 
             const osg::Vec2f texBase(3 * UNIT, 3 * UNIT);
             osg::Matrixf m(osg::Matrixf::scale(size, size, 1.0f)
                     * osg::Matrixf::translate(0.0f, radius, 0.0f)
                     * wxRotate(bearing) * _centerTrans);
             addQuad(_vertices, _texCoords, m, texBase);
-
-            //SG_LOG(SG_GENERAL, SG_DEBUG, "Radar:    drawing AI"
-            //        << " x=" << x << " y=" << y
-            //        << " radius=" << radius
-            //        << " angle=" << angle * SG_RADIANS_TO_DEGREES);
         }
 
         // data mode
@@ -616,12 +693,10 @@ wxRadarBg::update_aircraft()
                     * osg::Matrixf::translate(0.0f, radius, 0.0f)
                     * wxRotate(bearing) * _centerTrans);
             addQuad(_vertices, _texCoords, m, texBase);
-
-            //SG_LOG(SG_GENERAL, SG_DEBUG, "Radar:    drawing data"
-            //        << " x=" << x <<" y="<< y
-            //        << " bearing=" << angle * SG_RADIANS_TO_DEGREES
-            //        << " radius=" << radius);
         }
+
+        if (draw_data || i < 0)  // selected one (i == -1) is always drawn
+            update_data(model, alt, heading, radius, bearing, i < 0);
     }
 }
 
@@ -718,13 +793,13 @@ wxRadarBg::withinRadarHorizon(double user_alt, double alt, double range_nm)
         alt = 0;
 
     double radarhorizon = 1.23 * (sqrt(alt) + sqrt(user_alt));
-    SG_LOG(SG_GENERAL, SG_DEBUG, "Radar: horizon " << radarhorizon);
+    //SG_LOG(SG_GENERAL, SG_DEBUG, "Radar: horizon " << radarhorizon);
     return radarhorizon >= range_nm;
 }
 
 
 bool
-wxRadarBg::inRadarRange(int type, double range_nm)
+wxRadarBg::inRadarRange(double sigma, double range_nm)
 {
     //The Radar Equation:
     //
@@ -740,21 +815,20 @@ wxRadarBg::inRadarRange(int type, double range_nm)
     //
     // TODO - make the maximum range adjustable at runtime
 
-    const double sigma[] = {0, 1, 100, 100, 0.001, 0.1, 100, 100, 1, 1};
     double constant = _radar_ref_rng;
 
     if (constant <= 0)
         constant = 35;
 
-    double maxrange = constant * pow(sigma[type], 0.25);
-    SG_LOG(SG_GENERAL, SG_DEBUG, "Radar: max range " << maxrange);
+    double maxrange = constant * pow(sigma, 0.25);
+    //SG_LOG(SG_GENERAL, SG_DEBUG, "Radar: max range " << maxrange);
     return maxrange >= range_nm;
 }
 
 
 void
 wxRadarBg::calcRangeBearing(double lat, double lon, double lat2, double lon2,
-        double &range, double &bearing ) const
+        double &range, double &bearing) const
 {
     // calculate the bearing and range of the second pos from the first
     double az2, distance;
@@ -777,3 +851,48 @@ wxRadarBg::calcRelBearing(float bearing, float heading)
     return angle;
 }
 
+
+void
+wxRadarBg::updateFont()
+{
+    float red = _font_node->getFloatValue("color/red");
+    float green = _font_node->getFloatValue("color/green");
+    float blue = _font_node->getFloatValue("color/blue");
+    float alpha = _font_node->getFloatValue("color/alpha");
+    _font_color.set(red, green, blue, alpha);
+
+    _font_size = _font_node->getFloatValue("size");
+    _font_spacing = _font_size * _font_node->getFloatValue("line-spacing");
+    string path = _font_node->getStringValue("name", DEFAULT_FONT);
+
+    SGPath tpath;
+    if (path[0] != '/') {
+        tpath = globals->get_fg_root();
+        tpath.append("Fonts");
+        tpath.append(path);
+    } else {
+        tpath = path;
+    }
+
+#if (FG_OSG_VERSION >= 21000)
+    osg::ref_ptr<osgDB::ReaderWriter::Options> fontOptions = new osgDB::ReaderWriter::Options("monochrome");
+    osg::ref_ptr<osgText::Font> font = osgText::readFontFile(tpath.c_str(), fontOptions.get());
+#else
+    osg::ref_ptr<osgText::Font> font = osgText::readFontFile(tpath.c_str());
+#endif
+
+    if (font != 0) {
+        _font = font;
+        _font->setMinFilterHint(osg::Texture::NEAREST);
+        _font->setMagFilterHint(osg::Texture::NEAREST);
+        _font->setGlyphImageMargin(0);
+        _font->setGlyphImageMarginRatio(0);
+    }
+}
+
+void
+wxRadarBg::valueChanged(SGPropertyNode*)
+{
+    updateFont();
+}
+