This piggybacks on the weather radar for a cool ATC display.
od_gauge.hxx od_gauge.cxx wxradar.hxx wxradar.cxx \
tacan.cxx tacan.hxx mk_viii.cxx mk_viii.hxx \
dclgps.cxx dclgps.hxx \
- render_area_2d.cxx render_area_2d.hxx
+ render_area_2d.cxx render_area_2d.hxx \
+ groundradar.cxx groundradar.hxx
INCLUDES = -I$(top_srcdir) -I$(top_srcdir)/src -I$(top_builddir)/src
--- /dev/null
+// groundradar.cxx - Background layer for the ATC radar.
+//
+// Written by Csaba Halasz.
+//
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of the GNU General Public License as
+// published by the Free Software Foundation; either version 2 of the
+// License, or (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful, but
+// WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <osg/Node>
+#include <osg/Geode>
+#include <osg/Geometry>
+#include <osg/Camera>
+#include <osg/Texture2D>
+#include <osgViewer/Viewer>
+
+#include <osgText/Text>
+#include <osgDB/Registry>
+#include <osgDB/ReaderWriter>
+
+#include <Main/fg_props.hxx>
+#include <Main/globals.hxx>
+#include <Main/renderer.hxx>
+#include <Cockpit/panel.hxx>
+#include <Airports/simple.hxx>
+#include <Airports/runways.hxx>
+#include <simgear/math/sg_geodesy.hxx>
+
+#include "groundradar.hxx"
+
+static const char* airport_node_name = "/sim/tower/airport-id";
+static const char* texture_name = "Aircraft/Instruments/Textures/od_groundradar.rgb";
+static const char* radar_node_name = "/instrumentation/radar/range";
+
+struct SingleFrameCallback : public osg::Camera::DrawCallback
+{
+ virtual void operator () (const osg::Camera& camera) const
+ {
+ const_cast<osg::Camera&>(camera).setNodeMask(0);
+ }
+};
+
+GroundRadar::GroundRadar(SGPropertyNode *node)
+{
+ _airport_node = fgGetNode(airport_node_name, true);
+ _radar_node = fgGetNode(radar_node_name, true);
+ createTexture();
+ updateTexture();
+ _airport_node->addChangeListener(this);
+ _radar_node->addChangeListener(this);
+}
+
+GroundRadar::~GroundRadar()
+{
+ _airport_node->removeChangeListener(this);
+ _radar_node->removeChangeListener(this);
+}
+
+void GroundRadar::valueChanged(SGPropertyNode*)
+{
+ updateTexture();
+}
+
+inline static osg::Vec3 fromPolar(double fi, double r)
+{
+ return osg::Vec3(sin(fi * SGD_DEGREES_TO_RADIANS) * r, cos(fi * SGD_DEGREES_TO_RADIANS) * r, 0);
+}
+
+void GroundRadar::createTexture()
+{
+ setSize(512);
+ allocRT();
+
+ osg::Vec4Array* colors = new osg::Vec4Array;
+ colors->push_back(osg::Vec4(0.0f,0.5f,0.0f,1.0f));
+ colors->push_back(osg::Vec4(0.0f,0.5f,0.5f,1.0f));
+
+ _geom = new osg::Geometry();
+ _geom->setColorArray(colors);
+ _geom->setColorBinding(osg::Geometry::BIND_PER_PRIMITIVE_SET);
+ _geom->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::QUADS, 0, 0));
+ _geom->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::QUADS, 0, 0));
+
+ osg::Geode* geode = new osg::Geode();
+ osg::StateSet* stateset = geode->getOrCreateStateSet();
+ stateset->setMode(GL_BLEND, osg::StateAttribute::OFF);
+ geode->addDrawable(_geom.get());
+
+ osg::Camera* camera = getCamera();
+ camera->setPostDrawCallback(new SingleFrameCallback());
+ camera->addChild(geode);
+ camera->setNodeMask(0);
+ camera->setProjectionMatrixAsOrtho2D(0, getTexture()->getTextureWidth(), 0, getTexture()->getTextureHeight());
+
+ // Texture in the 2D panel system
+ FGTextureManager::addTexture(texture_name, getTexture());
+}
+
+void GroundRadar::updateTexture()
+{
+ osg::ref_ptr<osg::Vec3Array> rwy_vertices = new osg::Vec3Array;
+ osg::ref_ptr<osg::Vec3Array> taxi_vertices = new osg::Vec3Array;
+
+ const string airport_name = _airport_node->getStringValue();
+ FGRunwayList* runways = globals->get_runways();
+
+ const FGAirport* airport = fgFindAirportID(airport_name);
+ const SGGeod& tower_location = airport->getTowerLocation();
+ const double tower_lat = tower_location.getLatitudeDeg();
+ const double tower_lon = tower_location.getLongitudeDeg();
+ double scale = SG_METER_TO_NM * 200 / _radar_node->getDoubleValue();
+
+ for(FGRunway runway = runways->search(airport_name); runway._id == airport_name; runway = runways->next())
+ {
+ double az1, az2, dist_m;
+ geo_inverse_wgs_84(tower_lat, tower_lon, runway._lat, runway._lon, &az1, &az2, &dist_m);
+
+ osg::Vec3 center = fromPolar(az1, dist_m * scale) + osg::Vec3(256, 256, 0);
+ osg::Vec3 leftcenter = fromPolar(runway._heading, runway._length * SG_FEET_TO_METER * scale / 2) + center;
+ osg::Vec3 lefttop = fromPolar(runway._heading - 90, runway._width * SG_FEET_TO_METER * scale / 2) + leftcenter;
+ osg::Vec3 leftbottom = leftcenter * 2 - lefttop;
+ osg::Vec3 rightbottom = center * 2 - lefttop;
+ osg::Vec3 righttop = center * 2 - leftbottom;
+
+ osg::Vec3Array* vertices = runway._rwy_no[0] == 'x' ? taxi_vertices.get() : rwy_vertices.get();
+ vertices->push_back(lefttop);
+ vertices->push_back(leftbottom);
+ vertices->push_back(rightbottom);
+ vertices->push_back(righttop);
+ }
+
+ osg::Vec3Array* vertices = new osg::Vec3Array(*taxi_vertices.get());
+ vertices->insert(vertices->end(), rwy_vertices->begin(), rwy_vertices->end());
+ _geom->setVertexArray(vertices);
+ osg::DrawArrays* taxi = dynamic_cast<osg::DrawArrays*>(_geom->getPrimitiveSet(0));
+ osg::DrawArrays* rwy = dynamic_cast<osg::DrawArrays*>(_geom->getPrimitiveSet(1));
+ taxi->setCount(taxi_vertices->size());
+ rwy->setFirst(taxi_vertices->size());
+ rwy->setCount(rwy_vertices->size());
+
+ getCamera()->setNodeMask(0xffffffff);
+}
+
+// end of GroundRadar.cxx
--- /dev/null
+// groundradar.hxx - Background layer for the ATC radar.
+//
+// Written by Csaba Halasz.
+//
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of the GNU General Public License as
+// published by the Free Software Foundation; either version 2 of the
+// License, or (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful, but
+// WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+
+#ifndef __INST_GROUNDRADAR_HXX
+#define __INST_GROUNDRADAR_HXX
+
+#include <osg/ref_ptr>
+#include <osg/Geometry>
+#include <simgear/props/props.hxx>
+#include "od_gauge.hxx"
+
+////////////////////////////////////////////////////////////////////////
+// Built-in layer for the atc radar.
+////////////////////////////////////////////////////////////////////////
+
+class GroundRadar : public SGPropertyChangeListener, public FGODGauge
+{
+public:
+ GroundRadar(SGPropertyNode* node);
+ virtual ~GroundRadar();
+ void updateTexture();
+ virtual void valueChanged(SGPropertyNode*);
+
+protected:
+ osg::ref_ptr<osg::Geometry> _geom;
+ SGPropertyNode_ptr _airport_node;
+ SGPropertyNode_ptr _radar_node;
+
+ void createTexture();
+};
+
+#endif // __INST_GROUNDRADAR_HXX
#include "tacan.hxx"
#include "mk_viii.hxx"
#include "mrg.hxx"
-
+#include "groundradar.hxx"
FGInstrumentMgr::FGInstrumentMgr ()
{
} else if ( name == "master-reference-gyro" ) {
set_subsystem( "instrument" + temp.str(),
new MasterReferenceGyro( node ) );
+ } else if ( name == "groundradar" ) {
+ set_subsystem( "instrument" + temp.str(),
+ new GroundRadar( node ), 1 );
} else {
SG_LOG( SG_ALL, SG_ALERT, "Unknown top level section: "
#include <osg/Matrixf>
#include <osg/PrimitiveSet>
#include <osg/StateSet>
+#include <osg/Version>
+#include <osgDB/ReaderWriter>
#include <osgDB/WriteFile>
#include <simgear/constants.h>
#include <simgear/misc/sg_path.hxx>
#include <simgear/math/sg_geodesy.hxx>
+#include <sstream>
+#include <iomanip>
+SG_USING_STD(stringstream);
+SG_USING_STD(endl);
+SG_USING_STD(setprecision);
+SG_USING_STD(fixed);
+SG_USING_STD(setw);
+SG_USING_STD(setfill);
+
#include <Main/fg_props.hxx>
#include <Main/globals.hxx>
#include <Cockpit/panel.hxx>
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")),
wxRadarBg::~wxRadarBg ()
{
+ if (_radar_font_node != 0) {
+ _radar_font_node->removeChangeListener(this);
+ }
}
// no mipmap or else alpha will mix with pixels on the border of shapes, ruining the effect
_wxEcho = SGLoadTexture2D(tpath.c_str(), false, false);
+
_Instrument->setFloatValue("trk", 0.0);
_Instrument->setFloatValue("tilt", 0.0);
_Instrument->setStringValue("status","");
FGInstrumentMgr *imgr = (FGInstrumentMgr *) globals->get_subsystem("instrumentation");
_odg = (FGODGauge *) imgr->get_subsystem("od_gauge");
- _odg->setSize(256);
+ _odg->setSize(512);
_ai = (FGAIManager*)globals->get_subsystem("ai_model");
_ai_enabled_node = fgGetNode("/sim/ai/enabled", true);
_radar_weather_node = n->getNode("WX", true);
_radar_position_node = n->getNode("pos", true);
_radar_data_node = n->getNode("data", true);
+ _radar_symbol_node = n->getNode("symbol", true);
_radar_centre_node = n->getNode("centre", true);
+ _radar_rotate_node = n->getNode("rotate", true);
+ _radar_font_node = _Instrument->getNode("font", true);
+ _radar_font_node->addChangeListener(this);
+
+ updateFont();
_radar_centre_node->setBoolValue(false);
if (_radar_coverage_node->getType() == SGPropertyNode::NONE)
// Texture in the 2D panel system
FGTextureManager::addTexture(_texture_path.c_str(), _odg->getTexture());
+ _textGeode = new osg::Geode;
+
osg::Camera* camera = _odg->getCamera();
camera->addChild(_radarGeode.get());
+ camera->addChild(_textGeode.get());
}
_centerTrans.makeTranslate(_x_offset, _y_offset, 0.0f);
} else if ( _display_mode == PLAN ) {
- // no sense I presume
+ if (_radar_rotate_node->getBoolValue()) {
+ _angle_offset = -_view_heading;
+ }
} else {
// rose
}
_vertices->clear();
_texCoords->clear();
+ _textGeode->removeDrawables(0, _textGeode->getNumDrawables());
update_weather();
}
}
+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(12);
+ callsign->setColor(selected ? osg::Vec4(1, 1, 1, 1) : osg::Vec4(0, 1, 0, 1));
+ 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(0.25);
+
+ 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()
return;
bool draw_echoes = _radar_position_node->getBoolValue();
- bool draw_symbols = _radar_data_node->getBoolValue();
- if (!draw_echoes && !draw_symbols)
+ 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();
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;
float radius = range * _scale;
float angle = calcRelBearing(bearing, _view_heading);
- float limit = _radar_coverage_node->getFloatValue();
- if (limit > 180)
- limit = 180;
- else if (limit < 0)
- limit = 0;
- limit *= SG_DEGREES_TO_RADIANS;
if (angle > limit || angle < -limit)
continue;
// << " 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);
+ }
+ }
+ }
+ if (selected_ac) {
+ update_data(selected_ac, selected_radius, selected_bearing, true);
}
}
return angle;
}
+void
+wxRadarBg::updateFont()
+{
+ SGPath tpath;
+ string path = _radar_font_node->getStringValue();
+ if (path.length() == 0) {
+ path = DEFAULT_FONT;
+ }
+ if (path[0] != '/') {
+ tpath = globals->get_fg_root();
+ tpath.append("Fonts");
+ tpath.append(path);
+ } else {
+ tpath = path;
+ }
+#if OSG_VERSION_MAJOR > 2 || (OSG_VERSION_MAJOR == 2 && OSG_VERSION_MINOR > 0)
+ osg::ref_ptr<osgDB::ReaderWriter::Options> fontOptions = new osgDB::ReaderWriter::Options("monochrome");
+ osg::ref_ptr<osgText::Font> font = osgText::readFontFile(tpath.c_str(), fontOptions.get());
+#else
+ osg::ref_ptr<osgText::Font> font = osgText::readFontFile(tpath.c_str());
+#endif
+ if (font != 0) {
+ _font = font;
+ _font->setMinFilterHint(osg::Texture::NEAREST);
+ _font->setMagFilterHint(osg::Texture::NEAREST);
+ _font->setGlyphImageMargin(0);
+ _font->setGlyphImageMarginRatio(0);
+ }
+}
+
+void
+wxRadarBg::valueChanged(SGPropertyNode*)
+{
+ updateFont();
+}
#include <osg/ref_ptr>
#include <osg/Geode>
#include <osg/Texture2D>
+#include <osgText/Text>
#include <simgear/props/props.hxx>
#include <simgear/structure/subsystem_mgr.hxx>
class FGODGauge;
-class wxRadarBg : public SGSubsystem {
+class wxRadarBg : public SGSubsystem, public SGPropertyChangeListener {
public:
wxRadarBg ( SGPropertyNode *node );
virtual void init ();
virtual void update (double dt);
+ virtual void valueChanged(SGPropertyNode*);
private:
string _name;
SGPropertyNode_ptr _radar_weather_node;
SGPropertyNode_ptr _radar_position_node;
SGPropertyNode_ptr _radar_data_node;
+ SGPropertyNode_ptr _radar_symbol_node;
SGPropertyNode_ptr _radar_mode_control_node;
SGPropertyNode_ptr _radar_centre_node;
SGPropertyNode_ptr _radar_coverage_node;
SGPropertyNode_ptr _radar_ref_rng_node;
SGPropertyNode_ptr _radar_hdg_marker_node;
+ SGPropertyNode_ptr _radar_rotate_node;
+ SGPropertyNode_ptr _radar_font_node;
SGPropertyNode_ptr _ai_enabled_node;
osg::ref_ptr<osg::Texture2D> _resultTexture;
osg::ref_ptr<osg::Texture2D> _wxEcho;
osg::ref_ptr<osg::Geode> _radarGeode;
+ osg::ref_ptr<osg::Geode> _textGeode;
osg::Geometry *_geom;
osg::Vec2Array *_vertices;
osg::Vec2Array *_texCoords;
osg::Matrixf _centerTrans;
+ osg::ref_ptr<osgText::Font> _font;
list_of_SGWxRadarEcho _radarEchoBuffer;
void update_aircraft();
void update_tacan();
void update_heading_marker();
+ void update_data(FGAIBase* ac, double radius, double bearing, bool selected);
void center_map();
void apply_map_offset();
float calcRelBearing(float bearing, float heading);
void calcRangeBearing(double lat, double lon, double lat2, double lon2,
double &range, double &bearing) const;
+ void updateFont();
};
#endif // _INST_WXRADAR_HXX