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