+ osg::DrawArrays *maskPSet
+ = static_cast<osg::DrawArrays*>(_geom->getPrimitiveSet(1));
+ osg::DrawArrays *trimaskPSet
+ = static_cast<osg::DrawArrays*>(_geom->getPrimitiveSet(2));
+
+ if (_display_mode == ARC) {
+ float xOffset = 256.0f;
+ float yOffset = 200.0f;
+
+ int firstQuadVert = _vertices->size();
+ _texCoords->push_back(osg::Vec2f(0.5f, 0.25f));
+ _vertices->push_back(osg::Vec2f(-xOffset, 0.0 + yOffset));
+ _texCoords->push_back(osg::Vec2f(1.0f, 0.25f));
+ _vertices->push_back(osg::Vec2f(xOffset, 0.0 + yOffset));
+ _texCoords->push_back(osg::Vec2f(1.0f, 0.5f));
+ _vertices->push_back(osg::Vec2f(xOffset, 256.0 + yOffset));
+ _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);
+ _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));
+
+ _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));
+
+ _vertices->push_back(osg::Vec2f(-256, 0.0));
+ _vertices->push_back(osg::Vec2f(256.0, 0.0));
+ _vertices->push_back(osg::Vec2f(-256.0, -256.0));
+
+ _vertices->push_back(osg::Vec2f(256, 0.0));
+ _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);
+
+ trimaskPSet->set(osg::PrimitiveSet::TRIANGLES, firstQuadVert + 4, 3 * 4);
+
+ } else {
+ maskPSet->set(osg::PrimitiveSet::QUADS, 0, 0);
+ trimaskPSet->set(osg::PrimitiveSet::TRIANGLES, 0, 0);
+ }
+
+ maskPSet->dirty();
+ trimaskPSet->dirty();
+
+ // draw without mask
+ _vertices->clear();
+ _texCoords->clear();
+
+ update_aircraft();
+ update_tacan();
+ update_heading_marker();
+
+ quadPSet->set(osg::PrimitiveSet::QUADS, 0, _vertices->size());
+ quadPSet->dirty();
+ }
+}
+
+
+void
+wxRadarBg::update_weather()
+{
+ string modeButton = _Instrument->getStringValue("mode", "wx");
+ _radarEchoBuffer = *sgEnviro.get_radar_echo();
+
+ // pretend we have a scan angle bigger then the FOV
+ // TODO:check real fov, enlarge if < nn, and do clipping if > mm
+ const float fovFactor = 1.45f;
+ _Instrument->setStringValue("status", modeButton.c_str());
+
+ list_of_SGWxRadarEcho *radarEcho = &_radarEchoBuffer;
+ list_of_SGWxRadarEcho::iterator iradarEcho, end = radarEcho->end();
+ const float LWClevel[] = { 0.1f, 0.5f, 2.1f };
+
+ // draw the cloud radar echo
+ bool drawClouds = _radar_weather_node->getBoolValue();
+ if (drawClouds) {
+
+ // we do that in 3 passes, one for each color level
+ // this is to 'merge' same colors together
+ for (int level = 0; level <= 2; level++) {
+ float col = level * UNIT;
+
+ for (iradarEcho = radarEcho->begin(); iradarEcho != end; ++iradarEcho) {
+ int cloudId = iradarEcho->cloudId;
+ bool upgrade = (cloudId >> 5) & 1;
+ float lwc = iradarEcho->LWC + (upgrade ? 1.0f : 0.0f);
+
+ // skip ns
+ if (iradarEcho->LWC >= 0.5 && iradarEcho->LWC <= 0.6)
+ continue;
+
+ if (iradarEcho->lightning || lwc < LWClevel[level])
+ continue;
+
+ float radius = sgSqrt(iradarEcho->dist) * SG_METER_TO_NM * _scale;
+ float size = iradarEcho->radius * 2.0 * SG_METER_TO_NM * _scale;
+
+ if (radius - size > 180)
+ continue;
+
+ float angle = (iradarEcho->heading - _angle_offset) //* fovFactor
+ + 0.5 * SG_PI;
+
+ // Rotate echo into position, and rotate echo to have
+ // a constant orientation towards the
+ // airplane. Compass headings increase in clockwise
+ // direction, while graphics rotations follow
+ // right-hand (counter-clockwise) rule.
+ const osg::Vec2f texBase(col, (UNIT * (float) (4 + (cloudId & 3))));
+
+ osg::Matrixf m(osg::Matrixf::scale(size, size, 1.0f)
+ * osg::Matrixf::translate(0.0f, radius, 0.0f)
+ * wxRotate(angle) * _centerTrans);
+ addQuad(_vertices, _texCoords, m, texBase);
+
+ //SG_LOG(SG_GENERAL, SG_DEBUG, "Radar: drawing clouds"
+ // << " ID=" << cloudId
+ // << " x=" << x
+ // << " y="<< y
+ // << " radius=" << radius
+ // << " view_heading=" << _view_heading * SG_RADIANS_TO_DEGREES
+ // << " heading=" << iradarEcho->heading * SG_RADIANS_TO_DEGREES
+ // << " angle=" << angle * SG_RADIANS_TO_DEGREES);
+ }
+ }
+ }
+
+ // draw lightning echos
+ bool drawLightning = _Instrument->getBoolValue("lightning", true);
+ if (drawLightning) {
+ const osg::Vec2f texBase(3 * UNIT, 4 * UNIT);
+
+ for (iradarEcho = radarEcho->begin(); iradarEcho != end; ++iradarEcho) {
+ if (!iradarEcho->lightning)
+ continue;
+
+ float size = UNIT * 0.5f;
+ float radius = iradarEcho->dist * _scale;
+ float angle = iradarEcho->heading * SG_DEGREES_TO_RADIANS
+ - _angle_offset;
+
+ osg::Matrixf m(osg::Matrixf::scale(size, size, 1.0f)
+ * wxRotate(-angle)
+ * osg::Matrixf::translate(0.0f, radius, 0.0f)
+ * wxRotate(angle) * _centerTrans);
+ addQuad(_vertices, _texCoords, m, texBase);
+ }
+ }
+}
+
+
+void
+wxRadarBg::update_data(FGAIBase *ac, 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);
+
+ stringstream text;
+ text << ac->_getCallsign() << endl
+ << setprecision(0) << fixed
+ << setw(3) << setfill('0') << ac->_getHeading() << "\xB0 "
+ << setw(0) << ac->_getAltitude() << "ft" << endl
+ << ac->_getSpeed() << "kts";
+
+ callsign->setText(text.str());
+ _textGeode->addDrawable(callsign);
+}
+
+
+void
+wxRadarBg::update_aircraft()
+{
+ if (!_ai_enabled_node->getBoolValue())
+ return;
+
+ bool draw_echoes = _radar_position_node->getBoolValue();
+ bool draw_symbols = _radar_symbol_node->getBoolValue();
+ bool draw_data = _radar_data_node->getBoolValue();
+ if (!draw_echoes && !draw_symbols && !draw_data)
+ 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())
+ 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, 1.5};
+
+ double user_lat = _user_lat_node->getDoubleValue();
+ double user_lon = _user_lon_node->getDoubleValue();
+ double user_alt = _user_alt_node->getDoubleValue();
+
+ float limit = _radar_coverage_node->getFloatValue();
+ if (limit > 180)
+ limit = 180;
+ else if (limit < 0)
+ limit = 0;
+ limit *= SG_DEGREES_TO_RADIANS;
+
+ radar_list_iterator it = radar_list.begin();
+ radar_list_iterator end = radar_list.end();
+ FGAIBase *selected_ac = 0;
+ double selected_radius = 0;
+ double selected_bearing = 0;
+ int selected_id = fgGetInt("/instrumentation/radar/selected-id", -1);
+
+ for (; it != end; ++it) {
+ FGAIBase *ac = (*it).get();
+ int type = ac->getType();
+ double lat = ac->_getLatitude();
+ double lon = ac->_getLongitude();
+ double alt = ac->_getAltitude();
+ double heading = ac->_getHeading();
+
+ 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))
+ continue;
+
+ bearing *= SG_DEGREES_TO_RADIANS;
+ heading *= SG_DEGREES_TO_RADIANS;
+
+ float radius = range * _scale;
+ float angle = calcRelBearing(bearing, _view_heading);
+
+ if (angle > limit || angle < -limit)
+ continue;
+
+ bearing += _angle_offset;
+ heading += _angle_offset;
+
+ // pos mode
+ if (draw_echoes) {
+ float echo_radius = echo_radii[type] * 120;
+ float size = echo_radius * 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"
+ //<< " ID=" << ac->getID()
+ //<< " type=" << type
+ // << " radius=" << radius
+ // << " angle=" << angle * SG_RADIANS_TO_DEGREES);