]> git.mxchange.org Git - flightgear.git/blob - src/Instrumentation/wxradar.hxx
Merge branch 'torsten/auto'
[flightgear.git] / src / Instrumentation / wxradar.hxx
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 - hjohnsen@evc.net
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 #include <simgear/environment/visual_enviro.hxx>
34
35 #include <vector>
36 #include <string>
37
38 using std::vector;
39 using std::string;
40
41 class FGODGauge;
42
43 class wxRadarBg : public SGSubsystem, public SGPropertyChangeListener {
44 public:
45
46     wxRadarBg(SGPropertyNode *node);
47     wxRadarBg();
48     virtual ~wxRadarBg();
49
50     virtual void init();
51     virtual void update(double dt);
52     virtual void valueChanged(SGPropertyNode *);
53
54 protected:
55     string _name;
56     int _num;
57     double _time;
58     double _interval;
59     double _elapsed_time;
60     double _persistance;
61     bool _sim_init_done;
62
63     SGPropertyNode_ptr _serviceable_node;
64     SGPropertyNode_ptr _Instrument;
65     SGPropertyNode_ptr _radar_mode_control_node;
66
67     SGPropertyNode_ptr _user_lat_node;
68     SGPropertyNode_ptr _user_lon_node;
69     SGPropertyNode_ptr _user_heading_node;
70     SGPropertyNode_ptr _user_alt_node;
71
72     FGODGauge *_odg;
73
74     typedef struct {
75         double bearing;
76         double range;
77         double elevation;
78         double bumpiness;
79         double elapsed_time;
80     }ground_echo;
81
82     typedef vector <ground_echo*> ground_echo_vector_type;
83     typedef ground_echo_vector_type::iterator ground_echo_vector_iterator;
84
85     ground_echo_vector_type       ground_echoes;
86     ground_echo_vector_iterator   ground_echoes_iterator;
87
88     // Convenience function for creating a property node with a
89     // default value
90     template<typename DefaultType>
91     SGPropertyNode *getInstrumentNode(const char *name, DefaultType value);
92
93 private:
94     string _texture_path;
95
96     typedef enum { ARC, MAP, PLAN, ROSE, BSCAN} DisplayMode;
97     DisplayMode _display_mode;
98
99     string _last_switchKnob;
100
101     float _range_nm;
102     float _scale;   // factor to convert nm to display units
103     float _angle_offset;
104     float _view_heading;
105     float _x_offset, _y_offset;
106
107     double _radar_ref_rng;
108     double _lat, _lon;
109     double _antenna_ht;
110
111     SGPropertyNode_ptr _Tacan;
112     SGPropertyNode_ptr _Radar_controls;
113
114     SGPropertyNode_ptr _user_speed_east_fps_node;
115     SGPropertyNode_ptr _user_speed_north_fps_node;
116
117     SGPropertyNode_ptr _tacan_serviceable_node;
118     SGPropertyNode_ptr _tacan_distance_node;
119     SGPropertyNode_ptr _tacan_name_node;
120     SGPropertyNode_ptr _tacan_bearing_node;
121     SGPropertyNode_ptr _tacan_in_range_node;
122
123     SGPropertyNode_ptr _radar_weather_node;
124     SGPropertyNode_ptr _radar_position_node;
125     SGPropertyNode_ptr _radar_data_node;
126     SGPropertyNode_ptr _radar_symbol_node;
127
128     SGPropertyNode_ptr _radar_centre_node;
129     SGPropertyNode_ptr _radar_coverage_node;
130     SGPropertyNode_ptr _radar_ref_rng_node;
131     SGPropertyNode_ptr _radar_hdg_marker_node;
132     SGPropertyNode_ptr _radar_rotate_node;
133
134     SGPropertyNode_ptr _font_node;
135     SGPropertyNode_ptr _ai_enabled_node;
136
137     osg::ref_ptr<osg::Texture2D> _resultTexture;
138     osg::ref_ptr<osg::Texture2D> _wxEcho;
139     osg::ref_ptr<osg::Geode> _radarGeode;
140     osg::ref_ptr<osg::Geode> _textGeode;
141     osg::Geometry *_geom;
142     osg::Vec2Array *_vertices;
143     osg::Vec2Array *_texCoords;
144     osg::Matrixf _centerTrans;
145     osg::ref_ptr<osgText::Font> _font;
146     osg::Vec4 _font_color;
147     float _font_size;
148     float _font_spacing;
149
150     list_of_SGWxRadarEcho _radarEchoBuffer;
151
152     void update_weather();
153     void update_aircraft();
154     void update_tacan();
155     void update_heading_marker();
156     void update_data(const SGPropertyNode *ac, double alt, double heading,
157         double radius, double bearing, bool selected);
158     void center_map();
159     void apply_map_offset();
160     void updateFont();
161     void calcRangeBearing(double lat, double lon, double lat2, double lon2,
162         double &range, double &bearing) const;
163
164     bool withinRadarHorizon(double user_alt, double alt, double range);
165     bool inRadarRange(double sigma, double range);
166
167     float calcRelBearing(float bearing, float heading);
168     float calcRelBearingDeg(float bearing, float heading);
169 };
170
171
172 template<> inline
173 SGPropertyNode *wxRadarBg::getInstrumentNode(const char *name, bool value)
174 {
175     SGPropertyNode *result = _Instrument->getNode(name, true);
176     if (!result->hasValue())
177         result->setBoolValue(value);
178     return result;
179 }
180
181
182 template<> inline
183 SGPropertyNode *wxRadarBg::getInstrumentNode(const char *name, double value)
184 {
185     SGPropertyNode *result = _Instrument->getNode(name, true);
186     if (!result->hasValue())
187         result->setDoubleValue(value);
188     return result;
189 }
190
191
192 template<> inline
193 SGPropertyNode *wxRadarBg::getInstrumentNode(const char *name, const char *value)
194 {
195     SGPropertyNode *result = _Instrument->getNode(name, true);
196     if (result->hasValue())
197         result->setStringValue(value);
198     return result;
199 }
200
201
202 #endif // _INST_WXRADAR_HXX