2005-10-08 11:55:18 +00:00
|
|
|
// Wx Radar background texture
|
|
|
|
//
|
|
|
|
// Written by Harald JOHNSEN, started May 2005.
|
2007-06-24 07:57:45 +00:00
|
|
|
// With major amendments by Vivian MEAZZA May 2007
|
|
|
|
// Ported to OSG by Tim Moore Jun 2007
|
|
|
|
//
|
2005-10-08 11:55:18 +00:00
|
|
|
//
|
2005-10-16 17:31:06 +00:00
|
|
|
// Copyright (C) 2005 Harald JOHNSEN
|
2005-10-08 11:55:18 +00:00
|
|
|
//
|
|
|
|
// 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
|
2006-02-21 01:16:04 +00:00
|
|
|
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2005-10-08 11:55:18 +00:00
|
|
|
//
|
|
|
|
//
|
|
|
|
|
2006-02-18 13:58:09 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2007-06-24 07:57:45 +00:00
|
|
|
#include <osg/Array>
|
|
|
|
#include <osg/Geometry>
|
|
|
|
#include <osg/Matrixf>
|
|
|
|
#include <osg/PrimitiveSet>
|
|
|
|
#include <osg/StateSet>
|
2007-09-09 23:22:14 +00:00
|
|
|
#include <osg/Version>
|
|
|
|
#include <osgDB/ReaderWriter>
|
2007-06-24 07:57:45 +00:00
|
|
|
#include <osgDB/WriteFile>
|
|
|
|
|
|
|
|
#include <simgear/constants.h>
|
|
|
|
#include <simgear/misc/sg_path.hxx>
|
|
|
|
#include <simgear/environment/visual_enviro.hxx>
|
|
|
|
#include <simgear/scene/model/model.hxx>
|
|
|
|
#include <simgear/structure/exception.hxx>
|
|
|
|
#include <simgear/misc/sg_path.hxx>
|
|
|
|
#include <simgear/math/sg_geodesy.hxx>
|
|
|
|
|
2007-09-09 23:22:14 +00:00
|
|
|
#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);
|
|
|
|
|
2005-10-08 11:55:18 +00:00
|
|
|
#include <Main/fg_props.hxx>
|
|
|
|
#include <Main/globals.hxx>
|
|
|
|
#include <Cockpit/panel.hxx>
|
|
|
|
#include <Cockpit/hud.hxx>
|
2007-06-24 07:57:45 +00:00
|
|
|
#include <AIModel/AIBase.hxx>
|
|
|
|
#include <AIModel/AIManager.hxx>
|
|
|
|
#include <AIModel/AIBallistic.hxx>
|
2005-10-08 11:55:18 +00:00
|
|
|
|
2007-10-04 20:40:29 +00:00
|
|
|
#include <Include/general.hxx>
|
2005-10-08 11:55:18 +00:00
|
|
|
#include "instrument_mgr.hxx"
|
|
|
|
#include "od_gauge.hxx"
|
|
|
|
#include "wxradar.hxx"
|
|
|
|
|
2007-06-24 07:57:45 +00:00
|
|
|
|
2008-03-22 09:31:06 +00:00
|
|
|
typedef list <osg::ref_ptr<FGAIBase> > radar_list_type;
|
2007-06-29 22:44:41 +00:00
|
|
|
typedef radar_list_type::iterator radar_list_iterator;
|
|
|
|
typedef radar_list_type::const_iterator radar_list_const_iterator;
|
|
|
|
|
|
|
|
|
|
|
|
static const float UNIT = 1.0f / 8.0f; // 8 symbols in a row/column in the texture
|
2007-09-09 23:22:14 +00:00
|
|
|
static const char *DEFAULT_FONT = "typewriter.txf";
|
2005-10-08 11:55:18 +00:00
|
|
|
|
2008-06-01 18:08:01 +00:00
|
|
|
wxRadarBg::wxRadarBg(SGPropertyNode *node) :
|
2007-06-24 17:15:48 +00:00
|
|
|
_name(node->getStringValue("name", "radar")),
|
2006-12-06 22:11:43 +00:00
|
|
|
_num(node->getIntValue("number", 0)),
|
2007-06-24 22:13:25 +00:00
|
|
|
_interval(node->getDoubleValue("update-interval-sec", 1.0)),
|
2008-06-01 18:08:01 +00:00
|
|
|
_time(0.0),
|
|
|
|
_last_switchKnob("off"),
|
|
|
|
_sim_init_done(false),
|
|
|
|
_resultTexture(0),
|
|
|
|
_wxEcho(0),
|
|
|
|
_odg(0)
|
2005-10-08 11:55:18 +00:00
|
|
|
{
|
2008-06-01 18:08:01 +00:00
|
|
|
string branch;
|
|
|
|
branch = "/instrumentation/" + _name;
|
|
|
|
_Instrument = fgGetNode(branch.c_str(), _num, true );
|
|
|
|
|
|
|
|
const char *tacan_source = node->getStringValue("tacan-source", "/instrumentation/tacan");
|
2007-06-24 17:15:48 +00:00
|
|
|
_Tacan = fgGetNode(tacan_source, true);
|
2008-06-01 18:08:01 +00:00
|
|
|
|
|
|
|
_font_node = _Instrument->getNode("font", true);
|
|
|
|
_font_node->addChangeListener(this, true);
|
2005-10-08 11:55:18 +00:00
|
|
|
}
|
|
|
|
|
2007-06-29 22:44:41 +00:00
|
|
|
|
2005-10-08 11:55:18 +00:00
|
|
|
wxRadarBg::~wxRadarBg ()
|
|
|
|
{
|
2008-06-01 18:08:01 +00:00
|
|
|
_font_node->removeChangeListener(this);
|
2005-10-08 11:55:18 +00:00
|
|
|
}
|
|
|
|
|
2007-06-29 22:44:41 +00:00
|
|
|
|
2005-10-08 11:55:18 +00:00
|
|
|
void
|
|
|
|
wxRadarBg::init ()
|
|
|
|
{
|
2007-06-24 17:15:48 +00:00
|
|
|
_serviceable_node = _Instrument->getNode("serviceable", true);
|
2007-07-03 18:24:45 +00:00
|
|
|
|
|
|
|
// texture name to use in 2D and 3D instruments
|
|
|
|
_texture_path = _Instrument->getStringValue("radar-texture-path",
|
|
|
|
"Aircraft/Instruments/Textures/od_wxradar.rgb");
|
2008-06-01 18:08:01 +00:00
|
|
|
_resultTexture = FGTextureManager::createTexture(_texture_path.c_str(), false);
|
2007-06-24 07:57:45 +00:00
|
|
|
|
2005-10-08 11:55:18 +00:00
|
|
|
SGPath tpath(globals->get_fg_root());
|
2007-06-29 22:44:41 +00:00
|
|
|
string path = _Instrument->getStringValue("echo-texture-path",
|
|
|
|
"Aircraft/Instruments/Textures/wxecho.rgb");
|
|
|
|
tpath.append(path);
|
|
|
|
|
2005-10-08 11:55:18 +00:00
|
|
|
// no mipmap or else alpha will mix with pixels on the border of shapes, ruining the effect
|
2007-12-07 09:14:16 +00:00
|
|
|
_wxEcho = SGLoadTexture2D(tpath, false, false);
|
2005-10-08 11:55:18 +00:00
|
|
|
|
2007-09-09 23:22:14 +00:00
|
|
|
|
2005-10-08 11:55:18 +00:00
|
|
|
_Instrument->setFloatValue("trk", 0.0);
|
|
|
|
_Instrument->setFloatValue("tilt", 0.0);
|
|
|
|
_Instrument->setStringValue("status","");
|
|
|
|
// those properties are used by a radar instrument of a MFD
|
|
|
|
// input switch = OFF | TST | STBY | ON
|
|
|
|
// input mode = WX | WXA | MAP
|
2007-06-24 07:57:45 +00:00
|
|
|
// output status = STBY | TEST | WX | WXA | MAP | blank
|
2005-10-08 11:55:18 +00:00
|
|
|
// input lightning = true | false
|
|
|
|
// input TRK = +/- n degrees
|
|
|
|
// input TILT = +/- n degree
|
|
|
|
// input autotilt = true | false
|
|
|
|
// input range = n nm (20/40/80)
|
|
|
|
// input display-mode = arc | rose | map | plan
|
|
|
|
|
2008-06-01 18:08:01 +00:00
|
|
|
FGInstrumentMgr *imgr = (FGInstrumentMgr *)globals->get_subsystem("instrumentation");
|
|
|
|
_odg = (FGODGauge *)imgr->get_subsystem("od_gauge");
|
2007-09-09 23:22:14 +00:00
|
|
|
_odg->setSize(512);
|
2007-06-24 07:57:45 +00:00
|
|
|
|
|
|
|
_ai = (FGAIManager*)globals->get_subsystem("ai_model");
|
2007-06-29 22:44:41 +00:00
|
|
|
_ai_enabled_node = fgGetNode("/sim/ai/enabled", true);
|
2007-06-24 07:57:45 +00:00
|
|
|
|
|
|
|
_user_lat_node = fgGetNode("/position/latitude-deg", true);
|
|
|
|
_user_lon_node = fgGetNode("/position/longitude-deg", true);
|
|
|
|
_user_alt_node = fgGetNode("/position/altitude-ft", true);
|
|
|
|
|
|
|
|
_user_speed_east_fps_node = fgGetNode("/velocities/speed-east-fps", true);
|
|
|
|
_user_speed_north_fps_node = fgGetNode("/velocities/speed-north-fps", true);
|
|
|
|
|
|
|
|
_tacan_serviceable_node = _Tacan->getNode("serviceable", true);
|
|
|
|
_tacan_distance_node = _Tacan->getNode("indicated-distance-nm", true);
|
|
|
|
_tacan_name_node = _Tacan->getNode("name", true);
|
|
|
|
_tacan_bearing_node = _Tacan->getNode("indicated-bearing-true-deg", true);
|
|
|
|
_tacan_in_range_node = _Tacan->getNode("in-range", true);
|
|
|
|
|
2007-06-24 17:15:48 +00:00
|
|
|
_radar_mode_control_node = _Instrument->getNode("mode-control", true);
|
2007-06-29 22:44:41 +00:00
|
|
|
_radar_coverage_node = _Instrument->getNode("limit-deg", true);
|
|
|
|
_radar_ref_rng_node = _Instrument->getNode("reference-range-nm", true);
|
2007-06-30 08:53:06 +00:00
|
|
|
_radar_hdg_marker_node = _Instrument->getNode("heading-marker", true);
|
2007-06-24 07:57:45 +00:00
|
|
|
|
2007-06-24 17:15:48 +00:00
|
|
|
SGPropertyNode *n = _Instrument->getNode("display-controls", true);
|
|
|
|
_radar_weather_node = n->getNode("WX", true);
|
|
|
|
_radar_position_node = n->getNode("pos", true);
|
|
|
|
_radar_data_node = n->getNode("data", true);
|
2007-09-09 23:22:14 +00:00
|
|
|
_radar_symbol_node = n->getNode("symbol", true);
|
2007-06-24 17:15:48 +00:00
|
|
|
_radar_centre_node = n->getNode("centre", true);
|
2007-09-09 23:22:14 +00:00
|
|
|
_radar_rotate_node = n->getNode("rotate", true);
|
2007-06-24 17:15:48 +00:00
|
|
|
|
|
|
|
_radar_centre_node->setBoolValue(false);
|
2007-06-29 22:44:41 +00:00
|
|
|
if (_radar_coverage_node->getType() == SGPropertyNode::NONE)
|
|
|
|
_radar_coverage_node->setFloatValue(120);
|
|
|
|
if (_radar_ref_rng_node->getType() == SGPropertyNode::NONE)
|
|
|
|
_radar_ref_rng_node->setDoubleValue(35);
|
2007-06-30 08:53:06 +00:00
|
|
|
if (_radar_hdg_marker_node->getType() == SGPropertyNode::NONE)
|
|
|
|
_radar_hdg_marker_node->setBoolValue(true);
|
2007-06-24 17:15:48 +00:00
|
|
|
|
2007-06-29 22:44:41 +00:00
|
|
|
_x_offset = 0;
|
|
|
|
_y_offset = 0;
|
2007-06-24 07:57:45 +00:00
|
|
|
|
|
|
|
// OSG geometry setup. The polygons for the radar returns will be
|
|
|
|
// stored in a single Geometry. The geometry will have several
|
|
|
|
// primitive sets so we can have different kinds of polys and
|
|
|
|
// choose a different overall color for each set.
|
2007-06-29 22:44:41 +00:00
|
|
|
_radarGeode = new osg::Geode;
|
|
|
|
osg::StateSet* stateSet = _radarGeode->getOrCreateStateSet();
|
|
|
|
stateSet->setTextureAttributeAndModes(0, _wxEcho.get());
|
2007-07-01 14:26:06 +00:00
|
|
|
_geom = new osg::Geometry;
|
|
|
|
_geom->setUseDisplayList(false);
|
2007-06-24 07:57:45 +00:00
|
|
|
// Initially allocate space for 128 quads
|
2007-07-01 14:26:06 +00:00
|
|
|
_vertices = new osg::Vec2Array;
|
|
|
|
_vertices->setDataVariance(osg::Object::DYNAMIC);
|
|
|
|
_vertices->reserve(128 * 4);
|
|
|
|
_geom->setVertexArray(_vertices);
|
|
|
|
_texCoords = new osg::Vec2Array;
|
|
|
|
_texCoords->setDataVariance(osg::Object::DYNAMIC);
|
|
|
|
_texCoords->reserve(128 * 4);
|
|
|
|
_geom->setTexCoordArray(0, _texCoords);
|
2007-06-24 07:57:45 +00:00
|
|
|
osg::Vec3Array* colors = new osg::Vec3Array;
|
|
|
|
colors->push_back(osg::Vec3(1.0f, 1.0f, 1.0f)); // color of echos
|
|
|
|
colors->push_back(osg::Vec3(1.0f, 0.0f, 0.0f)); // arc mask
|
|
|
|
colors->push_back(osg::Vec3(0.0f, 0.0f, 0.0f)); // rest of mask
|
2007-07-01 14:26:06 +00:00
|
|
|
_geom->setColorBinding(osg::Geometry::BIND_PER_PRIMITIVE_SET);
|
|
|
|
_geom->setColorArray(colors);
|
2007-06-24 07:57:45 +00:00
|
|
|
osg::PrimitiveSet* pset = new osg::DrawArrays(osg::PrimitiveSet::QUADS);
|
|
|
|
pset->setDataVariance(osg::Object::DYNAMIC);
|
2007-07-01 14:26:06 +00:00
|
|
|
_geom->addPrimitiveSet(pset);
|
2007-06-24 07:57:45 +00:00
|
|
|
pset = new osg::DrawArrays(osg::PrimitiveSet::QUADS);
|
|
|
|
pset->setDataVariance(osg::Object::DYNAMIC);
|
2007-07-01 14:26:06 +00:00
|
|
|
_geom->addPrimitiveSet(pset);
|
2007-06-24 07:57:45 +00:00
|
|
|
pset = new osg::DrawArrays(osg::PrimitiveSet::TRIANGLES);
|
|
|
|
pset->setDataVariance(osg::Object::DYNAMIC);
|
2007-07-01 14:26:06 +00:00
|
|
|
_geom->addPrimitiveSet(pset);
|
|
|
|
_geom->setInitialBound(osg::BoundingBox(osg::Vec3f(-256.0f, -256.0f, 0.0f),
|
2007-06-24 07:57:45 +00:00
|
|
|
osg::Vec3f(256.0f, 256.0f, 0.0f)));
|
2007-07-01 14:26:06 +00:00
|
|
|
_radarGeode->addDrawable(_geom);
|
2007-06-24 07:57:45 +00:00
|
|
|
_odg->allocRT();
|
|
|
|
// Texture in the 2D panel system
|
2007-07-03 18:24:45 +00:00
|
|
|
FGTextureManager::addTexture(_texture_path.c_str(), _odg->getTexture());
|
2007-06-24 07:57:45 +00:00
|
|
|
|
2007-09-09 23:22:14 +00:00
|
|
|
_textGeode = new osg::Geode;
|
|
|
|
|
2007-06-24 07:57:45 +00:00
|
|
|
osg::Camera* camera = _odg->getCamera();
|
2007-06-29 22:44:41 +00:00
|
|
|
camera->addChild(_radarGeode.get());
|
2007-09-09 23:22:14 +00:00
|
|
|
camera->addChild(_textGeode.get());
|
2007-06-24 07:57:45 +00:00
|
|
|
}
|
|
|
|
|
2007-06-29 22:44:41 +00:00
|
|
|
|
2007-06-24 07:57:45 +00:00
|
|
|
// Local coordinates for each echo
|
|
|
|
const osg::Vec3f echoCoords[4] = {
|
|
|
|
osg::Vec3f(-.7f, -.7f, 0.0f), osg::Vec3f(.7f, -.7f, 0.0f),
|
|
|
|
osg::Vec3f(.7f, .7f, 0.0f), osg::Vec3f(-.7f, .7f, 0.0f)
|
|
|
|
};
|
|
|
|
|
2007-06-29 22:44:41 +00:00
|
|
|
|
2007-06-24 07:57:45 +00:00
|
|
|
const osg::Vec2f echoTexCoords[4] = {
|
2007-06-29 22:44:41 +00:00
|
|
|
osg::Vec2f(0.0f, 0.0f), osg::Vec2f(UNIT, 0.0f),
|
|
|
|
osg::Vec2f(UNIT, UNIT), osg::Vec2f(0.0f, UNIT)
|
2007-06-24 07:57:45 +00:00
|
|
|
};
|
|
|
|
|
2007-06-29 22:44:41 +00:00
|
|
|
|
2007-06-24 07:57:45 +00:00
|
|
|
// helper
|
|
|
|
static void
|
|
|
|
addQuad(osg::Vec2Array* vertices, osg::Vec2Array* texCoords,
|
|
|
|
const osg::Matrixf& transform, const osg::Vec2f& texBase)
|
|
|
|
{
|
|
|
|
for (int i = 0; i < 4; i++) {
|
|
|
|
const osg::Vec3f coords = transform.preMult(echoCoords[i]);
|
|
|
|
texCoords->push_back(texBase + echoTexCoords[i]);
|
|
|
|
vertices->push_back(osg::Vec2f(coords.x(), coords.y()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-06-29 22:44:41 +00:00
|
|
|
|
2007-06-24 07:57:45 +00:00
|
|
|
// Rotate by a heading value
|
|
|
|
static inline
|
|
|
|
osg::Matrixf wxRotate(float angle)
|
|
|
|
{
|
|
|
|
return osg::Matrixf::rotate(angle, 0.0f, 0.0f, -1.0f);
|
2005-10-08 11:55:18 +00:00
|
|
|
}
|
|
|
|
|
2007-06-29 22:44:41 +00:00
|
|
|
|
2005-10-08 11:55:18 +00:00
|
|
|
void
|
|
|
|
wxRadarBg::update (double delta_time_sec)
|
|
|
|
{
|
2007-06-24 07:57:45 +00:00
|
|
|
if ( ! _sim_init_done ) {
|
2006-06-09 18:48:57 +00:00
|
|
|
if ( ! fgGetBool("sim/sceneryloaded", false) )
|
2005-10-08 11:55:18 +00:00
|
|
|
return;
|
2007-06-24 07:57:45 +00:00
|
|
|
|
|
|
|
_sim_init_done = true;
|
2005-10-08 11:55:18 +00:00
|
|
|
}
|
2007-06-24 07:57:45 +00:00
|
|
|
if ( !_odg || ! _serviceable_node->getBoolValue() ) {
|
2005-10-08 11:55:18 +00:00
|
|
|
_Instrument->setStringValue("status","");
|
|
|
|
return;
|
|
|
|
}
|
2007-06-24 22:13:25 +00:00
|
|
|
_time += delta_time_sec;
|
|
|
|
if (_time < _interval)
|
|
|
|
return;
|
|
|
|
|
|
|
|
_time = 0.0;
|
2007-06-24 07:57:45 +00:00
|
|
|
|
2007-06-29 22:44:41 +00:00
|
|
|
string mode = _Instrument->getStringValue("display-mode", "arc");
|
|
|
|
if (mode == "map") {
|
|
|
|
if (_display_mode != MAP) {
|
|
|
|
_display_mode = MAP;
|
|
|
|
center_map();
|
|
|
|
}
|
|
|
|
} else if (mode == "plan") {
|
|
|
|
_display_mode = PLAN;
|
|
|
|
} else {
|
|
|
|
_display_mode = ARC;
|
|
|
|
}
|
2007-06-24 07:57:45 +00:00
|
|
|
|
2007-06-29 22:44:41 +00:00
|
|
|
string switchKnob = _Instrument->getStringValue("switch", "on");
|
2007-06-24 07:57:45 +00:00
|
|
|
if ( _last_switchKnob != switchKnob ) {
|
2005-10-08 11:55:18 +00:00
|
|
|
// 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
|
2007-06-29 22:44:41 +00:00
|
|
|
//if ( _last_switchKnob == "off" )
|
2007-07-03 18:24:45 +00:00
|
|
|
//_odg->set_texture(_texture_path.c_str(), _resultTexture->getHandle());
|
|
|
|
|
2007-06-24 07:57:45 +00:00
|
|
|
_last_switchKnob = switchKnob;
|
2005-10-16 17:31:06 +00:00
|
|
|
}
|
|
|
|
|
2006-06-09 18:48:57 +00:00
|
|
|
if ( switchKnob == "off" ) {
|
|
|
|
_Instrument->setStringValue("status","");
|
|
|
|
} else if ( switchKnob == "stby" ) {
|
|
|
|
_Instrument->setStringValue("status","STBY");
|
|
|
|
} else if ( switchKnob == "tst" ) {
|
|
|
|
_Instrument->setStringValue("status","TST");
|
2007-06-29 22:44:41 +00:00
|
|
|
// find something interesting to do...
|
|
|
|
} else {
|
|
|
|
float r = _Instrument->getFloatValue("range", 40.0);
|
|
|
|
if (r != _range_nm) {
|
|
|
|
center_map();
|
|
|
|
_range_nm = r;
|
|
|
|
}
|
2007-06-24 07:57:45 +00:00
|
|
|
|
2007-06-29 22:44:41 +00:00
|
|
|
_radar_ref_rng = _radar_ref_rng_node->getDoubleValue();
|
|
|
|
_view_heading = get_heading() * SG_DEGREES_TO_RADIANS;
|
|
|
|
_centerTrans.makeTranslate(0.0f, 0.0f, 0.0f);
|
|
|
|
|
|
|
|
_scale = 200.0 / _range_nm;
|
|
|
|
_angle_offset = 0;
|
|
|
|
|
|
|
|
if ( _display_mode == ARC ) {
|
|
|
|
_scale = 2*200.0f / _range_nm;
|
|
|
|
_angle_offset = -_view_heading;
|
|
|
|
_centerTrans.makeTranslate(0.0f, -200.0f, 0.0f);
|
2007-06-24 07:57:45 +00:00
|
|
|
|
2007-06-29 22:44:41 +00:00
|
|
|
} else if ( _display_mode == MAP ) {
|
|
|
|
apply_map_offset();
|
2007-06-24 07:57:45 +00:00
|
|
|
|
2007-06-29 22:44:41 +00:00
|
|
|
bool centre = _radar_centre_node->getBoolValue();
|
|
|
|
if (centre) {
|
|
|
|
center_map();
|
|
|
|
_radar_centre_node->setBoolValue(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
//SG_LOG(SG_GENERAL, SG_DEBUG, "Radar: displacement "
|
|
|
|
// << _x_offset <<", "<<_y_offset
|
|
|
|
// << " user_speed_east_fps * SG_FPS_TO_KT "
|
|
|
|
// << user_speed_east_fps * SG_FPS_TO_KT
|
|
|
|
// << " user_speed_north_fps * SG_FPS_TO_KT "
|
|
|
|
// << user_speed_north_fps * SG_FPS_TO_KT
|
|
|
|
// << " dt " << delta_time_sec);
|
|
|
|
|
|
|
|
_centerTrans.makeTranslate(_x_offset, _y_offset, 0.0f);
|
2007-06-24 07:57:45 +00:00
|
|
|
|
2007-06-29 22:44:41 +00:00
|
|
|
} else if ( _display_mode == PLAN ) {
|
2007-09-09 23:22:14 +00:00
|
|
|
if (_radar_rotate_node->getBoolValue()) {
|
|
|
|
_angle_offset = -_view_heading;
|
|
|
|
}
|
2006-06-09 18:48:57 +00:00
|
|
|
} else {
|
2007-06-29 22:44:41 +00:00
|
|
|
// rose
|
2006-06-09 18:48:57 +00:00
|
|
|
}
|
2005-10-08 11:55:18 +00:00
|
|
|
|
2007-06-29 22:44:41 +00:00
|
|
|
_vertices->clear();
|
|
|
|
_texCoords->clear();
|
2007-09-09 23:22:14 +00:00
|
|
|
_textGeode->removeDrawables(0, _textGeode->getNumDrawables());
|
2007-06-24 07:57:45 +00:00
|
|
|
|
|
|
|
|
2007-06-29 22:44:41 +00:00
|
|
|
update_weather();
|
|
|
|
|
|
|
|
|
|
|
|
osg::DrawArrays* quadPSet
|
|
|
|
= static_cast<osg::DrawArrays*>(_geom->getPrimitiveSet(0));
|
|
|
|
quadPSet->set(osg::PrimitiveSet::QUADS, 0, _vertices->size());
|
|
|
|
quadPSet->dirty();
|
|
|
|
|
|
|
|
// erase what is out of sight of antenna
|
|
|
|
/*
|
|
|
|
|\ /|
|
|
|
|
| \ / |
|
|
|
|
| \ / |
|
|
|
|
---------
|
|
|
|
| |
|
|
|
|
| |
|
|
|
|
---------
|
|
|
|
*/
|
|
|
|
|
|
|
|
osg::DrawArrays* maskPSet
|
|
|
|
= static_cast<osg::DrawArrays*>(_geom->getPrimitiveSet(1));
|
|
|
|
osg::DrawArrays* trimaskPSet
|
|
|
|
= static_cast<osg::DrawArrays*>(_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);
|
2007-07-01 14:26:06 +00:00
|
|
|
|
2007-06-29 22:44:41 +00:00
|
|
|
// 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));
|
|
|
|
|
2007-07-01 14:26:06 +00:00
|
|
|
const osg::Vec2f whiteSpot(1.0f, 0.0f);
|
2007-06-29 22:44:41 +00:00
|
|
|
for (int i = 0; i < 3 * 4; i++)
|
|
|
|
_texCoords->push_back(whiteSpot);
|
|
|
|
|
|
|
|
trimaskPSet->set(osg::PrimitiveSet::TRIANGLES, firstQuadVert + 4,
|
|
|
|
3 * 4);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
maskPSet->set(osg::PrimitiveSet::QUADS, 0, 0);
|
|
|
|
trimaskPSet->set(osg::PrimitiveSet::TRIANGLES, 0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
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();
|
2007-06-24 07:57:45 +00:00
|
|
|
}
|
2007-06-29 22:44:41 +00:00
|
|
|
}
|
2007-06-24 07:57:45 +00:00
|
|
|
|
2007-06-29 22:44:41 +00:00
|
|
|
|
|
|
|
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());
|
2007-06-24 07:57:45 +00:00
|
|
|
|
|
|
|
list_of_SGWxRadarEcho *radarEcho = &_radarEchoBuffer;
|
2007-06-29 22:44:41 +00:00
|
|
|
list_of_SGWxRadarEcho::iterator iradarEcho, end = radarEcho->end();
|
2007-06-24 07:57:45 +00:00
|
|
|
const float LWClevel[] = { 0.1f, 0.5f, 2.1f };
|
|
|
|
|
|
|
|
// draw the cloud radar echo
|
|
|
|
bool drawClouds = _radar_weather_node->getBoolValue();
|
|
|
|
if (drawClouds) {
|
2007-06-29 22:44:41 +00:00
|
|
|
|
|
|
|
// we do that in 3 passes, one for each color level
|
2007-06-24 07:57:45 +00:00
|
|
|
// this is to 'merge' same colors together
|
|
|
|
for (int level = 0; level <= 2; level++) {
|
2007-06-29 22:44:41 +00:00
|
|
|
float col = level * UNIT;
|
2007-06-24 07:57:45 +00:00
|
|
|
|
2007-06-29 22:44:41 +00:00
|
|
|
for (iradarEcho = radarEcho->begin(); iradarEcho != end; ++iradarEcho) {
|
|
|
|
int cloudId = iradarEcho->cloudId;
|
|
|
|
bool upgrade = (cloudId >> 5) & 1;
|
2006-06-09 18:48:57 +00:00
|
|
|
float lwc = iradarEcho->LWC + (upgrade ? 1.0f : 0.0f);
|
2007-06-24 07:57:45 +00:00
|
|
|
|
2006-06-09 18:48:57 +00:00
|
|
|
// skip ns
|
2007-06-24 07:57:45 +00:00
|
|
|
if (iradarEcho->LWC >= 0.5 && iradarEcho->LWC <= 0.6)
|
2006-06-09 18:48:57 +00:00
|
|
|
continue;
|
2007-06-24 07:57:45 +00:00
|
|
|
|
2007-06-29 22:44:41 +00:00
|
|
|
if (iradarEcho->lightning || lwc < LWClevel[level])
|
|
|
|
continue;
|
2006-06-09 18:48:57 +00:00
|
|
|
|
2007-06-29 22:44:41 +00:00
|
|
|
float radius = sgSqrt(iradarEcho->dist) * SG_METER_TO_NM * _scale;
|
|
|
|
float size = iradarEcho->radius * 2.0 * SG_METER_TO_NM * _scale;
|
2007-06-24 07:57:45 +00:00
|
|
|
|
2007-06-29 22:44:41 +00:00
|
|
|
if (radius - size > 180)
|
2007-06-24 07:57:45 +00:00
|
|
|
continue;
|
|
|
|
|
2007-06-29 22:44:41 +00:00
|
|
|
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);
|
2005-10-08 11:55:18 +00:00
|
|
|
}
|
2006-06-09 18:48:57 +00:00
|
|
|
}
|
2007-06-29 22:44:41 +00:00
|
|
|
}
|
2007-06-24 07:57:45 +00:00
|
|
|
|
2007-06-29 22:44:41 +00:00
|
|
|
// draw lightning echos
|
|
|
|
bool drawLightning = _Instrument->getBoolValue("lightning", true);
|
|
|
|
if ( drawLightning ) {
|
|
|
|
const osg::Vec2f texBase(3 * UNIT, 4 * UNIT);
|
2007-06-24 07:57:45 +00:00
|
|
|
|
2007-06-29 22:44:41 +00:00
|
|
|
for (iradarEcho = radarEcho->begin(); iradarEcho != end; ++iradarEcho) {
|
|
|
|
if (!iradarEcho->lightning)
|
|
|
|
continue;
|
2007-06-24 07:57:45 +00:00
|
|
|
|
2007-06-29 22:44:41 +00:00
|
|
|
float size = UNIT * 0.5f;
|
|
|
|
float radius = iradarEcho->dist * _scale;
|
|
|
|
float angle = iradarEcho->heading * SG_DEGREES_TO_RADIANS
|
|
|
|
- _angle_offset;
|
2007-06-24 07:57:45 +00:00
|
|
|
|
2007-06-29 22:44:41 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-06-24 07:57:45 +00:00
|
|
|
|
2008-06-01 18:08:01 +00:00
|
|
|
|
2007-09-09 23:22:14 +00:00
|
|
|
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);
|
2008-06-01 18:08:01 +00:00
|
|
|
callsign->setCharacterSize(_font_size);
|
|
|
|
callsign->setColor(selected ? osg::Vec4(1, 1, 1, 1) : _font_color);
|
2007-09-09 23:22:14 +00:00
|
|
|
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);
|
2008-06-01 18:08:01 +00:00
|
|
|
callsign->setLineSpacing(_font_spacing);
|
|
|
|
|
2007-09-09 23:22:14 +00:00
|
|
|
stringstream text;
|
2008-06-01 18:08:01 +00:00
|
|
|
text << ac->_getCallsign() << endl
|
2007-09-09 23:22:14 +00:00
|
|
|
<< 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);
|
|
|
|
}
|
2007-06-24 07:57:45 +00:00
|
|
|
|
2008-06-01 18:08:01 +00:00
|
|
|
|
2007-06-29 22:44:41 +00:00
|
|
|
void
|
|
|
|
wxRadarBg::update_aircraft()
|
|
|
|
{
|
|
|
|
if (!_ai_enabled_node->getBoolValue())
|
|
|
|
return;
|
2007-06-24 07:57:45 +00:00
|
|
|
|
2007-06-29 22:44:41 +00:00
|
|
|
bool draw_echoes = _radar_position_node->getBoolValue();
|
2007-09-09 23:22:14 +00:00
|
|
|
bool draw_symbols = _radar_symbol_node->getBoolValue();
|
|
|
|
bool draw_data = _radar_data_node->getBoolValue();
|
|
|
|
if (!draw_echoes && !draw_symbols && !draw_data)
|
2007-06-29 22:44:41 +00:00
|
|
|
return;
|
2007-06-24 07:57:45 +00:00
|
|
|
|
2007-06-29 22:44:41 +00:00
|
|
|
radar_list_type radar_list = _ai->get_ai_list();
|
2008-03-17 08:47:16 +00:00
|
|
|
//SG_LOG(SG_GENERAL, SG_DEBUG, "Radar: AI submodel list size" << radar_list.size());
|
2007-06-29 22:44:41 +00:00
|
|
|
if (radar_list.empty())
|
|
|
|
return;
|
2007-06-24 07:57:45 +00:00
|
|
|
|
2008-03-17 08:47:16 +00:00
|
|
|
//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};
|
2007-06-24 07:57:45 +00:00
|
|
|
|
2007-06-29 22:44:41 +00:00
|
|
|
double user_lat = _user_lat_node->getDoubleValue();
|
|
|
|
double user_lon = _user_lon_node->getDoubleValue();
|
|
|
|
double user_alt = _user_alt_node->getDoubleValue();
|
2007-06-24 07:57:45 +00:00
|
|
|
|
2007-09-09 23:22:14 +00:00
|
|
|
float limit = _radar_coverage_node->getFloatValue();
|
|
|
|
if (limit > 180)
|
|
|
|
limit = 180;
|
|
|
|
else if (limit < 0)
|
|
|
|
limit = 0;
|
|
|
|
limit *= SG_DEGREES_TO_RADIANS;
|
|
|
|
|
2007-06-29 22:44:41 +00:00
|
|
|
radar_list_iterator it = radar_list.begin();
|
|
|
|
radar_list_iterator end = radar_list.end();
|
2007-09-09 23:22:14 +00:00
|
|
|
FGAIBase *selected_ac = 0;
|
|
|
|
double selected_radius = 0;
|
|
|
|
double selected_bearing = 0;
|
|
|
|
int selected_id = fgGetInt("/instrumentation/radar/selected-id", -1);
|
2007-06-29 22:44:41 +00:00
|
|
|
|
|
|
|
for (; it != end; ++it) {
|
2008-03-22 09:31:06 +00:00
|
|
|
FGAIBase *ac = (*it).get();
|
2007-06-29 22:44:41 +00:00
|
|
|
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,
|
2008-03-17 08:47:16 +00:00
|
|
|
/* "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);*/
|
2007-06-29 22:44:41 +00:00
|
|
|
|
|
|
|
bool isVisible = withinRadarHorizon(user_alt, alt, range);
|
2008-03-17 08:47:16 +00:00
|
|
|
//SG_LOG(SG_GENERAL, SG_DEBUG, "Radar: visible " << isVisible);
|
2007-06-29 22:44:41 +00:00
|
|
|
if (!isVisible)
|
|
|
|
continue;
|
2007-06-24 07:57:45 +00:00
|
|
|
|
2007-06-29 22:44:41 +00:00
|
|
|
if (!inRadarRange(type, range))
|
|
|
|
continue;
|
2007-06-24 07:57:45 +00:00
|
|
|
|
2007-06-29 22:44:41 +00:00
|
|
|
bearing *= SG_DEGREES_TO_RADIANS;
|
|
|
|
heading *= SG_DEGREES_TO_RADIANS;
|
2007-06-24 07:57:45 +00:00
|
|
|
|
2007-06-29 22:44:41 +00:00
|
|
|
float radius = range * _scale;
|
|
|
|
float angle = calcRelBearing(bearing, _view_heading);
|
2007-06-24 07:57:45 +00:00
|
|
|
|
2007-06-29 22:44:41 +00:00
|
|
|
if (angle > limit || angle < -limit)
|
|
|
|
continue;
|
2007-06-24 07:57:45 +00:00
|
|
|
|
2007-06-29 22:44:41 +00:00
|
|
|
bearing += _angle_offset;
|
|
|
|
heading += _angle_offset;
|
2007-06-24 07:57:45 +00:00
|
|
|
|
2007-06-29 22:44:41 +00:00
|
|
|
// pos mode
|
|
|
|
if (draw_echoes) {
|
|
|
|
float echo_radius = echo_radii[type] * 120;
|
|
|
|
float size = echo_radius * UNIT;
|
2007-06-24 07:57:45 +00:00
|
|
|
|
2007-06-29 22:44:41 +00:00
|
|
|
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"
|
2008-03-17 08:47:16 +00:00
|
|
|
//<< " ID=" << ac->getID()
|
|
|
|
//<< " type=" << type
|
2007-06-29 22:44:41 +00:00
|
|
|
// << " radius=" << radius
|
|
|
|
// << " angle=" << angle * SG_RADIANS_TO_DEGREES);
|
|
|
|
}
|
2007-06-24 07:57:45 +00:00
|
|
|
|
2007-06-29 22:44:41 +00:00
|
|
|
// 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);
|
|
|
|
}
|
2008-06-01 18:08:01 +00:00
|
|
|
|
2007-09-09 23:22:14 +00:00
|
|
|
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);
|
2007-06-24 07:57:45 +00:00
|
|
|
}
|
2007-06-29 22:44:41 +00:00
|
|
|
}
|
2007-06-24 07:57:45 +00:00
|
|
|
|
|
|
|
|
2007-06-29 22:44:41 +00:00
|
|
|
void
|
|
|
|
wxRadarBg::update_tacan()
|
|
|
|
{
|
|
|
|
// draw TACAN symbol
|
|
|
|
int mode = _radar_mode_control_node->getIntValue();
|
|
|
|
bool inRange = _tacan_in_range_node->getBoolValue();
|
2006-06-09 18:48:57 +00:00
|
|
|
|
2007-06-29 22:44:41 +00:00
|
|
|
if (mode != 1 || !inRange)
|
|
|
|
return;
|
2007-06-24 07:57:45 +00:00
|
|
|
|
2007-06-29 22:44:41 +00:00
|
|
|
float size = 600 * UNIT;
|
|
|
|
float radius = _tacan_distance_node->getFloatValue() * _scale;
|
|
|
|
float angle = _tacan_bearing_node->getFloatValue() * SG_DEGREES_TO_RADIANS
|
|
|
|
+ _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);
|
|
|
|
addQuad(_vertices, _texCoords, m, texBase);
|
|
|
|
|
|
|
|
//SG_LOG(SG_GENERAL, SG_DEBUG, "Radar: drawing TACAN"
|
|
|
|
// << " dist=" << radius
|
|
|
|
// << " view_heading=" << _view_heading * SG_RADIANS_TO_DEGREES
|
|
|
|
// << " bearing=" << angle * SG_RADIANS_TO_DEGREES
|
|
|
|
// << " x=" << x << " y="<< y
|
|
|
|
// << " size=" << size);
|
2007-06-24 07:57:45 +00:00
|
|
|
}
|
|
|
|
|
2007-06-29 22:44:41 +00:00
|
|
|
|
2007-06-24 07:57:45 +00:00
|
|
|
void
|
2007-06-29 22:44:41 +00:00
|
|
|
wxRadarBg::update_heading_marker()
|
2007-06-24 07:57:45 +00:00
|
|
|
{
|
2007-06-30 08:53:06 +00:00
|
|
|
if (!_radar_hdg_marker_node->getBoolValue())
|
|
|
|
return;
|
2007-06-24 07:57:45 +00:00
|
|
|
|
2007-06-29 22:44:41 +00:00
|
|
|
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));
|
2007-06-24 07:57:45 +00:00
|
|
|
|
2007-06-29 22:44:41 +00:00
|
|
|
m *= _centerTrans;
|
|
|
|
addQuad(_vertices, _texCoords, m, texBase);
|
2007-06-24 07:57:45 +00:00
|
|
|
|
2007-06-29 22:44:41 +00:00
|
|
|
//SG_LOG(SG_GENERAL, SG_DEBUG, "Radar: drawing heading marker"
|
|
|
|
// << " x,y " << x <<","<< y
|
|
|
|
// << " dist" << dist
|
|
|
|
// << " view_heading" << _view_heading * SG_RADIANS_TO_DEGREES
|
|
|
|
// << " heading " << iradarEcho->heading * SG_RADIANS_TO_DEGREES
|
|
|
|
// << " angle " << angle * SG_RADIANS_TO_DEGREES);
|
|
|
|
}
|
2007-06-24 07:57:45 +00:00
|
|
|
|
|
|
|
|
2007-06-29 22:44:41 +00:00
|
|
|
void
|
|
|
|
wxRadarBg::center_map()
|
|
|
|
{
|
|
|
|
_lat = _user_lat_node->getDoubleValue();
|
|
|
|
_lon = _user_lon_node->getDoubleValue();
|
|
|
|
_x_offset = _y_offset = 0;
|
2007-06-24 07:57:45 +00:00
|
|
|
}
|
|
|
|
|
2007-06-29 22:44:41 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
wxRadarBg::apply_map_offset()
|
|
|
|
{
|
|
|
|
double lat = _user_lat_node->getDoubleValue();
|
|
|
|
double lon = _user_lon_node->getDoubleValue();
|
|
|
|
double bearing, distance, az2;
|
|
|
|
geo_inverse_wgs_84(_lat, _lon, lat, lon, &bearing, &az2, &distance);
|
|
|
|
distance *= SG_METER_TO_NM * _scale;
|
|
|
|
bearing *= SG_DEGREES_TO_RADIANS;
|
|
|
|
_x_offset += sin(bearing) * distance;
|
|
|
|
_y_offset += cos(bearing) * distance;
|
|
|
|
_lat = lat;
|
|
|
|
_lon = lon;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-06-24 07:57:45 +00:00
|
|
|
bool
|
2007-06-29 22:44:41 +00:00
|
|
|
wxRadarBg::withinRadarHorizon(double user_alt, double alt, double range_nm)
|
2007-06-24 07:57:45 +00:00
|
|
|
{
|
|
|
|
// Radar Horizon = 1.23(ht^1/2 + hr^1/2),
|
|
|
|
//don't allow negative altitudes (an approximation - yes altitudes can be negative)
|
|
|
|
|
|
|
|
if (user_alt < 0)
|
|
|
|
user_alt = 0;
|
|
|
|
|
|
|
|
if (alt < 0)
|
|
|
|
alt = 0;
|
|
|
|
|
|
|
|
double radarhorizon = 1.23 * (sqrt(alt) + sqrt(user_alt));
|
2008-03-17 08:47:16 +00:00
|
|
|
//SG_LOG(SG_GENERAL, SG_DEBUG, "Radar: horizon " << radarhorizon);
|
2007-06-29 22:44:41 +00:00
|
|
|
return radarhorizon >= range_nm;
|
2005-10-08 11:55:18 +00:00
|
|
|
}
|
2007-06-24 07:57:45 +00:00
|
|
|
|
2007-06-29 22:44:41 +00:00
|
|
|
|
2007-06-24 07:57:45 +00:00
|
|
|
bool
|
2007-06-29 22:44:41 +00:00
|
|
|
wxRadarBg::inRadarRange(int type, double range_nm)
|
2007-06-24 07:57:45 +00:00
|
|
|
{
|
|
|
|
//The Radar Equation:
|
|
|
|
//
|
|
|
|
// MaxRange^4 = (TxPower * AntGain^2 * lambda^2 * sigma)/((constant) * MDS)
|
|
|
|
//
|
|
|
|
// Where (constant) = (4*pi)3 and MDS is the Minimum Detectable Signal power.
|
|
|
|
//
|
|
|
|
// For a given radar we can assume that the only variable is sigma,
|
|
|
|
// the target radar cross section.
|
|
|
|
//
|
2007-06-29 22:44:41 +00:00
|
|
|
// Here, we will use a normalised rcs (sigma) for a standard taget and assume that this
|
2007-06-24 07:57:45 +00:00
|
|
|
// will provide a maximum range of 35nm;
|
|
|
|
//
|
2007-06-29 22:44:41 +00:00
|
|
|
// TODO - make the maximum range adjustable at runtime
|
2007-06-24 07:57:45 +00:00
|
|
|
|
2008-03-17 08:47:16 +00:00
|
|
|
const double sigma[] = {0, 1, 100, 100, 0.001, 0.1, 100, 100, 1, 1, 1};
|
2007-06-29 22:44:41 +00:00
|
|
|
double constant = _radar_ref_rng;
|
2007-06-24 07:57:45 +00:00
|
|
|
|
|
|
|
if (constant <= 0)
|
|
|
|
constant = 35;
|
|
|
|
|
|
|
|
double maxrange = constant * pow(sigma[type], 0.25);
|
2008-03-17 08:47:16 +00:00
|
|
|
//SG_LOG(SG_GENERAL, SG_DEBUG, "Radar: max range " << maxrange);
|
2007-06-29 22:44:41 +00:00
|
|
|
return maxrange >= range_nm;
|
2007-06-24 07:57:45 +00:00
|
|
|
}
|
|
|
|
|
2007-06-29 22:44:41 +00:00
|
|
|
|
2007-06-24 07:57:45 +00:00
|
|
|
void
|
2007-06-29 22:44:41 +00:00
|
|
|
wxRadarBg::calcRangeBearing(double lat, double lon, double lat2, double lon2,
|
|
|
|
double &range, double &bearing ) const
|
2007-06-24 07:57:45 +00:00
|
|
|
{
|
|
|
|
// calculate the bearing and range of the second pos from the first
|
2007-06-29 22:44:41 +00:00
|
|
|
double az2, distance;
|
2007-06-24 07:57:45 +00:00
|
|
|
geo_inverse_wgs_84(lat, lon, lat2, lon2, &bearing, &az2, &distance);
|
|
|
|
range = distance *= SG_METER_TO_NM;
|
|
|
|
}
|
|
|
|
|
2007-06-29 22:44:41 +00:00
|
|
|
|
2007-06-24 07:57:45 +00:00
|
|
|
float
|
|
|
|
wxRadarBg::calcRelBearing(float bearing, float heading)
|
|
|
|
{
|
|
|
|
float angle = bearing - heading;
|
|
|
|
|
2007-06-29 22:44:41 +00:00
|
|
|
if (angle >= SG_PI)
|
|
|
|
angle -= 2.0 * SG_PI;
|
2007-06-24 07:57:45 +00:00
|
|
|
|
|
|
|
if (angle < -SG_PI)
|
2007-06-29 22:44:41 +00:00
|
|
|
angle += 2.0 * SG_PI;
|
2007-06-24 07:57:45 +00:00
|
|
|
|
|
|
|
return angle;
|
|
|
|
}
|
|
|
|
|
2008-06-01 18:08:01 +00:00
|
|
|
|
2007-09-09 23:22:14 +00:00
|
|
|
void
|
|
|
|
wxRadarBg::updateFont()
|
|
|
|
{
|
2008-06-01 18:08:01 +00:00
|
|
|
float red = _font_node->getFloatValue("color/red", 0);
|
|
|
|
float green = _font_node->getFloatValue("color/green", 0.8);
|
|
|
|
float blue = _font_node->getFloatValue("color/blue", 0);
|
|
|
|
float alpha = _font_node->getFloatValue("color/alpha", 1);
|
|
|
|
_font_color.set(red, green, blue, alpha);
|
|
|
|
|
|
|
|
_font_size = _font_node->getFloatValue("size", 12);
|
|
|
|
_font_spacing = _font_size * _font_node->getFloatValue("line-spacing", 0.25);
|
|
|
|
string path = _font_node->getStringValue("name", DEFAULT_FONT);
|
|
|
|
|
2007-09-09 23:22:14 +00:00
|
|
|
SGPath tpath;
|
|
|
|
if (path[0] != '/') {
|
|
|
|
tpath = globals->get_fg_root();
|
|
|
|
tpath.append("Fonts");
|
|
|
|
tpath.append(path);
|
|
|
|
} else {
|
|
|
|
tpath = path;
|
|
|
|
}
|
2008-06-01 18:08:01 +00:00
|
|
|
|
2007-10-04 20:40:29 +00:00
|
|
|
#if (FG_OSG_VERSION >= 21000)
|
2007-09-09 23:22:14 +00:00
|
|
|
osg::ref_ptr<osgDB::ReaderWriter::Options> fontOptions = new osgDB::ReaderWriter::Options("monochrome");
|
2008-06-01 18:08:01 +00:00
|
|
|
osg::ref_ptr<osgText::Font> font = osgText::readFontFile(tpath.c_str(), fontOptions.get());
|
|
|
|
#else
|
2007-09-09 23:22:14 +00:00
|
|
|
osg::ref_ptr<osgText::Font> font = osgText::readFontFile(tpath.c_str());
|
|
|
|
#endif
|
2008-06-01 18:08:01 +00:00
|
|
|
|
2007-09-09 23:22:14 +00:00
|
|
|
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();
|
|
|
|
}
|
2008-06-01 18:08:01 +00:00
|
|
|
|