1 // Wx Radar background texture
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
7 // Copyright (C) 2005 Harald JOHNSEN - hjohnsen@evc.net
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.
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.
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.
23 #ifndef _INST_WXRADAR_HXX
24 #define _INST_WXRADAR_HXX
26 #include <osg/ref_ptr>
28 #include <osg/Texture2D>
29 #include <osgText/Text>
31 #include <simgear/props/props.hxx>
32 #include <simgear/structure/subsystem_mgr.hxx>
33 #include <simgear/environment/visual_enviro.hxx>
45 class wxRadarBg : public SGSubsystem, public SGPropertyChangeListener {
48 wxRadarBg(SGPropertyNode *node);
53 virtual void update(double dt);
54 virtual void valueChanged(SGPropertyNode *);
65 SGPropertyNode_ptr _serviceable_node;
66 SGPropertyNode_ptr _Instrument;
67 SGPropertyNode_ptr _radar_mode_control_node;
69 SGPropertyNode_ptr _user_lat_node;
70 SGPropertyNode_ptr _user_lon_node;
71 SGPropertyNode_ptr _user_heading_node;
72 SGPropertyNode_ptr _user_alt_node;
84 typedef vector <ground_echo*> ground_echo_vector_type;
85 typedef ground_echo_vector_type::iterator ground_echo_vector_iterator;
87 ground_echo_vector_type ground_echoes;
88 ground_echo_vector_iterator ground_echoes_iterator;
90 // Convenience function for creating a property node with a
92 template<typename DefaultType>
93 SGPropertyNode *getInstrumentNode(const char *name, DefaultType value);
98 typedef enum { ARC, MAP, PLAN, ROSE, BSCAN} DisplayMode;
99 DisplayMode _display_mode;
101 string _last_switchKnob;
104 float _scale; // factor to convert nm to display units
107 float _x_offset, _y_offset;
109 double _radar_ref_rng;
113 SGPropertyNode_ptr _Tacan;
114 SGPropertyNode_ptr _Radar_controls;
116 SGPropertyNode_ptr _user_speed_east_fps_node;
117 SGPropertyNode_ptr _user_speed_north_fps_node;
119 SGPropertyNode_ptr _tacan_serviceable_node;
120 SGPropertyNode_ptr _tacan_distance_node;
121 SGPropertyNode_ptr _tacan_name_node;
122 SGPropertyNode_ptr _tacan_bearing_node;
123 SGPropertyNode_ptr _tacan_in_range_node;
125 SGPropertyNode_ptr _radar_weather_node;
126 SGPropertyNode_ptr _radar_position_node;
127 SGPropertyNode_ptr _radar_data_node;
128 SGPropertyNode_ptr _radar_symbol_node;
130 SGPropertyNode_ptr _radar_centre_node;
131 SGPropertyNode_ptr _radar_coverage_node;
132 SGPropertyNode_ptr _radar_ref_rng_node;
133 SGPropertyNode_ptr _radar_hdg_marker_node;
134 SGPropertyNode_ptr _radar_rotate_node;
136 SGPropertyNode_ptr _font_node;
137 SGPropertyNode_ptr _ai_enabled_node;
139 osg::ref_ptr<osg::Texture2D> _resultTexture;
140 osg::ref_ptr<osg::Texture2D> _wxEcho;
141 osg::ref_ptr<osg::Geode> _radarGeode;
142 osg::ref_ptr<osg::Geode> _textGeode;
143 osg::Geometry *_geom;
144 osg::Vec2Array *_vertices;
145 osg::Vec2Array *_texCoords;
146 osg::Matrixf _centerTrans;
147 osg::ref_ptr<osgText::Font> _font;
148 osg::Vec4 _font_color;
152 list_of_SGWxRadarEcho _radarEchoBuffer;
154 void update_weather();
155 void update_aircraft();
157 void update_heading_marker();
158 void update_data(const SGPropertyNode *ac, double alt, double heading,
159 double radius, double bearing, bool selected);
161 void apply_map_offset();
163 void calcRangeBearing(double lat, double lon, double lat2, double lon2,
164 double &range, double &bearing) const;
166 bool withinRadarHorizon(double user_alt, double alt, double range);
167 bool inRadarRange(double sigma, double range);
169 float calcRelBearing(float bearing, float heading);
170 float calcRelBearingDeg(float bearing, float heading);
175 SGPropertyNode *wxRadarBg::getInstrumentNode(const char *name, bool value)
177 SGPropertyNode *result = _Instrument->getNode(name, true);
178 if (!result->hasValue())
179 result->setBoolValue(value);
185 SGPropertyNode *wxRadarBg::getInstrumentNode(const char *name, double value)
187 SGPropertyNode *result = _Instrument->getNode(name, true);
188 if (!result->hasValue())
189 result->setDoubleValue(value);
195 SGPropertyNode *wxRadarBg::getInstrumentNode(const char *name, const char *value)
197 SGPropertyNode *result = _Instrument->getNode(name, true);
198 if (result->hasValue())
199 result->setStringValue(value);
204 #endif // _INST_WXRADAR_HXX