]> git.mxchange.org Git - flightgear.git/blobdiff - src/Instrumentation/wxradar.cxx
- Added ultra-light traffic is now a separate traffic class that can have its
[flightgear.git] / src / Instrumentation / wxradar.cxx
index 256cc563a4a78495bf66b743971756808adb3122..2727dd2efbded81f1b7dd2a47cc013110be19b15 100644 (file)
@@ -60,8 +60,6 @@ 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
 
 
@@ -95,7 +93,11 @@ wxRadarBg::init ()
 
     _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());
 
     SGPath tpath(globals->get_fg_root());
     string path = _Instrument->getStringValue("echo-texture-path",
@@ -168,45 +170,41 @@ wxRadarBg::init ()
     _radarGeode = new osg::Geode;
     osg::StateSet* stateSet = _radarGeode->getOrCreateStateSet();
     stateSet->setTextureAttributeAndModes(0, _wxEcho.get());
-    osg::Geometry* geom = new osg::Geometry;
-    geom->setUseDisplayList(false);
+    _geom = new osg::Geometry;
+    _geom->setUseDisplayList(false);
     // Initially allocate space for 128 quads
-    osg::Vec2Array* vertices = new osg::Vec2Array;
-    vertices->setDataVariance(osg::Object::DYNAMIC);
-    vertices->reserve(128 * 4);
-    geom->setVertexArray(vertices);
-    osg::Vec2Array* texCoords = new osg::Vec2Array;
-    texCoords->setDataVariance(osg::Object::DYNAMIC);
-    texCoords->reserve(128 * 4);
-    geom->setTexCoordArray(0, texCoords);
+    _vertices = new osg::Vec2Array;
+    _vertices->setDataVariance(osg::Object::DYNAMIC);
+    _vertices->reserve(128 * 4);
+    _geom->setVertexArray(_vertices);
+    _texCoords = new osg::Vec2Array;
+    _texCoords->setDataVariance(osg::Object::DYNAMIC);
+    _texCoords->reserve(128 * 4);
+    _geom->setTexCoordArray(0, _texCoords);
     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);
+    _geom->setColorBinding(osg::Geometry::BIND_PER_PRIMITIVE_SET);
+    _geom->setColorArray(colors);
     osg::PrimitiveSet* pset = new osg::DrawArrays(osg::PrimitiveSet::QUADS);
     pset->setDataVariance(osg::Object::DYNAMIC);
-    geom->addPrimitiveSet(pset);
+    _geom->addPrimitiveSet(pset);
     pset = new osg::DrawArrays(osg::PrimitiveSet::QUADS);
     pset->setDataVariance(osg::Object::DYNAMIC);
-    geom->addPrimitiveSet(pset);
+    _geom->addPrimitiveSet(pset);
     pset = new osg::DrawArrays(osg::PrimitiveSet::TRIANGLES);
     pset->setDataVariance(osg::Object::DYNAMIC);
-    geom->addPrimitiveSet(pset);
-    geom->setInitialBound(osg::BoundingBox(osg::Vec3f(-256.0f, -256.0f, 0.0f),
+    _geom->addPrimitiveSet(pset);
+    _geom->setInitialBound(osg::BoundingBox(osg::Vec3f(-256.0f, -256.0f, 0.0f),
             osg::Vec3f(256.0f, 256.0f, 0.0f)));
-    _radarGeode->addDrawable(geom);
+    _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());
 
     osg::Camera* camera = _odg->getCamera();
     camera->addChild(_radarGeode.get());
-
-    _geom = static_cast<osg::Geometry*>(_radarGeode->getDrawable(0));
-    _vertices = static_cast<osg::Vec2Array*>(_geom->getVertexArray());
-    _texCoords = static_cast<osg::Vec2Array*>(_geom->getTexCoordArray(0));
 }
 
 
@@ -281,7 +279,8 @@ wxRadarBg::update (double delta_time_sec)
         // 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());
+        //_odg->set_texture(_texture_path.c_str(), _resultTexture->getHandle());
+
         _last_switchKnob = switchKnob;
     }
 
@@ -378,12 +377,12 @@ wxRadarBg::update (double delta_time_sec)
             _texCoords->push_back(osg::Vec2f(0.5f, 0.5f));
             _vertices->push_back(osg::Vec2f(-xOffset, 256.0 + yOffset));
             maskPSet->set(osg::PrimitiveSet::QUADS, firstQuadVert, 4);
+
             // The triangles aren't supposed to be textured, but there's
             // no need to set up a different Geometry, switch modes,
             // etc. I happen to know that there's a white pixel in the
             // texture at 1.0, 0.0 :)
             float centerY = tan(30 * SG_DEGREES_TO_RADIANS);
-            const osg::Vec2f whiteSpot(1.0f, 0.0f);
             _vertices->push_back(osg::Vec2f(0.0, 0.0));
             _vertices->push_back(osg::Vec2f(-256.0, 0.0));
             _vertices->push_back(osg::Vec2f(-256.0, 256.0 * centerY));
@@ -400,6 +399,7 @@ wxRadarBg::update (double delta_time_sec)
             _vertices->push_back(osg::Vec2f(256.0, -256.0));
             _vertices->push_back(osg::Vec2f(-256.0, -256.0));
 
+            const osg::Vec2f whiteSpot(1.0f, 0.0f);
             for (int i = 0; i < 3 * 4; i++)
                 _texCoords->push_back(whiteSpot);
 
@@ -695,8 +695,6 @@ wxRadarBg::center_map()
 void
 wxRadarBg::apply_map_offset()
 {
-    if (_display_mode != MAP)
-        return;
     double lat = _user_lat_node->getDoubleValue();
     double lon = _user_lon_node->getDoubleValue();
     double bearing, distance, az2;