+ */
+ 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);
+ 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, 3 * 4);
+
+ } else
+ {
+ maskPSet->set(osg::PrimitiveSet::QUADS, 0, 0);
+ trimaskPSet->set(osg::PrimitiveSet::TRIANGLES, 0, 0);
+ }
+
+ maskPSet->dirty();
+ trimaskPSet->dirty();
+ }
+#endif
+
+ // remember index of next vertex
+ int vIndex = _vertices->size();
+
+ update_weather();
+
+ osg::DrawArrays *quadPSet
+ = static_cast<osg::DrawArrays*>(_geom->getPrimitiveSet(0));
+
+ update_aircraft();
+ update_tacan();
+ update_heading_marker();
+
+ // draw all new vertices are quads
+ quadPSet->set(osg::PrimitiveSet::QUADS, vIndex, _vertices->size()-vIndex);
+ quadPSet->dirty();
+ }
+}
+
+
+void
+wxRadarBg::update_weather()
+{
+ string modeButton = _Instrument->getStringValue("mode", "WX");
+// FIXME: implementation of radar echoes missing
+// _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());
+
+// FIXME: implementation of radar echoes missing
+#if 0
+ 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 = sqrt(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_INSTR, 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);
+ }
+ }
+#endif
+}
+
+
+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()
+{
+ double diff;
+ double age_factor = 1.0;
+ double test_rng;
+ double test_brg;
+ double range;
+ double bearing;
+ float echo_radius;
+ double angle;
+
+ if (!ground_echoes.empty()){
+ ground_echoes_iterator = ground_echoes.begin();
+
+ while(ground_echoes_iterator != ground_echoes.end()) {
+ diff = _elapsed_time - (*ground_echoes_iterator)->elapsed_time;
+
+ if( diff > _persistance) {
+ ground_echoes.erase(ground_echoes_iterator++);
+ } else {
+// double test_brg = (*ground_echoes_iterator)->bearing;
+// double bearing = test_brg * SG_DEGREES_TO_RADIANS;
+// float angle = calcRelBearing(bearing, _view_heading);
+ double bumpinessFactor = (*ground_echoes_iterator)->bumpiness;
+ float heading = fgGetDouble("/orientation/heading-deg");
+ if ( _display_mode == BSCAN ){
+ test_rng = (*ground_echoes_iterator)->elevation * 6;
+ test_brg = (*ground_echoes_iterator)->bearing;
+ angle = calcRelBearingDeg(test_brg, heading) * 6;
+ range = sqrt(test_rng * test_rng + angle * angle);
+ bearing = atan2(angle, test_rng);
+ //cout << "angle " << angle <<" bearing "
+ // << bearing / SG_DEGREES_TO_RADIANS << endl;
+ echo_radius = (0.1 + (1.9 * bumpinessFactor)) * 240 * age_factor;
+ } else {
+ test_rng = (*ground_echoes_iterator)->range;
+ range = test_rng * SG_METER_TO_NM;
+ test_brg = (*ground_echoes_iterator)->bearing;
+ bearing = test_brg * SG_DEGREES_TO_RADIANS;
+ echo_radius = (0.1 + (1.9 * bumpinessFactor)) * 120 * age_factor;
+ bearing += _angle_offset;
+ }
+
+ float radius = range * _scale;
+ //double heading = 90 * SG_DEGREES_TO_RADIANS;
+ //heading += _angle_offset;
+
+ age_factor = 1;
+
+ if (diff != 0)
+ age_factor = 1 - (0.5 * diff/_persistance);
+
+ 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);
+
+ ++ground_echoes_iterator;
+
+ //cout << "test bearing " << test_brg
+ //<< " test_rng " << test_rng * SG_METER_TO_NM
+ //<< " persistance " << _persistance
+ //<< endl;
+ }
+
+ }
+
+ }
+ if (!_ai_enabled_node->getBoolValue())
+ return;
+
+ bool draw_tcas = _radar_tcas_node->getBoolValue();
+ bool draw_absolute = _radar_absalt_node->getBoolValue();
+ 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)&&
+ (!draw_tcas)) {
+ selected_ac = model; // save selected model for last iteration
+ continue;