- if ( display_mode != "plan" ) {
- glDisable(GL_BLEND);
- glColor4f(1.0f, 0.0f, 0.0f, 0.01f);
- glBegin( GL_QUADS );
- glTexCoord2f( 0.5f, 0.25f);
- glVertex2f(-xOffset, 0.0 + yOffset);
- glTexCoord2f( 1.0f, 0.25f);
- glVertex2f(xOffset, 0.0 + yOffset);
- glTexCoord2f( 1.0f, 0.5f);
- glVertex2f(xOffset, 256.0 + yOffset);
- glTexCoord2f( 0.5f, 0.5f);
- glVertex2f(-xOffset, 256.0 + yOffset);
- glEnd();
-
- glColor4f(0.0f, 0.0f, 0.0f, 0.0f);
-// glColor4f(0.0f, 1.0f, 0.0f, 1.0f);
- glDisable(GL_ALPHA_TEST);
- glBindTexture(GL_TEXTURE_2D, 0);
-
- glBegin( GL_TRIANGLES );
- glVertex2f(0.0, 0.0);
- glVertex2f(-256.0, 0.0);
- glVertex2f(-256.0, 256.0 * tan(30*SG_DEGREES_TO_RADIANS));
-
- glVertex2f(0.0, 0.0);
- glVertex2f(256.0, 0.0);
- glVertex2f(256.0, 256.0 * tan(30*SG_DEGREES_TO_RADIANS));
-
- glVertex2f(-256, 0.0);
- glVertex2f(256.0, 0.0);
- glVertex2f(-256.0, -256.0);
-
- glVertex2f(256, 0.0);
- glVertex2f(256.0, -256.0);
- glVertex2f(-256.0, -256.0);
- glEnd();
+ 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(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()
+{
+ 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;
+
+ 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;
+
+ 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;
+ }