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