X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FInstrumentation%2Fwxradar.cxx;h=b1f81be656ebf2e293ba902f662e6331943a4990;hb=caf0138ab35b03bbe7bf367ff2222d0a31be3157;hp=968db833a4f32ee59ccf396a004075c3118a354a;hpb=16dd71a04457663b1ac7192bb122b2d4af673927;p=flightgear.git diff --git a/src/Instrumentation/wxradar.cxx b/src/Instrumentation/wxradar.cxx index 968db833a..b1f81be65 100644 --- a/src/Instrumentation/wxradar.cxx +++ b/src/Instrumentation/wxradar.cxx @@ -38,7 +38,6 @@ #include #include -#include #include #include #include @@ -46,39 +45,53 @@ #include #include + using std::stringstream; using std::endl; using std::setprecision; using std::fixed; using std::setw; using std::setfill; +using std::string; #include
#include
#include -#include -#include #include "instrument_mgr.hxx" #include "od_gauge.hxx" #include "wxradar.hxx" +#include // for cout, endl +using std::cout; +using std::endl; static const float UNIT = 1.0f / 8.0f; // 8 symbols in a row/column in the texture static const char *DEFAULT_FONT = "typewriter.txf"; - wxRadarBg::wxRadarBg(SGPropertyNode *node) : _name(node->getStringValue("name", "radar")), _num(node->getIntValue("number", 0)), - _interval(node->getDoubleValue("update-interval-sec", 1.0)), _time(0.0), - _sim_init_done(false), + _interval(node->getDoubleValue("update-interval-sec", 1.0)), + _elapsed_time(0), + _persistance(0), _odg(0), - _last_switchKnob("off"), + _range_nm(0), + _scale(0), + _angle_offset(0), + _view_heading(0), + _x_offset(0), + _y_offset(0), + _radar_ref_rng(0), + _lat(0), + _lon(0), + _antenna_ht(node->getDoubleValue("antenna-ht-ft", 0.0)), _resultTexture(0), - _wxEcho(0) + _wxEcho(0), + _font_size(0), + _font_spacing(0) { string branch; branch = "/instrumentation/" + _name; @@ -106,6 +119,7 @@ wxRadarBg::wxRadarBg(SGPropertyNode *node) : wxRadarBg::~wxRadarBg () { _font_node->removeChangeListener(this); + delete _odg; } @@ -113,19 +127,19 @@ void wxRadarBg::init () { _serviceable_node = _Instrument->getNode("serviceable", true); + _sceneryLoaded = fgGetNode("/sim/sceneryloaded", true); // texture name to use in 2D and 3D instruments _texture_path = _Instrument->getStringValue("radar-texture-path", - "Aircraft/Instruments/Textures/od_wxradar.rgb"); + "Aircraft/Instruments/Textures/od_wxradar.rgb"); _resultTexture = FGTextureManager::createTexture(_texture_path.c_str(), false); - SGPath tpath(globals->get_fg_root()); string path = _Instrument->getStringValue("echo-texture-path", - "Aircraft/Instruments/Textures/wxecho.rgb"); - tpath.append(path); + "Aircraft/Instruments/Textures/wxecho.rgb"); + SGPath tpath = globals->resolve_aircraft_path(path); // no mipmap or else alpha will mix with pixels on the border of shapes, ruining the effect - _wxEcho = SGLoadTexture2D(tpath, false, false); + _wxEcho = SGLoadTexture2D(tpath, NULL, false, false); _Instrument->setFloatValue("trk", 0.0); @@ -142,8 +156,7 @@ wxRadarBg::init () // input range = n nm (20/40/80) // input display-mode = arc | rose | map | plan - FGInstrumentMgr *imgr = (FGInstrumentMgr *)globals->get_subsystem("instrumentation"); - _odg = (FGODGauge *)imgr->get_subsystem("od_gauge"); + _odg = new FGODGauge; _odg->setSize(512); _ai_enabled_node = fgGetNode("/sim/ai/enabled", true); @@ -173,6 +186,8 @@ wxRadarBg::init () _radar_symbol_node = n->getNode("symbol", true); _radar_centre_node = n->getNode("centre", true); _radar_rotate_node = n->getNode("rotate", true); + _radar_tcas_node = n->getNode("tcas", true); + _radar_absalt_node = n->getNode("abs-altitude", true); _radar_centre_node->setBoolValue(false); if (!_radar_coverage_node->hasValue()) @@ -219,7 +234,7 @@ wxRadarBg::init () pset->setDataVariance(osg::Object::DYNAMIC); _geom->addPrimitiveSet(pset); _geom->setInitialBound(osg::BoundingBox(osg::Vec3f(-256.0f, -256.0f, 0.0f), - osg::Vec3f(256.0f, 256.0f, 0.0f))); + osg::Vec3f(256.0f, 256.0f, 0.0f))); _radarGeode->addDrawable(_geom); _odg->allocRT(); // Texture in the 2D panel system @@ -230,6 +245,8 @@ wxRadarBg::init () osg::Camera *camera = _odg->getCamera(); camera->addChild(_radarGeode.get()); camera->addChild(_textGeode.get()); + + updateFont(); } @@ -270,16 +287,14 @@ osg::Matrixf wxRotate(float angle) void wxRadarBg::update (double delta_time_sec) { - if (!_sim_init_done) { - if (!fgGetBool("sim/sceneryloaded", false)) - return; + if (!_sceneryLoaded->getBoolValue()) + return; - _sim_init_done = true; - } if (!_odg || !_serviceable_node->getBoolValue()) { _Instrument->setStringValue("status", ""); return; } + _time += delta_time_sec; if (_time < _interval) return; @@ -293,22 +308,14 @@ wxRadarBg::update (double delta_time_sec) center_map(); } } else if (mode == "plan") { - _display_mode = PLAN; + _display_mode = PLAN;} + else if (mode == "bscan") { + _display_mode = BSCAN; } else { _display_mode = ARC; } string switchKnob = _Instrument->getStringValue("switch", "on"); - if (_last_switchKnob != switchKnob) { - // since 3D models don't share textures with the rest of the world - // 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(_texture_path.c_str(), _resultTexture->getHandle()); - - _last_switchKnob = switchKnob; - } - if (switchKnob == "off") { _Instrument->setStringValue("status", ""); } else if (switchKnob == "stby") { @@ -324,7 +331,7 @@ wxRadarBg::update (double delta_time_sec) } _radar_ref_rng = _radar_ref_rng_node->getDoubleValue(); - _view_heading = get_heading() * SG_DEGREES_TO_RADIANS; + _view_heading = fgGetDouble("/orientation/heading-deg") * SG_DEGREES_TO_RADIANS; _centerTrans.makeTranslate(0.0f, 0.0f, 0.0f); _scale = 200.0 / _range_nm; @@ -344,7 +351,7 @@ wxRadarBg::update (double delta_time_sec) _radar_centre_node->setBoolValue(false); } - //SG_LOG(SG_GENERAL, SG_DEBUG, "Radar: displacement " + //SG_LOG(SG_INSTR, SG_DEBUG, "Radar: displacement " // << _x_offset <<", "<<_y_offset // << " user_speed_east_fps * SG_FPS_TO_KT " // << user_speed_east_fps * SG_FPS_TO_KT @@ -358,6 +365,8 @@ wxRadarBg::update (double delta_time_sec) if (_radar_rotate_node->getBoolValue()) { _angle_offset = -_view_heading; } + } else if (_display_mode == BSCAN) { + _angle_offset = -_view_heading; } else { // rose } @@ -366,90 +375,99 @@ wxRadarBg::update (double delta_time_sec) _texCoords->clear(); _textGeode->removeDrawables(0, _textGeode->getNumDrawables()); - - update_weather(); - - - osg::DrawArrays *quadPSet - = static_cast(_geom->getPrimitiveSet(0)); - quadPSet->set(osg::PrimitiveSet::QUADS, 0, _vertices->size()); - quadPSet->dirty(); - - // erase what is out of sight of antenna - /* - |\ /| - | \ / | - | \ / | - --------- - | | - | | - --------- - */ - - osg::DrawArrays *maskPSet +#if 0 + //TODO FIXME Mask below (only used for ARC mode) isn't properly aligned, i.e. + // it assumes the a/c position at the center of the display - though it's somewhere at + // bottom part for ARC mode. + // The mask hadn't worked at all for a while (probably since the OSG port) due to + // another bug (which is fixed now). Now, the mask is disabled completely until s.o. + // adapted the coordinates below. And the mask is only really useful to limit displayed + // weather blobs (not support yet). + // Aircraft echos are already limited properly through wxradar's "limit-deg" property. + { + osg::DrawArrays *maskPSet = static_cast(_geom->getPrimitiveSet(1)); - osg::DrawArrays *trimaskPSet + osg::DrawArrays *trimaskPSet = static_cast(_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); + if (_display_mode == ARC) { + // erase what is out of sight of antenna + /* + |\ /| + | \ / | + | \ / | + --------- + | | + | | + --------- + */ + 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); + } - } else { - maskPSet->set(osg::PrimitiveSet::QUADS, 0, 0); - trimaskPSet->set(osg::PrimitiveSet::TRIANGLES, 0, 0); + maskPSet->dirty(); + trimaskPSet->dirty(); } +#endif - maskPSet->dirty(); - trimaskPSet->dirty(); + // remember index of next vertex + int vIndex = _vertices->size(); - // draw without mask - _vertices->clear(); - _texCoords->clear(); + update_weather(); + + osg::DrawArrays *quadPSet + = static_cast(_geom->getPrimitiveSet(0)); update_aircraft(); update_tacan(); update_heading_marker(); - quadPSet->set(osg::PrimitiveSet::QUADS, 0, _vertices->size()); + // draw all new vertices are quads + quadPSet->set(osg::PrimitiveSet::QUADS, vIndex, _vertices->size()-vIndex); quadPSet->dirty(); } } @@ -458,14 +476,17 @@ wxRadarBg::update (double delta_time_sec) void wxRadarBg::update_weather() { - string modeButton = _Instrument->getStringValue("mode", "wx"); - _radarEchoBuffer = *sgEnviro.get_radar_echo(); + 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; +// 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 }; @@ -491,14 +512,14 @@ wxRadarBg::update_weather() if (iradarEcho->lightning || lwc < LWClevel[level]) continue; - float radius = sgSqrt(iradarEcho->dist) * SG_METER_TO_NM * _scale; + 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; + + 0.5 * SG_PI; // Rotate echo into position, and rotate echo to have // a constant orientation towards the @@ -508,11 +529,11 @@ wxRadarBg::update_weather() 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); + * 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" + //SG_LOG(SG_INSTR, SG_DEBUG, "Radar: drawing clouds" // << " ID=" << cloudId // << " x=" << x // << " y="<< y @@ -536,21 +557,22 @@ wxRadarBg::update_weather() float size = UNIT * 0.5f; float radius = iradarEcho->dist * _scale; float angle = iradarEcho->heading * SG_DEGREES_TO_RADIANS - - _angle_offset; + - _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); + * 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) + double radius, double bearing, bool selected) { osgText::Text *callsign = new osgText::Text; callsign->setFont(_font.get()); @@ -558,8 +580,8 @@ wxRadarBg::update_data(const SGPropertyNode *ac, double altitude, double heading 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::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 @@ -573,10 +595,10 @@ wxRadarBg::update_data(const SGPropertyNode *ac, double altitude, double heading 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"; + << 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); @@ -586,12 +608,83 @@ wxRadarBg::update_data(const SGPropertyNode *ac, double altitude, double heading 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_echoes = _radar_position_node->getBoolValue(); - bool draw_symbols = _radar_symbol_node->getBoolValue(); - bool draw_data = _radar_data_node->getBoolValue(); + 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; @@ -620,7 +713,8 @@ wxRadarBg::update_aircraft() model = ai->getChild(i); if (!model->nChildren()) continue; - if (model->getIntValue("id") == selected_id) { + if ((model->getIntValue("id") == selected_id)&& + (!draw_tcas)) { selected_ac = model; // save selected model for last iteration continue; } @@ -630,11 +724,13 @@ wxRadarBg::update_aircraft() double echo_radius, sigma; const string name = model->getName(); + + //cout << "name "<getDoubleValue("position/latitude-deg"); double lon = model->getDoubleValue("position/longitude-deg"); @@ -652,7 +748,7 @@ wxRadarBg::update_aircraft() double range, bearing; calcRangeBearing(user_lat, user_lon, lat, lon, range, bearing); - + //cout << _antenna_ht << _interval<< endl; bool isVisible = withinRadarHorizon(user_alt, alt, range); if (!isVisible) @@ -673,33 +769,126 @@ wxRadarBg::update_aircraft() bearing += _angle_offset; heading += _angle_offset; + bool is_tcas_contact = false; + if (draw_tcas) + { + is_tcas_contact = update_tcas(model,range,user_alt,alt,bearing,radius,draw_absolute); + } + // pos mode - if (draw_echoes) { + if (draw_echoes && (!is_tcas_contact)) { float size = echo_radius * 120 * 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); + * osg::Matrixf::translate(0.0f, radius, 0.0f) + * wxRotate(bearing) * _centerTrans); addQuad(_vertices, _texCoords, m, texBase); } // data mode - if (draw_symbols) { + if (draw_symbols && (!draw_tcas)) { 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); + * wxRotate(heading - bearing) + * osg::Matrixf::translate(0.0f, radius, 0.0f) + * wxRotate(bearing) * _centerTrans); addQuad(_vertices, _texCoords, m, texBase); } - if (draw_data || i < 0) // selected one (i == -1) is always drawn + if ((draw_data || i < 0)&& // selected one (i == -1) is always drawn + ((!draw_tcas)||(is_tcas_contact)||(draw_echoes))) update_data(model, alt, heading, radius, bearing, i < 0); } } +/** Update TCAS display. + * Return true when processed as TCAS contact, false otherwise. */ +bool +wxRadarBg::update_tcas(const SGPropertyNode *model,double range,double user_alt,double alt, + double bearing,double radius,bool absMode) +{ + int threatLevel=0; + { + // update TCAS symbol + osg::Vec2f texBase; + threatLevel = model->getIntValue("tcas/threat-level",-1); + if (threatLevel == -1) + { + // no TCAS information (i.e. no transponder) => not visible to TCAS + return false; + } + int row = 7 - threatLevel; + int col = 4; + double vspeed = model->getDoubleValue("velocities/vertical-speed-fps"); + if (vspeed < -3.0) // descending + col+=1; + else + if (vspeed > 3.0) // climbing + col+=2; + texBase = osg::Vec2f(col*UNIT,row * UNIT); + float size = 200 * UNIT; + osg::Matrixf m(osg::Matrixf::scale(size, size, 1.0f) + * wxRotate(-bearing) + * osg::Matrixf::translate(0.0f, radius, 0.0f) + * wxRotate(bearing) * _centerTrans); + addQuad(_vertices, _texCoords, m, texBase); + } + + { + // update TCAS data + osgText::Text *altStr = new osgText::Text; + altStr->setFont(_font.get()); + altStr->setFontResolution(12, 12); + altStr->setCharacterSize(_font_size); + altStr->setColor(_tcas_colors[threatLevel]); + 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 + altStr->setLineSpacing(_font_spacing); + + stringstream text; + altStr->setAlignment(osgText::Text::LEFT_CENTER); + int altDif = (alt-user_alt+50)/100; + char sign = 0; + int dy=0; + if (altDif>=0) + { + sign='+'; + dy=2; + } + else + if (altDif<0) + { + sign='-'; + altDif = -altDif; + dy=-30; + } + altStr->setPosition(osg::Vec3((int)pos.x()-30, (int)pos.y()+dy, 0)); + if (absMode) + { + // absolute altitude display + text << setprecision(0) << fixed + << setw(3) << setfill('0') << alt/100 << endl; + } + else // relative altitude display + if (sign) + { + text << sign + << setprecision(0) << fixed + << setw(2) << setfill('0') << altDif << endl; + } + + altStr->setText(text.str()); + _textGeode->addDrawable(altStr); + } + + return true; +} void wxRadarBg::update_tacan() @@ -714,16 +903,16 @@ wxRadarBg::update_tacan() float size = 600 * UNIT; float radius = _tacan_distance_node->getFloatValue() * _scale; float angle = _tacan_bearing_node->getFloatValue() * SG_DEGREES_TO_RADIANS - + _angle_offset; + + _angle_offset; const osg::Vec2f texBase(1 * UNIT, 3 * UNIT); osg::Matrixf m(osg::Matrixf::scale(size, size, 1.0f) - * wxRotate(-angle) - * osg::Matrixf::translate(0.0f, radius, 0.0f) - * wxRotate(angle) * _centerTrans); + * wxRotate(-angle) + * osg::Matrixf::translate(0.0f, radius, 0.0f) + * wxRotate(angle) * _centerTrans); addQuad(_vertices, _texCoords, m, texBase); - //SG_LOG(SG_GENERAL, SG_DEBUG, "Radar: drawing TACAN" + //SG_LOG(SG_INSTR, SG_DEBUG, "Radar: drawing TACAN" // << " dist=" << radius // << " view_heading=" << _view_heading * SG_RADIANS_TO_DEGREES // << " bearing=" << angle * SG_RADIANS_TO_DEGREES @@ -741,12 +930,12 @@ wxRadarBg::update_heading_marker() const osg::Vec2f texBase(2 * UNIT, 3 * UNIT); float size = 600 * UNIT; osg::Matrixf m(osg::Matrixf::scale(size, size, 1.0f) - * wxRotate(_view_heading + _angle_offset)); + * wxRotate(_view_heading + _angle_offset)); m *= _centerTrans; addQuad(_vertices, _texCoords, m, texBase); - //SG_LOG(SG_GENERAL, SG_DEBUG, "Radar: drawing heading marker" + //SG_LOG(SG_INSTR, SG_DEBUG, "Radar: drawing heading marker" // << " x,y " << x <<","<< y // << " dist" << dist // << " view_heading" << _view_heading * SG_RADIANS_TO_DEGREES @@ -785,15 +974,17 @@ wxRadarBg::withinRadarHorizon(double user_alt, double alt, double range_nm) { // Radar Horizon = 1.23(ht^1/2 + hr^1/2), //don't allow negative altitudes (an approximation - yes altitudes can be negative) + // Allow antenna ht to be set, but only on ground + _antenna_ht = _Instrument->getDoubleValue("antenna-ht-ft"); - if (user_alt < 0) - user_alt = 0; + if (user_alt <= 0) + user_alt = _antenna_ht; - if (alt < 0) - alt = 0; + if (alt <= 0) + alt = 0; // to allow some vertical extent of target double radarhorizon = 1.23 * (sqrt(alt) + sqrt(user_alt)); - //SG_LOG(SG_GENERAL, SG_DEBUG, "Radar: horizon " << radarhorizon); +// SG_LOG(SG_INSTR, SG_ALERT, "Radar: radar horizon " << radarhorizon); return radarhorizon >= range_nm; } @@ -821,14 +1012,14 @@ wxRadarBg::inRadarRange(double sigma, double range_nm) constant = 35; double maxrange = constant * pow(sigma, 0.25); - //SG_LOG(SG_GENERAL, SG_DEBUG, "Radar: max range " << maxrange); + //SG_LOG(SG_INSTR, SG_DEBUG, "Radar: max range " << maxrange); return maxrange >= range_nm; } void wxRadarBg::calcRangeBearing(double lat, double lon, double lat2, double lon2, - double &range, double &bearing) const + double &range, double &bearing) const { // calculate the bearing and range of the second pos from the first double az2, distance; @@ -851,6 +1042,20 @@ wxRadarBg::calcRelBearing(float bearing, float heading) return angle; } +float +wxRadarBg::calcRelBearingDeg(float bearing, float heading) +{ + float angle = bearing - heading; + + if (angle >= 180) + return angle -= 360; + + if (angle < -180) + return angle += 360; + + return angle; +} + void wxRadarBg::updateFont() @@ -888,11 +1093,23 @@ wxRadarBg::updateFont() _font->setGlyphImageMargin(0); _font->setGlyphImageMarginRatio(0); } + + for (int i=0;i<4;i++) + { + const float defaultColors[4][3] = {{0,1,1},{0,1,1},{1,0.5,0},{1,0,0}}; + SGPropertyNode_ptr color_node = _font_node->getNode("tcas/color",i,true); + float red = color_node->getFloatValue("red",defaultColors[i][0]); + float green = color_node->getFloatValue("green",defaultColors[i][1]); + float blue = color_node->getFloatValue("blue",defaultColors[i][2]); + float alpha = color_node->getFloatValue("alpha",1); + _tcas_colors[i]=osg::Vec4(red, green, blue, alpha); + } } void wxRadarBg::valueChanged(SGPropertyNode*) { updateFont(); + _time = _interval; }