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