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