]> git.mxchange.org Git - flightgear.git/blob - Cockpit/hud.hxx
05974867e243c07b61453ec39dcb457b8a743f5d
[flightgear.git] / Cockpit / hud.hxx
1 // hud.hxx -- hud defines and prototypes (initial draft)
2 //
3 // Written by Michele America, started September 1997.
4 //
5 // Copyright (C) 1997  Michele F. America  - nomimarketing@mail.telepac.pt
6 //
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License as
9 // published by the Free Software Foundation; either version 2 of the
10 // License, or (at your option) any later version.
11 //
12 // This program is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 // General Public License for more details.
16 //
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 //
21 // $Id$
22 // (Log is kept at end of this file)
23
24
25 #ifndef _HUD_HXX
26 #define _HUD_HXX
27
28 #ifndef __cplusplus
29 # error This library requires C++
30 #endif
31
32 #ifdef HAVE_CONFIG_H
33 #  include <config.h>
34 #endif
35
36 #ifdef HAVE_WINDOWS_H
37 #  include <windows.h>
38 #endif
39
40 #include <GL/glut.h>
41 #include <stdlib.h>
42 #include <string.h>
43
44 #ifdef HAVE_VALUES_H
45 #  include <values.h>  // for MAXINT
46 #endif
47
48 #include <fg_typedefs.h>
49 #include <fg_constants.h>
50 #include <Aircraft/aircraft.h>
51 #include <Flight/flight.h>
52 #include <Controls/controls.h>
53
54 #include <deque>        // STL double ended queue
55
56 #ifdef NEEDNAMESPACESTD
57 using namespace std;
58 #endif
59
60 #ifndef WIN32
61   typedef struct {
62       int x, y;
63   } POINT;
64  
65   typedef struct {
66       int top, bottom, left, right;
67   } RECT;
68 #endif
69
70 // View mode definitions
71
72 enum VIEW_MODES{ HUD_VIEW, PANEL_VIEW, CHASE_VIEW, TOWER_VIEW };
73
74 // DAY, NIGHT and brightness levels need to be visible where dialogs and
75 // controls can be used to set intensity and appropriate color. This will
76 // be moved.
77 // Hud general constants
78 #define DAY                1
79 #define NIGHT              2
80 #define BRT_BLACK          3
81 #define BRT_DARK           4
82 #define BRT_MEDIUM         5
83 #define BRT_LIGHT          6
84 #define SIZE_SMALL         7
85 #define SIZE_LARGE         8
86
87 // Label constants
88 #define SMALL              1
89 #define LARGE              2
90
91 #define BLINK              3
92 #define NOBLINK            4
93
94 enum fgLabelJust{ LEFT_JUST, CENTER_JUST, RIGHT_JUST } ;
95
96 // Ladder constants
97 #define NONE               1
98 #define UPPER_LEFT         2
99 #define UPPER_CENTER       3
100 #define UPPER_RIGHT        4
101 #define CENTER_RIGHT       5
102 #define LOWER_RIGHT        6
103 #define LOWER_CENTER       7
104 #define LOWER_LEFT         8
105 #define CENTER_LEFT        9
106 #define SOLID_LINES       10
107 #define DASHED_LINES      11
108 #define DASHED_NEG_LINES  12
109
110
111 #define HORIZON_FIXED   1
112 #define HORIZON_MOVING  2
113 #define LABEL_COUNTER   1
114 #define LABEL_WARNING   2
115
116 #define HUDS_AUTOTICKS           0x0001
117 #define HUDS_VERT                0x0002
118 #define HUDS_HORZ                0x0000
119 #define HUDS_TOP                 0x0004
120 #define HUDS_BOTTOM              0x0008
121 #define HUDS_LEFT     HUDS_TOP
122 #define HUDS_RIGHT    HUDS_BOTTOM
123 #define HUDS_BOTH     (HUDS_LEFT | HUDS_RIGHT)
124 #define HUDS_NOTICKS             0x0010
125 #define HUDS_ARITHTIC            0x0020
126 #define HUDS_DECITICS            0x0040
127 #define HUDS_NOTEXT              0x0080
128
129 // Ladder orientaion
130 // #define HUD_VERTICAL        1
131 // #define HUD_HORIZONTAL               2
132 // #define HUD_FREEFLOAT                3
133
134 // Ladder orientation modes
135 // #define HUD_LEFT             1
136 // #define HUD_RIGHT            2
137 // #define HUD_TOP              1
138 // #define HUD_BOTTOM           2
139 // #define HUD_V_LEFT                   1
140 // #define HUD_V_RIGHT          2
141 // #define HUD_H_TOP            1
142 // #define HUD_H_BOTTOM         2
143
144
145 // Ladder sub-types
146 // #define HUD_LIM                              1
147 // #define HUD_NOLIM                    2
148 // #define HUD_CIRC                     3
149
150 // #define HUD_INSTR_LADDER     1
151 // #define HUD_INSTR_CLADDER    2
152 // #define HUD_INSTR_HORIZON    3
153 // #define HUD_INSTR_LABEL              4
154
155 extern double get_throttleval ( void );
156 extern double get_aileronval  ( void );
157 extern double get_elevatorval ( void );
158 extern double get_elev_trimval( void );
159 extern double get_rudderval   ( void );
160 extern double get_speed       ( void );
161 extern double get_aoa         ( void );
162 extern double get_roll        ( void );
163 extern double get_pitch       ( void );
164 extern double get_heading     ( void );
165 extern double get_altitude    ( void );
166 extern double get_agl         ( void );
167 extern double get_sideslip    ( void );
168 extern double get_frame_rate  ( void );
169 extern double get_latitude    ( void );
170 extern double get_lat_min     ( void );
171 extern double get_longitude   ( void );
172 extern double get_long_min    ( void );
173 extern double get_fov         ( void );
174 extern double get_vfc_ratio   ( void );
175 extern double get_vfc_tris_drawn   ( void );
176 extern double get_climb_rate  ( void );
177
178 enum  hudinstype{ HUDno_instr,
179               HUDscale,
180               HUDlabel,
181               HUDladder,
182               HUDcirc_ladder,
183               HUDhorizon,
184               HUDguage,
185               HUDdual_inst,
186               HUDmoving_scale,
187               HUDtbi
188               };
189
190 typedef struct gltagRGBTRIPLE { // rgbt
191     GLfloat Blue;
192     GLfloat Green;
193     GLfloat Red;
194 } glRGBTRIPLE;
195
196 class instr_item {  // An Abstract Base Class (ABC)
197   private:
198     static UINT        instances;     // More than 64K instruments? Nah!
199     static int         brightness;
200     static glRGBTRIPLE color;
201
202     UINT               handle;
203     RECT               scrn_pos;      // Framing - affects scale dimensions
204                                     // and orientation. Vert vs Horz, etc.
205     DBLFNPTR           load_value_fn;
206     double             disp_factor;   // Multiply by to get numbers shown on scale.
207     UINT               opts;
208     bool               is_enabled;
209     bool               broken;
210     UINT               scr_span;      // Working values for draw;
211     POINT              mid_span;      //
212
213   public:
214     instr_item( int            x,
215                 int            y,
216                 UINT           height,
217                 UINT           width,
218                 DBLFNPTR       data_source,
219                 double         data_scaling,
220                 UINT           options,
221                 bool           working      = true);
222
223     instr_item( const instr_item & image );
224
225     instr_item & operator = ( const instr_item & rhs );
226     virtual ~instr_item ();
227
228     int          get_brightness  ( void ) { return brightness;}
229     RECT         get_location    ( void ) { return scrn_pos;  }
230     bool         is_broken       ( void ) { return broken;    }
231     bool         enabled         ( void ) { return is_enabled;}
232     bool         data_available  ( void ) { return !!load_value_fn; }
233     double       get_value       ( void ) { return load_value_fn(); }
234     double       data_scaling    ( void ) { return disp_factor; }
235     UINT         get_span        ( void ) { return scr_span;  }
236     POINT        get_centroid    ( void ) { return mid_span;  }
237     UINT         get_options     ( void ) { return opts;      }
238
239     virtual void display_enable( bool working ) { is_enabled = !! working;}
240
241
242     virtual void update( void );
243     virtual void break_display ( bool bad );
244     virtual void SetBrightness( int illumination_level ); // fgHUDSetBright...
245     void         SetPosition  ( int x, int y, UINT width, UINT height );
246     UINT    get_Handle( void );
247     virtual void draw( void ) = 0;   // Required method in derived classes
248 };
249
250 typedef instr_item *HIptr;
251 extern deque< instr_item *> HUD_deque;
252
253 // instr_item           This class has no other purpose than to maintain
254 //                      a linked list of instrument and derived class
255 // object pointers.
256
257
258 class instr_label : public instr_item {
259   private:
260     const char *pformat;
261     const char *pre_str;
262     const char *post_str;
263     fgLabelJust justify;
264     int         fontSize;
265     int         blink;
266
267   public:
268     instr_label( int          x,
269                  int          y,
270                  UINT         width,
271                  UINT         height,
272                  DBLFNPTR     data_source,
273                  const char  *label_format,
274                  const char  *pre_label_string  = 0,
275                  const char  *post_label_string = 0,
276                  double       scale_data        = 1.0,
277                  UINT         options           = HUDS_TOP,
278                  fgLabelJust  justification     = CENTER_JUST,
279                  int          font_size         = SMALL,
280                  int          blinking          = NOBLINK,
281                  bool         working           = true);
282
283     ~instr_label();
284
285     instr_label( const instr_label & image);
286     instr_label & operator = (const instr_label & rhs );
287     virtual void draw( void );       // Required method in base class
288 };
289
290 typedef instr_label * pInstlabel;
291
292 //
293 // instr_scale           This class is an abstract base class for both moving
294 //                       scale and moving needle (fixed scale) indicators. It
295 // does not draw itself, but is not instanciable.
296 //
297
298 class instr_scale : public instr_item {
299   private:
300     double range_shown;   // Width Units.
301     double Maximum_value; //                ceiling.
302     double Minimum_value; // Representation floor.
303     double scale_factor;  // factor => screen units/range values.
304     UINT   Maj_div;       // major division marker units
305     UINT   Min_div;       // minor division marker units
306     UINT   Modulo;        // Roll over point
307     int    signif_digits; // digits to show to the right.
308
309   public:
310     instr_scale( int          x,
311                  int          y,
312                  UINT         width,
313                  UINT         height,
314                  DBLFNPTR     load_fn,
315                  UINT         options,
316                  double       show_range,
317                  double       max_value    = 100.0,
318                  double       min_value    =   0.0,
319                  double       disp_scaling =   1.0,
320                  UINT         major_divs   =    10,
321                  UINT         minor_divs   =     5,
322                  UINT         rollover     =     0,
323                  int          dp_showing   =     2,
324                  bool         working      =  true);
325
326     virtual ~instr_scale();
327     instr_scale( const instr_scale & image);
328     instr_scale & operator = (const instr_scale & rhs);
329
330     virtual void draw   ( void ) {}; // No-op here. Defined in derived classes.
331     UINT   div_min      ( void ) { return Min_div;}
332     UINT   div_max      ( void ) { return Maj_div;}
333     double min_val      ( void ) { return Minimum_value;}
334     double max_val      ( void ) { return Maximum_value;}
335     UINT   modulo       ( void ) { return Modulo; }
336     double factor       ( void ) { return scale_factor;}
337     double range_to_show( void ) { return range_shown;}
338 };
339
340 // hud_card_               This class displays the indicated quantity on
341 //                         a scale that moves past the pointer. It may be
342 // horizontal or vertical, read above(left) or below(right) of the base
343 // line.
344
345 class hud_card : public instr_scale {
346   private:
347     double val_span;
348     double half_width_units;
349
350   public:
351     hud_card( int      x,
352               int      y,
353               UINT     width,
354               UINT     height,
355               DBLFNPTR load_fn,
356               UINT     options,
357               double   maxValue      = 100.0,
358               double   minValue      =   0.0,
359               double   disp_scaling  =   1.0,
360               UINT     major_divs    =  10,
361               UINT     minor_divs    =   5,
362               UINT     modulator     = 100,
363               int      dp_showing    =   2,
364               double   value_span    = 100.0,
365               bool     working       = true);
366
367     ~hud_card();
368     hud_card( const hud_card & image);
369     hud_card & operator = (const hud_card & rhs );
370 //    virtual void display_enable( bool setting );
371     virtual void draw( void );       // Required method in base class
372 };
373
374 typedef hud_card * pCardScale;
375
376 class guage_instr : public instr_scale {
377   private:
378
379   public:
380     guage_instr( int       x,
381                  int       y,
382                  UINT      width,
383                  UINT      height,
384                  DBLFNPTR  load_fn,
385                  UINT      options,
386                  double    disp_scaling = 1.0,
387                  double    maxValue     = 100,
388                  double    minValue     =   0,
389                  UINT      major_divs   =  50,
390                  UINT      minor_divs   =   0,
391                  int       dp_showing   =   2,
392                  UINT      modulus      =   0,
393                  bool      working      = true);
394
395     ~guage_instr();
396     guage_instr( const guage_instr & image);
397     guage_instr & operator = (const guage_instr & rhs );
398     virtual void draw( void );       // Required method in base class
399 };
400
401 typedef guage_instr * pGuageInst;
402 //
403 // dual_instr_item         This class was created to form the base class
404 //                         for both panel and HUD Turn Bank Indicators.
405
406 class dual_instr_item : public instr_item {
407   private:
408     DBLFNPTR alt_data_source;
409
410   public:
411     dual_instr_item ( int       x,
412                       int       y,
413                       UINT      width,
414                       UINT      height,
415                       DBLFNPTR  chn1_source,
416                       DBLFNPTR  chn2_source,
417                       bool      working     = true,
418                       UINT      options  = HUDS_TOP);
419
420     virtual ~dual_instr_item() {};
421     dual_instr_item( const dual_instr_item & image);
422     dual_instr_item & operator = (const dual_instr_item & rhs );
423
424     double current_ch1( void ) { return alt_data_source();}
425     double current_ch2( void ) { return get_value();}
426     virtual void draw ( void ) { }
427 };
428
429 class fgTBI_instr : public dual_instr_item {
430   private:
431     UINT BankLimit;
432     UINT SlewLimit;
433     UINT scr_hole;
434
435   public:
436     fgTBI_instr( int       x,
437                  int       y,
438                  UINT      width,
439                  UINT      height,
440                  DBLFNPTR  chn1_source  = get_roll,
441                  DBLFNPTR  chn2_source  = get_sideslip,
442                  double    maxBankAngle = 45.0,
443                  double    maxSlipAngle =  5.0,
444                  UINT      gap_width    =  5.0,
445                  bool      working      =  true);
446
447     fgTBI_instr( const fgTBI_instr & image);
448     fgTBI_instr & operator = (const fgTBI_instr & rhs );
449
450     ~fgTBI_instr();
451
452     UINT bank_limit( void ) { return BankLimit;}
453     UINT slew_limit( void ) { return SlewLimit;}
454
455     virtual void draw( void );       // Required method in base class
456 };
457
458 typedef fgTBI_instr * pTBI;
459
460 class HudLadder : public dual_instr_item {
461   private:
462     UINT   width_units;
463     int    div_units;
464     UINT   minor_div;
465     UINT   label_pos;
466     UINT   scr_hole;
467     double vmax;
468     double vmin;
469     double factor;
470
471   public:
472     HudLadder( int       x,
473                int       y,
474                UINT      width,
475                UINT      height,
476                DBLFNPTR  ptch_source    = get_roll,
477                DBLFNPTR  roll_source    = get_pitch,
478                double    span_units     = 45.0,
479                double    division_units = 10.0,
480                double    minor_division =  0.0,
481                UINT      screen_hole    =   70,
482                UINT      lbl_pos        =    0,
483                bool      working        = true );
484
485     ~HudLadder();
486
487     HudLadder( const HudLadder & image );
488     HudLadder & operator = ( const HudLadder & rhs );
489     virtual void draw( void );
490 };
491
492
493 //using namespace std;
494 //deque <instr_item>  * Hdeque_ptr;
495
496 extern void HUD_brightkey( bool incr_bright );
497 extern int  fgHUDInit( fgAIRCRAFT * /* current_aircraft */ );
498 extern int  fgHUDInit2( fgAIRCRAFT * /* current_aircraft */ );
499 extern void fgUpdateHUD( void );
500
501 extern void drawOneLine ( UINT x1, UINT y1, UINT x2, UINT y2);
502 extern void drawOneLine ( RECT &rect);
503 extern void textString  ( int x,
504                           int y,
505                           char *msg,
506                           void *font = GLUT_BITMAP_8_BY_13);
507 extern void strokeString( int x,
508                           int y,
509                           char *msg,
510                           void *font = GLUT_STROKE_ROMAN,
511                           float theta = 0);
512 /*
513 bool AddHUDInstrument( instr_item *pBlackBox );
514 void DrawHUD ( void );
515 bool DamageInstrument( INSTR_HANDLE unit );
516 bool RepairInstrument( INSTR_HANDLE unit );
517
518
519 void fgUpdateHUD ( Hptr hud );
520 void fgUpdateHUD2( Hptr hud ); // Future use?
521 void fgHUDSetTimeMode( Hptr hud, int time_of_day );
522 */
523
524 #endif // _HUD_H
525
526 // $Log$
527 // Revision 1.14  1998/09/29 14:56:33  curt
528 // c++-ified comments.
529 //
530 // Revision 1.13  1998/09/29 02:01:09  curt
531 // Added a "rate of climb" indicator.
532 //
533 // Revision 1.12  1998/08/24 20:05:17  curt
534 // Added a second minimalistic HUD.
535 // Added code to display the number of triangles rendered.
536 //
537 // Revision 1.11  1998/07/24 21:36:55  curt
538 // Ran dos2unix to get rid of extraneous ^M's.  Tweaked parameter in
539 // ImageGetRawData() to match usage.
540 //
541 // Revision 1.10  1998/07/13 21:28:02  curt
542 // Converted the aoa scale to a radio altimeter.
543 //
544 // Revision 1.9  1998/07/13 21:00:48  curt
545 // Integrated Charlies latest HUD updates.
546 // Wrote access functions for current fgOPTIONS.
547 //
548 // Revision 1.8  1998/07/03 13:16:29  curt
549 // Added Charlie Hotchkiss's HUD updates and improvementes.
550 //
551 // Revision 1.6  1998/06/03 00:43:28  curt
552 // No .h when including stl stuff.
553 //
554 // Revision 1.5  1998/05/17 16:58:13  curt
555 // Added a View Frustum Culling ratio display to the hud.
556 //
557 // Revision 1.4  1998/05/16 13:04:15  curt
558 // New updates from Charlie Hotchkiss.
559 //
560 // Revision 1.3  1998/05/13 18:27:55  curt
561 // Added an fov to hud display.
562 //
563 // Revision 1.2  1998/05/11 18:13:12  curt
564 // Complete C++ rewrite of all cockpit code by Charlie Hotchkiss.
565 //
566 // Revision 1.15  1998/02/23 19:07:57  curt
567 // Incorporated Durk's Astro/ tweaks.  Includes unifying the sun position
568 // calculation code between sun display, and other FG sections that use this
569 // for things like lighting.
570 //
571 // Revision 1.14  1998/02/21 14:53:14  curt
572 // Added Charlie's HUD changes.
573 //
574 // Revision 1.13  1998/02/20 00:16:22  curt
575 // Thursday's tweaks.
576 //
577 // Revision 1.12  1998/02/19 13:05:52  curt
578 // Incorporated some HUD tweaks from Michelle America.
579 // Tweaked the sky's sunset/rise colors.
580 // Other misc. tweaks.
581 //
582 // Revision 1.11  1998/02/16 13:38:42  curt
583 // Integrated changes from Charlie Hotchkiss.
584 //
585 // Revision 1.11  1998/02/16 13:38:42  curt
586 // Integrated changes from Charlie Hotchkiss.
587 //
588 // Revision 1.10  1998/02/12 21:59:42  curt
589 // Incorporated code changes contributed by Charlie Hotchkiss
590 // <chotchkiss@namg.us.anritsu.com>
591 //
592 // Revision 1.8  1998/02/07 15:29:35  curt
593 // Incorporated HUD changes and struct/typedef changes from Charlie Hotchkiss
594 // <chotchkiss@namg.us.anritsu.com>
595 //
596 // Revision 1.7  1998/02/03 23:20:15  curt
597 // Lots of little tweaks to fix various consistency problems discovered by
598 // Solaris' CC.  Fixed a bug in fg_debug.c with how the fgPrintf() wrapper
599 // passed arguments along to the real printf().  Also incorporated HUD changes
600 // by Michele America.
601 //
602 // Revision 1.6  1998/01/22 02:59:30  curt
603 // Changed #ifdef FILE_H to #ifdef _FILE_H
604 //
605 // Revision 1.5  1998/01/19 19:27:01  curt
606 // Merged in make system changes from Bob Kuehne <rpk@sgi.com>
607 // This should simplify things tremendously.
608 //
609 // Revision 1.4  1998/01/19 18:40:21  curt
610 // Tons of little changes to clean up the code and to remove fatal errors
611 // when building with the c++ compiler.
612 //
613 // Revision 1.3  1997/12/30 16:36:41  curt
614 // Merged in Durk's changes ...
615 //
616 // Revision 1.2  1997/12/10 22:37:40  curt
617 // Prepended "fg" on the name of all global structures that didn't have it yet.
618 // i.e. "struct WEATHER {}" became "struct fgWEATHER {}"
619 //
620 // Revision 1.1  1997/08/29 18:03:22  curt
621 // Initial revision.
622 //