| 1 | // Wx Radar background texture |
| 2 | // |
| 3 | // Written by Harald JOHNSEN, started May 2005. |
| 4 | // With major amendments by Vivian MEAZZA May 2007 |
| 5 | // Ported to OSG by Tim MOORE Jun 2007 |
| 6 | // |
| 7 | // Copyright (C) 2005 Harald JOHNSEN - [email protected] |
| 8 | // |
| 9 | // This program is free software; you can redistribute it and/or |
| 10 | // modify it under the terms of the GNU General Public License as |
| 11 | // published by the Free Software Foundation; either version 2 of the |
| 12 | // License, or (at your option) any later version. |
| 13 | // |
| 14 | // This program is distributed in the hope that it will be useful, but |
| 15 | // WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 17 | // General Public License for more details. |
| 18 | // |
| 19 | // You should have received a copy of the GNU General Public License |
| 20 | // along with this program; if not, write to the Free Software |
| 21 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 22 | |
| 23 | #ifndef _INST_WXRADAR_HXX |
| 24 | #define _INST_WXRADAR_HXX |
| 25 | |
| 26 | #include <osg/ref_ptr> |
| 27 | #include <osg/Geode> |
| 28 | #include <osg/Texture2D> |
| 29 | #include <osgText/Text> |
| 30 | |
| 31 | #include <simgear/props/props.hxx> |
| 32 | #include <simgear/structure/subsystem_mgr.hxx> |
| 33 | |
| 34 | #include <vector> |
| 35 | #include <string> |
| 36 | |
| 37 | class FGODGauge; |
| 38 | |
| 39 | class wxRadarBg : public SGSubsystem, |
| 40 | public SGPropertyChangeListener |
| 41 | { |
| 42 | public: |
| 43 | wxRadarBg(SGPropertyNode *node); |
| 44 | wxRadarBg(); |
| 45 | virtual ~wxRadarBg(); |
| 46 | |
| 47 | // Subsystem API. |
| 48 | void init() override; |
| 49 | void shutdown() override; |
| 50 | void update(double dt) override; |
| 51 | |
| 52 | // Subsystem identification. |
| 53 | static const char* staticSubsystemClassId() { return "radar"; } |
| 54 | |
| 55 | virtual void valueChanged(SGPropertyNode *); |
| 56 | |
| 57 | protected: |
| 58 | std::string _name; |
| 59 | int _num; |
| 60 | double _time; |
| 61 | double _interval; |
| 62 | double _elapsed_time; |
| 63 | double _persistance; |
| 64 | |
| 65 | SGPropertyNode_ptr _serviceable_node; |
| 66 | SGPropertyNode_ptr _sceneryLoaded; |
| 67 | SGPropertyNode_ptr _Instrument; |
| 68 | SGPropertyNode_ptr _radar_mode_control_node; |
| 69 | |
| 70 | SGPropertyNode_ptr _user_lat_node; |
| 71 | SGPropertyNode_ptr _user_lon_node; |
| 72 | SGPropertyNode_ptr _user_heading_node; |
| 73 | SGPropertyNode_ptr _user_alt_node; |
| 74 | |
| 75 | FGODGauge *_odg; |
| 76 | |
| 77 | typedef struct { |
| 78 | double bearing; |
| 79 | double range; |
| 80 | double elevation; |
| 81 | double bumpiness; |
| 82 | double elapsed_time; |
| 83 | } ground_echo; |
| 84 | |
| 85 | typedef std::vector <ground_echo*> ground_echo_vector_type; |
| 86 | typedef ground_echo_vector_type::iterator ground_echo_vector_iterator; |
| 87 | |
| 88 | ground_echo_vector_type ground_echoes; |
| 89 | ground_echo_vector_iterator ground_echoes_iterator; |
| 90 | |
| 91 | // Convenience function for creating a property node with a |
| 92 | // default value |
| 93 | template<typename DefaultType> |
| 94 | SGPropertyNode *getInstrumentNode(const char *name, DefaultType value); |
| 95 | |
| 96 | private: |
| 97 | std::string _texture_path; |
| 98 | |
| 99 | typedef enum { ARC, MAP, PLAN, ROSE, BSCAN} DisplayMode; |
| 100 | DisplayMode _display_mode; |
| 101 | |
| 102 | float _range_nm; |
| 103 | float _scale; // factor to convert nm to display units |
| 104 | float _angle_offset; |
| 105 | float _view_heading; |
| 106 | float _x_offset, _y_offset; |
| 107 | |
| 108 | double _radar_ref_rng; |
| 109 | double _lat, _lon; |
| 110 | double _antenna_ht; |
| 111 | |
| 112 | SGPropertyNode_ptr _Tacan; |
| 113 | SGPropertyNode_ptr _Radar_controls; |
| 114 | |
| 115 | SGPropertyNode_ptr _user_speed_east_fps_node; |
| 116 | SGPropertyNode_ptr _user_speed_north_fps_node; |
| 117 | |
| 118 | SGPropertyNode_ptr _tacan_serviceable_node; |
| 119 | SGPropertyNode_ptr _tacan_distance_node; |
| 120 | SGPropertyNode_ptr _tacan_name_node; |
| 121 | SGPropertyNode_ptr _tacan_bearing_node; |
| 122 | SGPropertyNode_ptr _tacan_in_range_node; |
| 123 | |
| 124 | SGPropertyNode_ptr _radar_weather_node; |
| 125 | SGPropertyNode_ptr _radar_position_node; |
| 126 | SGPropertyNode_ptr _radar_data_node; |
| 127 | SGPropertyNode_ptr _radar_symbol_node; |
| 128 | |
| 129 | SGPropertyNode_ptr _radar_centre_node; |
| 130 | SGPropertyNode_ptr _radar_coverage_node; |
| 131 | SGPropertyNode_ptr _radar_ref_rng_node; |
| 132 | SGPropertyNode_ptr _radar_hdg_marker_node; |
| 133 | SGPropertyNode_ptr _radar_rotate_node; |
| 134 | SGPropertyNode_ptr _radar_tcas_node; |
| 135 | SGPropertyNode_ptr _radar_absalt_node; |
| 136 | |
| 137 | SGPropertyNode_ptr _font_node; |
| 138 | SGPropertyNode_ptr _ai_enabled_node; |
| 139 | |
| 140 | osg::ref_ptr<osg::Texture2D> _resultTexture; |
| 141 | osg::ref_ptr<osg::Texture2D> _wxEcho; |
| 142 | osg::ref_ptr<osg::Geode> _radarGeode; |
| 143 | osg::ref_ptr<osg::Geode> _textGeode; |
| 144 | osg::Geometry *_geom; |
| 145 | osg::Vec2Array *_vertices; |
| 146 | osg::Vec2Array *_texCoords; |
| 147 | osg::Matrixf _centerTrans; |
| 148 | osg::ref_ptr<osgText::Font> _font; |
| 149 | osg::Vec4 _font_color; |
| 150 | osg::Vec4 _tcas_colors[4]; |
| 151 | float _font_size; |
| 152 | float _font_spacing; |
| 153 | |
| 154 | // FIXME: implementation of radar echoes missing |
| 155 | // list_of_SGWxRadarEcho _radarEchoBuffer; |
| 156 | |
| 157 | void update_weather(); |
| 158 | void update_aircraft(); |
| 159 | void update_tacan(); |
| 160 | void update_heading_marker(); |
| 161 | void update_data(const SGPropertyNode *ac, double alt, double heading, |
| 162 | double radius, double bearing, bool selected); |
| 163 | bool update_tcas(const SGPropertyNode *model,double range,double user_alt,double alt, |
| 164 | double bearing,double radius, bool absMode); |
| 165 | void center_map(); |
| 166 | void apply_map_offset(); |
| 167 | void updateFont(); |
| 168 | void calcRangeBearing(double lat, double lon, double lat2, double lon2, |
| 169 | double &range, double &bearing) const; |
| 170 | |
| 171 | bool withinRadarHorizon(double user_alt, double alt, double range); |
| 172 | bool inRadarRange(double sigma, double range); |
| 173 | |
| 174 | float calcRelBearing(float bearing, float heading); |
| 175 | float calcRelBearingDeg(float bearing, float heading); |
| 176 | }; |
| 177 | |
| 178 | |
| 179 | template<> inline |
| 180 | SGPropertyNode *wxRadarBg::getInstrumentNode(const char *name, bool value) |
| 181 | { |
| 182 | SGPropertyNode *result = _Instrument->getNode(name, true); |
| 183 | if (!result->hasValue()) |
| 184 | result->setBoolValue(value); |
| 185 | return result; |
| 186 | } |
| 187 | |
| 188 | |
| 189 | template<> inline |
| 190 | SGPropertyNode *wxRadarBg::getInstrumentNode(const char *name, double value) |
| 191 | { |
| 192 | SGPropertyNode *result = _Instrument->getNode(name, true); |
| 193 | if (!result->hasValue()) |
| 194 | result->setDoubleValue(value); |
| 195 | return result; |
| 196 | } |
| 197 | |
| 198 | |
| 199 | template<> inline |
| 200 | SGPropertyNode *wxRadarBg::getInstrumentNode(const char *name, const char *value) |
| 201 | { |
| 202 | SGPropertyNode *result = _Instrument->getNode(name, true); |
| 203 | if (result->hasValue()) |
| 204 | result->setStringValue(value); |
| 205 | return result; |
| 206 | } |
| 207 | |
| 208 | #endif // _INST_WXRADAR_HXX |