+ }
+ }
+
+ // 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);
+ }
+
+ // data mode
+ if (draw_symbols) {
+ const osg::Vec2f texBase(0, 3 * UNIT);
+ float size = 600 * UNIT;
+ osg::Matrixf m(osg::Matrixf::scale(size, size, 1.0f)
+ * wxRotate(heading - bearing)
+ * 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) {
+ if (ac->getID() == selected_id) {
+ selected_ac = ac;
+ selected_radius = radius;
+ selected_bearing = bearing;
+ } else {
+ update_data(ac, radius, bearing, false);