]> git.mxchange.org Git - flightgear.git/blob - Cockpit/hud.cxx
c++-ified comments.
[flightgear.git] / Cockpit / hud.cxx
1 // hud.cxx -- hud defines and prototypes
2 //
3 // Written by Michele America, started September 1997.
4 //
5 // Copyright (C) 1997  Michele F. America  - micheleamerica@geocities.com
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 #ifdef HAVE_CONFIG_H
26 #  include <config.h>
27 #endif
28
29 #ifdef HAVE_WINDOWS_H
30 #  include <windows.h>
31 #endif
32
33 #include <GL/glut.h>
34 #include <stdlib.h>
35 #include <string.h>
36
37 #ifdef HAVE_VALUES_H
38 #  include <values.h>  // for MAXINT
39 #endif
40
41 #include <Aircraft/aircraft.h>
42 #include <Debug/fg_debug.h>
43 #include <Include/fg_constants.h>
44 #include <Main/options.hxx>
45 #include <Math/fg_random.h>
46 #include <Math/mat3.h>
47 #include <Math/polar3d.hxx>
48 #include <Scenery/scenery.hxx>
49 #include <Time/fg_timer.hxx>
50 #include <Weather/weather.h>
51
52 #if defined ( __sun__ ) || defined ( __sgi )
53 extern "C" {
54   extern void *memmove(void *, const void *, size_t);
55 }
56 #endif
57
58 #include "hud.hxx"
59
60
61
62 // The following routines obtain information concerntin the aircraft's
63 // current state and return it to calling instrument display routines.
64 // They should eventually be member functions of the aircraft.
65 //
66
67 deque< instr_item * > HUD_deque;
68
69 class locRECT {
70   public:
71     RECT rect;
72
73     locRECT( UINT left, UINT top, UINT right, UINT bottom);
74     RECT get_rect(void) { return rect;}
75 };
76
77 locRECT :: locRECT( UINT left, UINT top, UINT right, UINT bottom)
78 {
79   rect.left   =  left;
80   rect.top    =  top;
81   rect.right  =  right;
82   rect.bottom =  bottom;
83
84 }
85 // #define DEBUG
86
87 void drawOneLine( UINT x1, UINT y1, UINT x2, UINT y2)
88 {
89   glBegin(GL_LINES);
90   glVertex2f(x1, y1);
91   glVertex2f(x2, y2);
92   glEnd();
93 }
94
95 void drawOneLine( RECT &rect)
96 {
97   glBegin(GL_LINES);
98   glVertex2f(rect.left, rect.top);
99   glVertex2f(rect.right, rect.bottom);
100   glEnd();
101 }
102
103 //
104 // The following code deals with painting the "instrument" on the display
105 //
106    /* textString - Bitmap font string */
107
108 void textString( int x, int y, char *msg, void *font ){
109         glRasterPos2f(x, y);
110         while (*msg) {
111                 glutBitmapCharacter(font, *msg);
112                 msg++;
113     }
114 }
115
116 /* strokeString - Stroke font string */
117
118 void strokeString(int x, int y, char *msg, void *font, float theta)
119 {
120 int xx;
121 int yy;
122
123         glPushMatrix();
124   glRotatef(theta * RAD_TO_DEG, 0.0, 0.0, 1.0);
125   xx = (int)(x * cos(theta) + y * sin( theta ));
126   yy = (int)(y * cos(theta) - x * sin( theta ));
127         glTranslatef( xx, yy, 0);
128         glScalef(.1, .1, 0.0);
129         while (*msg) {
130                 glutStrokeCharacter(font, *msg);
131                 msg++;
132         }
133         glPopMatrix();
134 }
135
136 //========================= End of Class Implementations===================
137 // fgHUDInit
138 //
139 // Constructs a HUD object and then adds in instruments. At the present
140 // the instruments are hard coded into the routine. Ultimately these need
141 // to be defined by the aircraft's instrumentation records so that the
142 // display for a Piper Cub doesn't show the speed range of a North American
143 // mustange and the engine readouts of a B36!
144 //
145
146 #define INSTRDEFS 21
147
148 int fgHUDInit( fgAIRCRAFT * /* current_aircraft */ )
149 {
150   instr_item *HIptr;
151   int index;
152
153   fgPrintf( FG_COCKPIT, FG_INFO, "Initializing current aircraft HUD\n" );
154
155   HUD_deque.erase( HUD_deque.begin(), HUD_deque.end());  // empty the HUD deque
156
157 //  hud->code = 1;
158 //  hud->status = 0;
159
160   // For now lets just hardcode the hud here.
161   // In the future, hud information has to come from the same place
162   // aircraft information came from.
163
164 //  fgHUDSetTimeMode( hud, NIGHT );
165 //  fgHUDSetBrightness( hud, BRT_LIGHT );
166
167   index = 0;
168
169   do {
170     switch ( index ) {
171       case 0:     // TBI
172         HIptr = (instr_item *) new fgTBI_instr( 270, 100, 60, 10 );
173         break;
174
175       case 1:     // Artificial Horizon
176         HIptr = (instr_item *) new HudLadder( 240, 195, 120, 180 );
177         break;
178
179       case 2:    // KIAS
180         HIptr = (instr_item *) new hud_card( 130,
181                                              170,
182                                               28,
183                                              200,
184                                              get_speed,
185                                              HUDS_LEFT | HUDS_VERT,
186                                              200.0, 0.0,
187                                              1.0,
188                                              10,  5,
189                                              0,
190                                              0,
191                                              50.0,
192                                              true);
193
194         break;
195
196       case 3:    // Radio Altimeter
197         HIptr = (instr_item *) new hud_card( 420,
198                                              195,
199                                               25,
200                                              150,
201                                              get_agl,
202                                              HUDS_LEFT | HUDS_VERT,
203                                              1000, 0,
204                                              1.0,
205                                              25,    5,
206                                              0,
207                                              0,
208                                              200.0,
209                                              true);
210         break;
211
212       case 4:    // GYRO COMPASS
213         HIptr = (instr_item *) new hud_card( 200,
214                                              375,
215                                              200,
216                                               28,
217                                              get_heading,
218                                              HUDS_TOP,
219                                              360, 0,
220                                                1.0,
221                                                5,   1,
222                                              360,
223                                                0,
224                                               25,
225                                              true);
226         break;
227
228       case 5:    // AMSL
229         HIptr = (instr_item *) new hud_card( 460,
230                                              170,
231                                               35,
232                                              200,
233                                              get_altitude,
234                                              HUDS_RIGHT | HUDS_VERT,
235                                              15000, 0,
236                                              1.0,
237                                              100,  25,
238                                              0,
239                                              0,
240                                              250,
241                                              true);
242         break;
243
244       case 6:
245         HIptr = (instr_item *) new  guage_instr( 250,            // x
246                                                  350,            // y
247                                                  100,            // width
248                                                   20,            // height
249                                                  get_aileronval, // data source
250                                                  HUDS_BOTTOM | HUDS_NOTEXT,
251                                                  100.0,
252                                                  +1.0,
253                                                  -1.0);
254         break;
255
256       case 7:
257         HIptr = (instr_item *) new  guage_instr( 170,             // x
258                                                  225,             // y
259                                                   20,             // width
260                                                  100,             // height
261                                                  get_elevatorval, // data source
262                                                  HUDS_RIGHT | HUDS_VERT | HUDS_NOTEXT,
263                                                 -100.0,           // Scale data
264                                                   +1.0,           // Data Range
265                                                   -1.0);
266         break;
267
268       case 8:
269         HIptr = (instr_item *) new  guage_instr( 250,             // x
270                                                  200,             // y
271                                                  100,             // width
272                                                   20,             // height
273                                                  get_rudderval,   // data source
274                                                  HUDS_TOP | HUDS_NOTEXT,
275                                                  100.0,
276                                                  +1.0,
277                                                  -1.0);
278         break;
279
280       case 9:
281         HIptr = (instr_item *) new  guage_instr( 100,             // x
282                                                  190,
283                                                   20,
284                                                  160,             // height
285                                                  get_throttleval, // data source
286                                                  HUDS_VERT | HUDS_RIGHT | HUDS_NOTEXT,
287                                                  100.0,
288                                                    1.0,
289                                                    0.0);
290         break;
291
292       case 10:    // Digital KIAS
293         HIptr = (instr_item *) new instr_label ( 110,
294                                                  150,
295                                                   40,
296                                                   30,
297                                                  get_speed,
298                                                  "%5.0f",
299                                                  NULL,
300                                                  " Kts",
301                                                  1.0,
302                                                  HUDS_TOP,
303                                                  RIGHT_JUST,
304                                                  SMALL,
305                                                  0,
306                                                  TRUE );
307         break;
308
309       case 11:    // Digital Rate of Climb
310         HIptr = (instr_item *) new instr_label ( 110,
311                                                  135,
312                                                   40,
313                                                   10,
314                                                  get_climb_rate,
315                                                  "%5.0f",
316                                                  " Climb",
317                                                  NULL,
318                                                  1.0,
319                                                  HUDS_TOP,
320                                                  RIGHT_JUST,
321                                                  SMALL,
322                                                  0,
323                                                  TRUE );
324         break;
325
326       case 12:    // Roll indication diagnostic
327         HIptr = (instr_item *) new instr_label ( 110,
328                                                  120,
329                                                   40,
330                                                   10,
331                                                  get_roll,
332                                                  "%5.2f",
333                                                  " Roll",
334                                                  " Deg",
335                                                  1.0,
336                                                  HUDS_TOP,
337                                                  RIGHT_JUST,
338                                                  SMALL,
339                                                  0,
340                                                  TRUE );
341         break;
342
343       case 13:    // Angle of attack diagnostic
344         HIptr = (instr_item *) new instr_label ( 440,
345                                                  150,
346                                                   60,
347                                                   10,
348                                                  get_aoa,
349                                                  "      %5.2f",
350                                                  "AOA",
351                                                  " Deg",
352                                                  1.0,
353                                                  HUDS_TOP,
354                                                  RIGHT_JUST,
355                                                  SMALL,
356                                                  0,
357                                                  TRUE );
358         break;
359
360       case 14:
361         HIptr = (instr_item *) new instr_label ( 440,
362                                                  135,
363                                                   60,
364                                                   10,
365                                                  get_heading,
366                                                  " %5.1f",
367                                                  "Heading ",
368                                                  " Deg",
369                                                  1.0,
370                                                  HUDS_TOP,
371                                                  RIGHT_JUST,
372                                                  SMALL,
373                                                  0,
374                                                  TRUE );
375         break;
376
377       case 15:
378         HIptr = (instr_item *) new instr_label ( 440,
379                                                  120,
380                                                   60,
381                                                   10,
382                                                  get_sideslip,
383                                                  "%5.2f",
384                                                  "Sideslip ",
385                                                  NULL,
386                                                  1.0,
387                                                  HUDS_TOP,
388                                                  RIGHT_JUST,
389                                                  SMALL,
390                                                  0,
391                                                  TRUE );
392         break;
393
394       case 16:
395         HIptr = (instr_item *) new instr_label( 440,
396                                                 100,
397                                                  60,
398                                                  10,
399                                                 get_throttleval,
400                                                 "%5.2f",
401                                                 "Throttle ",
402                                                 NULL,
403                                                  1.0,
404                                                 HUDS_TOP,
405                                                 RIGHT_JUST,
406                                                 SMALL,
407                                                 0,
408                                                 TRUE );
409         break;
410
411       case 17:
412         HIptr = (instr_item *) new instr_label( 440,
413                                                  85,
414                                                  60,
415                                                  10,
416                                                 get_elevatorval,
417                                                 "%5.2f",
418                                                 "Elevator ",
419                                                 NULL,
420                                                  1.0,
421                                                 HUDS_TOP,
422                                                 RIGHT_JUST,
423                                                 SMALL,
424                                                 0,
425                                                 TRUE );
426         break;
427
428       case 18:
429         HIptr = (instr_item *) new instr_label( 440,
430                                                  60,
431                                                  60,
432                                                  10,
433                                                 get_aileronval,
434                                                 "%5.2f",
435                                                 "Aileron  ",
436                                                 NULL,
437                                                  1.0,
438                                                 HUDS_TOP,
439                                                 RIGHT_JUST,
440                                                 SMALL,
441                                                 0,
442                                                 TRUE );
443         break;
444
445
446       case 19:
447         HIptr = (instr_item *) new instr_label( 10,
448                                                 10,
449                                                 60,
450                                                 10,
451                                                  get_frame_rate,
452                                                 "%.1f",
453                                                 "Frame rate = ",
454                                                 NULL,
455                                                  1.0,
456                                                 HUDS_TOP,
457                                                 RIGHT_JUST,
458                                                 SMALL,
459                                                 0,
460                                                 TRUE );
461         break;
462
463       case 20:
464           switch( current_options.get_tris_or_culled() ) {
465           case 0:
466               HIptr = (instr_item *) new instr_label( 10,
467                                                       25,
468                                                       90,
469                                                       10,
470                                                       get_vfc_tris_drawn,
471                                                       "%.0f",
472                                                       "Tris Rendered = ",
473                                                       NULL,
474                                                       1.0,
475                                                       HUDS_TOP,
476                                                       RIGHT_JUST,
477                                                       SMALL,
478                                                       0,
479                                                       TRUE );
480               break;
481           case 1:
482               HIptr = (instr_item *) new instr_label( 10,
483                                                       25,
484                                                       90,
485                                                       10,
486                                                       get_vfc_ratio,
487                                                       "%.2f",
488                                                       "VFC Ratio = ",
489                                                       NULL,
490                                                       1.0,
491                                                       HUDS_TOP,
492                                                       RIGHT_JUST,
493                                                       SMALL,
494                                                       0,
495                                                       TRUE );
496               break;
497           }
498           break;
499
500       case 21:
501         HIptr = (instr_item *) new instr_label( 10,
502                                                 40,
503                                                 90,
504                                                 10,
505                                                 get_fov,
506                                                 "%.1f",
507                                                 "FOV = ",
508                                                 NULL,
509                                                 1.0,
510                                                 HUDS_TOP,
511                                                 RIGHT_JUST,
512                                                 SMALL,
513                                                 0,
514                                                 TRUE );
515         break;
516
517       default:
518         HIptr = 0;;
519       }
520     if( HIptr ) {                   // Anything to install?
521       HUD_deque.insert( HUD_deque.begin(), HIptr);
522       }
523     index++;
524     }
525   while( HIptr );
526
527   return 0;  // For now. Later we may use this for an error code.
528 }
529
530 int fgHUDInit2( fgAIRCRAFT * /* current_aircraft */ )
531 {
532   instr_item *HIptr;
533   int index;
534
535   fgPrintf( FG_COCKPIT, FG_INFO, "Initializing current aircraft HUD\n" );
536
537   HUD_deque.erase( HUD_deque.begin(), HUD_deque.end());  // empty the HUD deque
538
539 //  hud->code = 1;
540 //  hud->status = 0;
541
542   // For now lets just hardcode the hud here.
543   // In the future, hud information has to come from the same place
544   // aircraft information came from.
545
546 //  fgHUDSetTimeMode( hud, NIGHT );
547 //  fgHUDSetBrightness( hud, BRT_LIGHT );
548
549 //  index = 0;
550   index = 19;  
551
552   do {
553     switch ( index ) {
554       case 0:     // TBI
555         HIptr = (instr_item *) new fgTBI_instr( 270, 100, 60, 10 );
556         break;
557
558       case 1:     // Artificial Horizon
559         HIptr = (instr_item *) new HudLadder( 240, 195, 120, 180 );
560         break;
561
562       case 2:    // KIAS
563         HIptr = (instr_item *) new hud_card( 130,
564                                              170,
565                                               28,
566                                              200,
567                                              get_speed,
568                                              HUDS_LEFT | HUDS_VERT,
569                                              200.0, 0.0,
570                                              1.0,
571                                              10,  5,
572                                              0,
573                                              0,
574                                              50.0,
575                                              true);
576
577         break;
578
579       case 3:    // Radio Altimeter
580         HIptr = (instr_item *) new hud_card( 420,
581                                              195,
582                                               25,
583                                              150,
584                                              get_agl,
585                                              HUDS_LEFT | HUDS_VERT,
586                                              1000, 0,
587                                              1.0,
588                                              25,    5,
589                                              0,
590                                              0,
591                                              200.0,
592                                              true);
593         break;
594
595       case 4:    // GYRO COMPASS
596         HIptr = (instr_item *) new hud_card( 200,
597                                              375,
598                                              200,
599                                               28,
600                                              get_heading,
601                                              HUDS_TOP,
602                                              360, 0,
603                                                1.0,
604                                                5,   1,
605                                              360,
606                                                0,
607                                               25,
608                                              true);
609         break;
610
611       case 5:    // AMSL
612         HIptr = (instr_item *) new hud_card( 460,
613                                              170,
614                                               35,
615                                              200,
616                                              get_altitude,
617                                              HUDS_RIGHT | HUDS_VERT,
618                                              15000, 0,
619                                              1.0,
620                                              100,  25,
621                                              0,
622                                              0,
623                                              250,
624                                              true);
625         break;
626
627       case 6:
628         HIptr = (instr_item *) new  guage_instr( 250,            // x
629                                                  350,            // y
630                                                  100,            // width
631                                                   20,            // height
632                                                  get_aileronval, // data source
633                                                  HUDS_BOTTOM | HUDS_NOTEXT,
634                                                  100.0,
635                                                  +1.0,
636                                                  -1.0);
637         break;
638
639       case 7:
640         HIptr = (instr_item *) new  guage_instr( 170,             // x
641                                                  225,             // y
642                                                   20,             // width
643                                                  100,             // height
644                                                  get_elevatorval, // data source
645                                                  HUDS_RIGHT | HUDS_VERT | HUDS_NOTEXT,
646                                                 -100.0,           // Scale data
647                                                   +1.0,           // Data Range
648                                                   -1.0);
649         break;
650
651       case 8:
652         HIptr = (instr_item *) new  guage_instr( 250,             // x
653                                                  200,             // y
654                                                  100,             // width
655                                                   20,             // height
656                                                  get_rudderval,   // data source
657                                                  HUDS_TOP | HUDS_NOTEXT,
658                                                  100.0,
659                                                  +1.0,
660                                                  -1.0);
661         break;
662
663       case 9:
664         HIptr = (instr_item *) new  guage_instr( 100,             // x
665                                                  190,
666                                                   20,
667                                                  160,             // height
668                                                  get_throttleval, // data source
669                                                  HUDS_VERT | HUDS_RIGHT | HUDS_NOTEXT,
670                                                  100.0,
671                                                    1.0,
672                                                    0.0);
673         break;
674
675       case 10:    // Digital KIAS
676         HIptr = (instr_item *) new instr_label ( 110,
677                                                  150,
678                                                   40,
679                                                   30,
680                                                  get_speed,
681                                                  "%5.0f",
682                                                  NULL,
683                                                  " Kts",
684                                                  1.0,
685                                                  HUDS_TOP,
686                                                  RIGHT_JUST,
687                                                  SMALL,
688                                                  0,
689                                                  TRUE );
690         break;
691
692       case 11:    // Digital Rate of Climb
693         HIptr = (instr_item *) new instr_label ( 110,
694                                                  135,
695                                                   40,
696                                                   10,
697                                                  get_altitude,
698                                                  "Climb  %5.0f",
699                                                  NULL,
700                                                  " m",
701                                                  1.0,
702                                                  HUDS_TOP,
703                                                  LEFT_JUST,
704                                                  SMALL,
705                                                  0,
706                                                  TRUE );
707         break;
708
709       case 12:    // Roll indication diagnostic
710         HIptr = (instr_item *) new instr_label ( 110,
711                                                  120,
712                                                   40,
713                                                   10,
714                                                  get_roll,
715                                                  "%5.2f",
716                                                  " Roll",
717                                                  " Deg",
718                                                  1.0,
719                                                  HUDS_TOP,
720                                                  RIGHT_JUST,
721                                                  SMALL,
722                                                  0,
723                                                  TRUE );
724         break;
725
726       case 13:    // Angle of attack diagnostic
727         HIptr = (instr_item *) new instr_label ( 440,
728                                                  150,
729                                                   60,
730                                                   10,
731                                                  get_aoa,
732                                                  "      %5.2f",
733                                                  "AOA",
734                                                  " Deg",
735                                                  1.0,
736                                                  HUDS_TOP,
737                                                  RIGHT_JUST,
738                                                  SMALL,
739                                                  0,
740                                                  TRUE );
741         break;
742
743       case 14:
744         HIptr = (instr_item *) new instr_label ( 440,
745                                                  135,
746                                                   60,
747                                                   10,
748                                                  get_heading,
749                                                  " %5.1f",
750                                                  "Heading ",
751                                                  " Deg",
752                                                  1.0,
753                                                  HUDS_TOP,
754                                                  RIGHT_JUST,
755                                                  SMALL,
756                                                  0,
757                                                  TRUE );
758         break;
759
760       case 15:
761         HIptr = (instr_item *) new instr_label ( 440,
762                                                  120,
763                                                   60,
764                                                   10,
765                                                  get_sideslip,
766                                                  "%5.2f",
767                                                  "Sideslip ",
768                                                  NULL,
769                                                  1.0,
770                                                  HUDS_TOP,
771                                                  RIGHT_JUST,
772                                                  SMALL,
773                                                  0,
774                                                  TRUE );
775         break;
776
777       case 16:
778         HIptr = (instr_item *) new instr_label( 440,
779                                                 100,
780                                                  60,
781                                                  10,
782                                                 get_throttleval,
783                                                 "%5.2f",
784                                                 "Throttle ",
785                                                 NULL,
786                                                  1.0,
787                                                 HUDS_TOP,
788                                                 RIGHT_JUST,
789                                                 SMALL,
790                                                 0,
791                                                 TRUE );
792         break;
793
794       case 17:
795         HIptr = (instr_item *) new instr_label( 440,
796                                                  85,
797                                                  60,
798                                                  10,
799                                                 get_elevatorval,
800                                                 "%5.2f",
801                                                 "Elevator ",
802                                                 NULL,
803                                                  1.0,
804                                                 HUDS_TOP,
805                                                 RIGHT_JUST,
806                                                 SMALL,
807                                                 0,
808                                                 TRUE );
809         break;
810
811       case 18:
812         HIptr = (instr_item *) new instr_label( 440,
813                                                  60,
814                                                  60,
815                                                  10,
816                                                 get_aileronval,
817                                                 "%5.2f",
818                                                 "Aileron  ",
819                                                 NULL,
820                                                  1.0,
821                                                 HUDS_TOP,
822                                                 RIGHT_JUST,
823                                                 SMALL,
824                                                 0,
825                                                 TRUE );
826         break;
827
828
829       case 19:
830         HIptr = (instr_item *) new instr_label( 10,
831                                                 10,
832                                                 60,
833                                                 10,
834                                                  get_frame_rate,
835                                                 "%.1f",
836                                                 "Frame rate = ",
837                                                 NULL,
838                                                  1.0,
839                                                 HUDS_TOP,
840                                                 RIGHT_JUST,
841                                                 SMALL,
842                                                 0,
843                                                 TRUE );
844         break;
845
846       case 20:
847                   switch( current_options.get_tris_or_culled() ) {
848                           case 0:
849                                   HIptr = (instr_item *) new instr_label( 10,
850                                           25,
851                                           90,
852                                           10,
853                                           get_vfc_tris_drawn,                                                                                           
854                                           "%.0f",
855                                           "Tris Rendered = ",
856                                           NULL,
857                                           1.0,
858                                           HUDS_TOP,
859                                           RIGHT_JUST,
860                                           SMALL,
861                                           0,
862                                           TRUE );
863                                   break;
864                           case 1:
865                                   HIptr = (instr_item *) new instr_label( 10,
866                                           25,
867                                           90,
868                                           10,
869                                           get_vfc_ratio,
870                                           "%.2f",
871                                           "VFC Ratio = ",
872                                           NULL,
873                                           1.0,
874                                           HUDS_TOP,
875                                           RIGHT_JUST,
876                                           SMALL,
877                                           0,
878                                           TRUE );
879                                   break;
880                   }
881                   break;
882                 
883       case 21:
884         HIptr = (instr_item *) new instr_label( 10,
885                                                 40,
886                                                 90,
887                                                 10,
888                                                 get_fov,
889                                                 "%.1f",
890                                                 "FOV = ",
891                                                 NULL,
892                                                  1.0,
893                                                 HUDS_TOP,
894                                                 RIGHT_JUST,
895                                                 SMALL,
896                                                 0,
897                                                 TRUE );
898         break;
899
900       default:
901         HIptr = 0;;
902       }
903     if( HIptr ) {                   // Anything to install?
904       HUD_deque.insert( HUD_deque.begin(), HIptr);
905       }
906     index++;
907     }
908   while( HIptr );
909
910   return 0;  // For now. Later we may use this for an error code.
911 }
912
913 int global_day_night_switch = DAY;
914
915 void HUD_brightkey( bool incr_bright )
916 {
917 instr_item *pHUDInstr = HUD_deque[0];
918 int brightness        = pHUDInstr->get_brightness();
919
920   if( current_options.get_hud_status() ) {
921     if( incr_bright ) {
922       switch (brightness) {
923         case BRT_LIGHT:
924               current_options.set_hud_status(0);
925           break;
926
927         case BRT_MEDIUM:
928           brightness = BRT_LIGHT;
929           break;
930
931         case BRT_DARK:
932           brightness = BRT_MEDIUM;
933           break;
934
935         case BRT_BLACK:
936           brightness = BRT_DARK;
937           break;
938
939         default:
940           brightness = BRT_BLACK;
941         }
942       }
943     else {
944       switch (brightness) {
945         case BRT_LIGHT:
946           brightness = BRT_MEDIUM;
947           break;
948
949         case BRT_MEDIUM:
950           brightness = BRT_DARK;
951           break;
952
953         case BRT_DARK:
954           brightness = BRT_BLACK;
955           break;
956
957         case BRT_BLACK:
958         default:
959               current_options.set_hud_status(0);
960         }
961       }
962     }
963   else {
964     current_options.set_hud_status(1);
965     if( incr_bright ) {
966       if( DAY == global_day_night_switch ) {
967         brightness = BRT_BLACK;
968         }
969       else {
970         brightness = BRT_DARK;
971         global_day_night_switch = DAY;
972         }
973       }
974     else {
975       if( NIGHT == global_day_night_switch ) {
976         brightness = BRT_DARK;
977         }
978       else {
979         brightness = BRT_MEDIUM;
980         global_day_night_switch = NIGHT;
981         }
982       }
983     }
984   pHUDInstr->SetBrightness( brightness );
985 }
986
987 // fgUpdateHUD
988 //
989 // Performs a once around the list of calls to instruments installed in
990 // the HUD object with requests for redraw. Kinda. It will when this is
991 // all C++.
992 //
993 void fgUpdateHUD( void ) {
994   int i;
995   int brightness;
996 //  int day_night_sw = current_aircraft.controls->day_night_switch;
997   int day_night_sw = global_day_night_switch;
998   int hud_displays = HUD_deque.size();
999   instr_item *pHUDInstr;
1000
1001   if( !hud_displays ) {  // Trust everyone, but ALWAYS cut the cards!
1002     return;
1003     }
1004
1005   pHUDInstr = HUD_deque[0];
1006   brightness = pHUDInstr->get_brightness();
1007 //  brightness = HUD_deque.at(0)->get_brightness();
1008
1009   glMatrixMode(GL_PROJECTION);
1010   glPushMatrix();
1011
1012   glLoadIdentity();
1013   gluOrtho2D(0, 640, 0, 480);
1014   glMatrixMode(GL_MODELVIEW);
1015   glPushMatrix();
1016   glLoadIdentity();
1017
1018   glColor3f(1.0, 1.0, 1.0);
1019   glIndexi(7);
1020
1021   glDisable(GL_DEPTH_TEST);
1022   glDisable(GL_LIGHTING);
1023
1024   glLineWidth(1);
1025
1026   deque < instr_item * > :: iterator current;
1027   deque < instr_item * > :: iterator last;
1028
1029   current = HUD_deque.begin();
1030   last = HUD_deque.end();
1031   while ( current != last ) {
1032     pHUDInstr = *current;
1033     current++;
1034
1035     // for( i = hud_displays; i; --i) { // Draw everything
1036     // if( HUD_deque.at(i)->enabled()) {
1037     // pHUDInstr = HUD_deque[i - 1];
1038     if( pHUDInstr->enabled()) {
1039                                    // We should to respond to a dial instead
1040                                    // or as well to the of time of day. Of
1041                                    // course, we have no dial!
1042       if( day_night_sw == DAY) {
1043         switch (brightness) {
1044           case BRT_LIGHT:
1045             glColor3f (0.1, 0.9, 0.1);
1046             break;
1047
1048           case BRT_MEDIUM:
1049             glColor3f (0.1, 0.7, 0.0);
1050             break;
1051
1052           case BRT_DARK:
1053             glColor3f (0.0, 0.5, 0.0);
1054             break;
1055
1056           case BRT_BLACK:
1057             glColor3f( 0.0, 0.0, 0.0);
1058             break;
1059
1060           default:;
1061             }
1062           }
1063         else {
1064           if( day_night_sw == NIGHT) {
1065             switch (brightness) {
1066               case BRT_LIGHT:
1067                 glColor3f (0.9, 0.1, 0.1);
1068                 break;
1069
1070               case BRT_MEDIUM:
1071                 glColor3f (0.7, 0.0, 0.1);
1072                 break;
1073
1074               case BRT_DARK:
1075               default:
1076                 glColor3f (0.5, 0.0, 0.0);
1077               }
1078             }
1079           else {     // Just in case default
1080             glColor3f (0.1, 0.9, 0.1);
1081             }
1082           }
1083     //  fgPrintf( FG_COCKPIT, FG_DEBUG, "HUD Code %d  Status %d\n",
1084     //            hud->code, hud->status );
1085       pHUDInstr->draw();
1086 //      HUD_deque.at(i)->draw(); // Responsible for broken or fixed variants.
1087                               // No broken displays honored just now.
1088       }
1089     }
1090
1091   glEnable(GL_DEPTH_TEST);
1092   glEnable(GL_LIGHTING);
1093   glMatrixMode(GL_PROJECTION);
1094   glPopMatrix();
1095   glMatrixMode(GL_MODELVIEW);
1096   glPopMatrix();
1097 }
1098
1099 // $Log$
1100 // Revision 1.22  1998/09/29 14:56:31  curt
1101 // c++-ified comments.
1102 //
1103 // Revision 1.21  1998/09/29 02:01:07  curt
1104 // Added a "rate of climb" indicator.
1105 //
1106 // Revision 1.20  1998/08/24 20:05:16  curt
1107 // Added a second minimalistic HUD.
1108 // Added code to display the number of triangles rendered.
1109 //
1110 // Revision 1.19  1998/07/30 23:44:05  curt
1111 // Tweaks for sgi building.
1112 //
1113 // Revision 1.18  1998/07/20 12:47:55  curt
1114 // Replace the hud rendering for loop (which linearly searches the the hud
1115 // list to find the entry with the proper position) with a simple linear
1116 // traversal using an "iterator."
1117 //
1118 // Revision 1.17  1998/07/13 21:28:02  curt
1119 // Converted the aoa scale to a radio altimeter.
1120 //
1121 // Revision 1.16  1998/07/13 21:00:47  curt
1122 // Integrated Charlies latest HUD updates.
1123 // Wrote access functions for current fgOPTIONS.
1124 //
1125 // Revision 1.15  1998/07/08 14:41:08  curt
1126 // Renamed polar3d.h to polar3d.hxx
1127 //
1128 // Revision 1.14  1998/07/06 21:31:20  curt
1129 // Removed an extraneous ^M.
1130 //
1131 // Revision 1.13  1998/07/03 13:16:28  curt
1132 // Added Charlie Hotchkiss's HUD updates and improvementes.
1133 //
1134 // Revision 1.11  1998/06/05 18:17:10  curt
1135 // Added the declaration of memmove needed by the stl which apparently
1136 // solaris only defines for cc compilations and not for c++ (__STDC__)
1137 //
1138 // Revision 1.10  1998/05/17 16:58:12  curt
1139 // Added a View Frustum Culling ratio display to the hud.
1140 //
1141 // Revision 1.9  1998/05/16 13:04:14  curt
1142 // New updates from Charlie Hotchkiss.
1143 //
1144 // Revision 1.8  1998/05/13 18:27:54  curt
1145 // Added an fov to hud display.
1146 //
1147 // Revision 1.7  1998/05/11 18:13:11  curt
1148 // Complete C++ rewrite of all cockpit code by Charlie Hotchkiss.
1149 //
1150 // Revision 1.22  1998/04/18 04:14:02  curt
1151 // Moved fg_debug.c to it's own library.
1152 //
1153 // Revision 1.21  1998/04/03 21:55:28  curt
1154 // Converting to Gnu autoconf system.
1155 // Tweaks to hud.c
1156 //
1157 // Revision 1.20  1998/03/09 22:48:40  curt
1158 // Minor "formatting" tweaks.
1159 //
1160 // Revision 1.19  1998/02/23 20:18:28  curt
1161 // Incorporated Michele America's hud changes.
1162 //
1163 // Revision 1.18  1998/02/21 14:53:10  curt
1164 // Added Charlie's HUD changes.
1165 //
1166 // Revision 1.17  1998/02/20 00:16:21  curt
1167 // Thursday's tweaks.
1168 //
1169 // Revision 1.16  1998/02/19 13:05:49  curt
1170 // Incorporated some HUD tweaks from Michelle America.
1171 // Tweaked the sky's sunset/rise colors.
1172 // Other misc. tweaks.
1173 //
1174 // Revision 1.15  1998/02/16 13:38:39  curt
1175 // Integrated changes from Charlie Hotchkiss.
1176 //
1177 // Revision 1.14  1998/02/12 21:59:41  curt
1178 // Incorporated code changes contributed by Charlie Hotchkiss
1179 // <chotchkiss@namg.us.anritsu.com>
1180 //
1181 // Revision 1.12  1998/02/09 15:07:48  curt
1182 // Minor tweaks.
1183 //
1184 // Revision 1.11  1998/02/07 15:29:34  curt
1185 // Incorporated HUD changes and struct/typedef changes from Charlie Hotchkiss
1186 // <chotchkiss@namg.us.anritsu.com>
1187 //
1188 // Revision 1.10  1998/02/03 23:20:14  curt
1189 // Lots of little tweaks to fix various consistency problems discovered by
1190 // Solaris' CC.  Fixed a bug in fg_debug.c with how the fgPrintf() wrapper
1191 // passed arguments along to the real printf().  Also incorporated HUD changes
1192 // by Michele America.
1193 //
1194 // Revision 1.9  1998/01/31 00:43:04  curt
1195 // Added MetroWorks patches from Carmen Volpe.
1196 //
1197 // Revision 1.8  1998/01/27 00:47:51  curt
1198 // Incorporated Paul Bleisch's <bleisch@chromatic.com> new debug message
1199 // system and commandline/config file processing code.
1200 //
1201 // Revision 1.7  1998/01/19 18:40:20  curt
1202 // Tons of little changes to clean up the code and to remove fatal errors
1203 // when building with the c++ compiler.
1204 //
1205 // Revision 1.6  1997/12/15 23:54:34  curt
1206 // Add xgl wrappers for debugging.
1207 // Generate terrain normals on the fly.
1208 //
1209 // Revision 1.5  1997/12/10 22:37:39  curt
1210 // Prepended "fg" on the name of all global structures that didn't have it yet.
1211 // i.e. "struct WEATHER {}" became "struct fgWEATHER {}"
1212 //
1213 // Revision 1.4  1997/09/23 00:29:32  curt
1214 // Tweaks to get things to compile with gcc-win32.
1215 //
1216 // Revision 1.3  1997/09/05 14:17:26  curt
1217 // More tweaking with stars.
1218 //
1219 // Revision 1.2  1997/09/04 02:17:30  curt
1220 // Shufflin' stuff.
1221 //
1222 // Revision 1.1  1997/08/29 18:03:22  curt
1223 // Initial revision.
1224 //