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