Debian Codegraph @

src/Instrumentation/HUD/HUD_private.hxx

raw symbols SCIP
1 // HUD_private.hxx -- Intenral delcerations for the HUD
2 //
3 // Written by Michele America, started September 1997.
4 //
5 // Copyright (C) 1997 Michele F. America [micheleamerica#geocities:com]
6 // Copyright (C) 2006 Melchior FRANZ [mfranz#aon:at]
7 //
8 // This program is free software; you can redistribute it and/or
9 // modify it under the terms of the GNU General Public License as
10 // published by the Free Software Foundation; either version 2 of the
11 // License, or (at your option) any later version.
12 //
13 // This program is distributed in the hope that it will be useful, but
14 // WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 // General Public License for more details.
17 //
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the Free Software
20 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21
22 #ifndef _HUD_PRIVATE_HXX
23 #define _HUD_PRIVATE_HXX
24
25 #include <simgear/compiler.h>
26 #include <simgear/props/condition.hxx>
27
28 #include <vector>
29 #include <deque>
30 #include <cassert>
31
32 #include <osg/State>
33
34 #include <simgear/math/SGLimits.hxx>
35 #include <simgear/constants.h>
36 #include <simgear/props/props.hxx>
37
38 #include <plib/sg.h> // for lingering sgdVec3 usage below
39
40 class FGFontCache;
41 class fntRenderer;
42 class fntTexFont;
43 class FGViewer;
44 class FGRunway;
45
46 class ClipBox {
47 public:
48 ClipBox(const SGPropertyNode *, float xoffset = 0, float yoffset = 0);
49 void set();
50 void unset();
51
52 private:
53 bool _active;
54 float _xoffs, _yoffs;
55 SGConstPropertyNode_ptr _top_node;
56 SGConstPropertyNode_ptr _bot_node;
57 SGConstPropertyNode_ptr _left_node;
58 SGConstPropertyNode_ptr _right_node;
59 GLdouble _top[4];
60 GLdouble _bot[4];
61 GLdouble _left[4];
62 GLdouble _right[4];
63 };
64
65
66 class HUD::Input {
67 public:
68 Input(const SGPropertyNode *n, float factor = 1.0, float offset = 0.0,
69 float min = -SGLimitsf::max(), float max = SGLimitsf::max());
70
71 bool getBoolValue() const {
72 assert(_property);
73 return _property->getBoolValue();
74 }
75
76 std::string getStringValue() const {
77 assert(_property);
78 return _property->getStringValue();
79 }
80
81 float getFloatValue() {
82 assert(_property);
83 float f = _property->getFloatValue() * _factor + _offset;
84 if (_damped == SGLimitsf::max())
85 _damped = f;
86 if (_coeff > 0.0f)
87 f = _damped = f * (1.0f - _coeff) + _damped * _coeff;
88 return clamp(f);
89 }
90
91 inline float isValid() const { return _valid; }
92 inline float min() const { return _min; }
93 inline float max() const { return _max; }
94 inline float factor() const { return _factor; }
95 float clamp(float v) const { return v < _min ? _min : v > _max ? _max : v; }
96
97 void set_min(float m, bool force = true) {
98 if (force || _min == -SGLimitsf::max())
99 _min = m;
100 }
101 void set_max(float m, bool force = true) {
102 if (force || _max == SGLimitsf::max())
103 _max = m;
104 }
105
106 private:
107 bool _valid;
108 SGConstPropertyNode_ptr _property;
109 float _factor;
110 float _offset;
111 float _min;
112 float _max;
113 float _coeff;
114 float _damped;
115 };
116
117
118
119 class HUD::Item {
120 public:
121 Item(HUD *parent, const SGPropertyNode *, float x = 0.0f, float y = 0.0f);
122 virtual ~Item () {}
123 virtual void draw() = 0;
124 virtual bool isEnabled();
125
126 protected:
127 enum Format {
128 INVALID,
129 NONE,
130 INT,
131 LONG,
132 FLOAT,
133 DOUBLE,
134 STRING,
135 };
136
137 Format check_format(const char *) const;
138 inline float get_span() const { return _scr_span; }
139 inline int get_digits() const { return _digits; }
140
141 inline bool option_vert() const { return (_options & VERTICAL) == VERTICAL; }
142 inline bool option_left() const { return (_options & LEFT) == LEFT; }
143 inline bool option_right() const { return (_options & RIGHT) == RIGHT; }
144 inline bool option_both() const { return (_options & BOTH) == BOTH; }
145 inline bool option_noticks() const { return (_options & NOTICKS) == NOTICKS; }
146 inline bool option_notext() const { return (_options & NOTEXT) == NOTEXT; }
147 inline bool option_top() const { return (_options & TOP) == TOP; }
148 inline bool option_bottom() const { return (_options & BOTTOM) == BOTTOM; }
149
150 void draw_line(float x1, float y1, float x2, float y2);
151 void draw_stipple_line(float x1, float y1, float x2, float y2);
152 void draw_text(float x, float y, const char *msg, int align = 0, int digit = 0);
153 void draw_circle(float x1, float y1, float r) const;
154 void draw_arc(float x1, float y1, float t0, float t1, float r) const;
155 void draw_bullet(float, float, float);
156
157 HUD *_hud;
158 std::string _name;
159 int _options;
160 float _x, _y, _w, _h;
161 float _center_x, _center_y;
162
163 private:
164 SGSharedPtr<SGCondition> _condition;
165 float _scr_span; // Working values for draw;
166 int _digits;
167 };
168
169
170
171 class HUD::Label : public Item {
172 public:
173 Label(HUD *parent, const SGPropertyNode *, float x, float y);
174 virtual void draw();
175
176 private:
177 bool blink();
178
179 Input _input;
180 Format _mode;
181 std::string _format;
182 int _halign; // HUDText alignment
183 bool _box;
184 float _pointer_width;
185 float _pointer_length;
186
187 SGSharedPtr<SGCondition> _blink_condition;
188 double _blink_interval;
189 double _blink_target; // time for next blink state change
190 bool _blink_state;
191 };
192
193
194
195 // abstract base class for both moving scale and moving needle (fixed scale)
196 // indicators.
197 //
198 class HUD::Scale : public Item {
199 public:
200 Scale(HUD *parent, const SGPropertyNode *, float x, float y);
201 virtual void draw ( void ) {} // No-op here. Defined in derived classes.
202
203 protected:
204 inline float factor() const { return _display_factor; }
205 inline float range_to_show() const { return _range_shown; }
206
207 Input _input;
208 float _major_divs; // major division marker units
209 float _minor_divs; // minor division marker units
210 unsigned int _modulo; // Roll over point
211
212 private:
213 float _range_shown; // Width Units.
214 float _display_factor; // factor => screen units/range values.
215 };
216
217
218 class HUD::Gauge : public Scale {
219 public:
220 Gauge(HUD *parent, const SGPropertyNode *, float x, float y);
221 virtual void draw();
222 };
223
224
225
226 // displays the indicated quantity on a scale that moves past the
227 // pointer. It may be horizontal or vertical.
228 //
229 class HUD::Tape : public Scale {
230 public:
231 Tape(HUD *parent, const SGPropertyNode *, float x, float y);
232 virtual void draw();
233
234 protected:
235 void draw_vertical(float);
236 void draw_horizontal(float);
237 void draw_fixed_pointer(float, float, float, float, float, float);
238 char *format_value(float);
239
240 private:
241 float _val_span;
242 float _half_width_units;
243 bool _draw_tick_bottom;
244 bool _draw_tick_top;
245 bool _draw_tick_right;
246 bool _draw_tick_left;
247 bool _draw_cap_bottom;
248 bool _draw_cap_top;
249 bool _draw_cap_right;
250 bool _draw_cap_left;
251 float _marker_offset;
252 float _label_offset;
253 float _label_gap;
254 bool _pointer;
255 Format _label_fmt;
256 std::string _format;
257 int _div_ratio; // _major_divs/_minor_divs
258 bool _odd_type; // whether to put numbers at 0/2/4 or 1/3/5
259
260 enum { BUFSIZE = 64 };
261 char _buf[BUFSIZE];
262
263 enum PointerType { FIXED, MOVING } _pointer_type;
264 enum TickType { LINE, CIRCLE } _tick_type;
265 enum TickLength { VARIABLE, CONSTANT } _tick_length;
266 };
267
268
269
270 class HUD::Dial : public Scale {
271 public:
272 Dial(HUD *parent, const SGPropertyNode *, float x, float y);
273 virtual void draw();
274
275 private:
276 float _radius;
277 int _divisions;
278 };
279
280
281
282 class HUD::TurnBankIndicator : public Item {
283 public:
284 TurnBankIndicator(HUD *parent, const SGPropertyNode *, float x, float y);
285 virtual void draw();
286
287 private:
288 void draw_scale();
289 void draw_tee();
290 void draw_line(float, float, float, float);
291 void draw_tick(float angle, float r1, float r2, int side);
292
293 Input _bank;
294 Input _sideslip;
295
296 float _gap_width;
297 bool _bank_scale;
298 };
299
300
301
302 class HUD::Ladder : public Item {
303 public:
304 Ladder(HUD *parent, const SGPropertyNode *, float x, float y);
305 ~Ladder();
306 virtual void draw();
307
308 private:
309 void draw_zenith(float, float);
310 void draw_nadir(float, float);
311
312 void draw_text(float x, float y, const char *s, int align = 0) {
313 _locTextList.add(x, y, s, align, 0);
314 }
315
316 void draw_line(float x1, float y1, float x2, float y2, bool stipple = false) {
317 if (stipple)
318 _locStippleLineList.add(LineSegment(x1, y1, x2, y2));
319 else
320 _locLineList.add(LineSegment(x1, y1, x2, y2));
321 }
322
323 enum Type { PITCH, CLIMB_DIVE } _type;
324 Input _pitch;
325 Input _roll;
326 float _width_units;
327 int _div_units;
328 float _scr_hole;
329 float _zero_bar_overlength;
330 bool _dive_bar_angle;
331 float _tick_length;
332 float _vmax;
333 float _vmin;
334 float _compression;
335 bool _dynamic_origin;
336 bool _frl; // fuselage reference line
337 bool _target_spot;
338 bool _target_markers;
339 bool _velocity_vector;
340 bool _ground_velocity_vector;
341 bool _drift_marker;
342 bool _alpha_bracket;
343 bool _energy_marker;
344 bool _climb_dive_marker;
345 bool _glide_slope_marker;
346 float _glide_slope;
347 bool _energy_worm;
348 bool _waypoint_marker;
349 bool _zenith;
350 bool _nadir;
351 bool _hat;
352
353 ClipBox *_clip_box;
354 // The Ladder has its own temporary display lists
355 TextList _locTextList;
356 LineList _locLineList;
357 LineList _locStippleLineList;
358 };
359
360
361
362 // responsible for rendering the active runway in the hud (if visible).
363 //
364 class HUD::Runway : public Item {
365 public:
366 Runway(HUD *parent, const SGPropertyNode *, float x, float y);
367 virtual void draw();
368
369 private:
370 void boundPoint(const sgdVec3& v, sgdVec3& m);
371 bool boundOutsidePoints(sgdVec3& v, sgdVec3& m);
372 bool drawLine(const sgdVec3& a1, const sgdVec3& a2, const sgdVec3& p1, const sgdVec3& p2);
373 void drawArrow();
374 FGRunway* get_active_runway();
375 void get_rwy_points(sgdVec3 *points);
376 void setLineWidth();
377
378 SGPropertyNode_ptr _agl;
379 sgdVec3 _points3d[6], _points2d[6];
380 double _mm[16];
381 double _pm[16];
382 double _arrow_scale; // scales of runway indication arrow
383 double _arrow_radius;
384 double _line_scale; // maximum line scale
385 double _scale_dist; // distance where to start scaling the lines
386 double _default_pitch;
387 double _default_heading;
388 GLint _view[4];
389 FGRunway* _runway;
390 unsigned short _stipple_out; // stipple pattern of the outline of the runway
391 unsigned short _stipple_center; // stipple pattern of the center line of the runway
392 bool _draw_arrow; // draw arrow when runway is not visible in HUD
393 bool _draw_arrow_always; // always draws arrow
394 float _left, _right, _top, _bottom;
395 };
396
397
398 class HUD::AimingReticle : public Item {
399 public:
400 AimingReticle(HUD *parent, const SGPropertyNode *, float x, float y);
401 virtual void draw();
402
403 private:
404 SGSharedPtr<SGCondition> _active_condition; // stadiametric (true) or standby (false)
405 SGSharedPtr<SGCondition> _tachy_condition; // tachymetric (true) or standby (false)
406 SGSharedPtr<SGCondition> _align_condition; // tachymetric (true) or standby (false)
407
408 Input _diameter; // inner/outer radius relation
409 Input _pitch;
410 Input _yaw;
411 Input _speed;
412 Input _range;
413 Input _t0;
414 Input _t1;
415 Input _offset_x;
416 Input _offset_y;
417
418 float _bullet_size;
419 float _inner_radius;
420 float _compression;
421 float _limit_x;
422 float _limit_y;
423
424 };
425
426
427 #endif // _HUD_HXX