1 /**************************************************************************
2 * hud.cxx -- hud defines and prototypes
4 * Written by Michele America, started September 1997.
6 * Copyright (C) 1997 Michele F. America - micheleamerica@geocities.com
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.
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.
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.
23 * (Log is kept at end of this file)
24 **************************************************************************/
40 # include <values.h> // for MAXINT
43 #include <Aircraft/aircraft.h>
44 #include <Debug/fg_debug.h>
45 #include <Include/fg_constants.h>
46 #include <Math/fg_random.h>
47 #include <Math/mat3.h>
48 #include <Math/polar3d.hxx>
49 #include <Scenery/scenery.hxx>
50 #include <Time/fg_timer.hxx>
51 #include <Weather/weather.h>
57 extern void *memmove(void *, const void *, size_t);
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.
67 deque< instr_item * > HUD_deque;
73 locRECT( UINT left, UINT top, UINT right, UINT bottom);
74 RECT get_rect(void) { return rect;}
77 locRECT :: locRECT( UINT left, UINT top, UINT right, UINT bottom)
87 void drawOneLine( UINT x1, UINT y1, UINT x2, UINT y2)
95 void drawOneLine( RECT &rect)
98 glVertex2f(rect.left, rect.top);
99 glVertex2f(rect.right, rect.bottom);
104 // The following code deals with painting the "instrument" on the display
106 /* textString - Bitmap font string */
108 void textString( int x, int y, char *msg, void *font ){
111 glutBitmapCharacter(font, *msg);
116 /* strokeString - Stroke font string */
118 void strokeString(int x, int y, char *msg, void *font, float theta)
124 glRotatef(theta * RAD_TO_DEG, 0.0, 0.0, 1.0);
125 xx = x * cos(theta) + y * sin( theta );
126 yy = y * cos(theta) - x * sin( theta );
127 glTranslatef( xx, yy, 0);
128 glScalef(.1, .1, 0.0);
130 glutStrokeCharacter(font, *msg);
136 //========================= End of Class Implementations===================
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!
148 int fgHUDInit( fgAIRCRAFT * /* current_aircraft */ )
153 fgPrintf( FG_COCKPIT, FG_INFO, "Initializing current aircraft HUD\n" );
155 HUD_deque.erase( HUD_deque.begin(), HUD_deque.end()); // empty the HUD deque
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.
164 // fgHUDSetTimeMode( hud, NIGHT );
165 // fgHUDSetBrightness( hud, BRT_LIGHT );
172 HIptr = (instr_item *) new fgTBI_instr( 300, 100, 60, 10 );
175 case 1: // Artificial Horizon
176 HIptr = (instr_item *) new HudLadder( 270, 195, 120, 180 );
180 HIptr = (instr_item *) new hud_card( 160,
185 HUDS_LEFT | HUDS_VERT,
196 case 3: // Angle of Attack
197 HIptr = (instr_item *) new hud_card( 450,
202 HUDS_LEFT | HUDS_VERT,
212 case 4: // GYRO COMPASS
213 HIptr = (instr_item *) new hud_card( 200,
229 HIptr = (instr_item *) new hud_card( 490,
234 HUDS_RIGHT | HUDS_VERT,
244 case 6: // Digital KIAS
245 HIptr = (instr_item *) new instr_label ( 160,
260 case 7: // Digital Altimeter
261 HIptr = (instr_item *) new instr_label ( 160,
276 case 8: // Roll indication diagnostic
277 HIptr = (instr_item *) new instr_label ( 160,
292 case 9: // Angle of attack diagnostic
293 HIptr = (instr_item *) new instr_label ( 440,
309 HIptr = (instr_item *) new instr_label ( 440,
325 HIptr = (instr_item *) new instr_label ( 440,
341 HIptr = (instr_item *) new instr_label( 440,
357 HIptr = (instr_item *) new instr_label( 440,
373 HIptr = (instr_item *) new instr_label( 440,
390 HIptr = (instr_item *) new instr_label( 10,
406 HIptr = (instr_item *) new instr_label( 10,
422 HIptr = (instr_item *) new instr_label( 10,
437 HIptr = (instr_item *) new guage_instr( 50, // x
441 get_aileronval, // data source
449 HIptr = (instr_item *) new guage_instr( 90, // x
453 get_elevatorval, // data source
454 HUDS_BOTH | HUDS_VERT,
461 HIptr = (instr_item *) new guage_instr( 50, // x
465 get_rudderval, // data source
475 if( HIptr ) { // Anything to install?
476 HUD_deque.insert( HUD_deque.begin(), HIptr);
482 return 0; // For now. Later we may use this for an error code.
488 // Performs a once around the list of calls to instruments installed in
489 // the HUD object with requests for redraw. Kinda. It will when this is
492 int global_day_night_switch = DAY;
494 void fgUpdateHUD( void ) {
497 // int day_night_sw = current_aircraft.controls->day_night_switch;
498 int day_night_sw = global_day_night_switch;
499 int hud_displays = HUD_deque.size();
500 instr_item *pHUDInstr;
502 if( !hud_displays ) { // Trust everyone, but ALWAYS cut the cards!
506 pHUDInstr = HUD_deque[0];
507 brightness = pHUDInstr->get_brightness();
508 // brightness = HUD_deque.at(0)->get_brightness();
510 glMatrixMode(GL_PROJECTION);
514 gluOrtho2D(0, 640, 0, 480);
515 glMatrixMode(GL_MODELVIEW);
519 glColor3f(1.0, 1.0, 1.0);
522 glDisable(GL_DEPTH_TEST);
523 glDisable(GL_LIGHTING);
527 for( i = hud_displays; i; --i) { // Draw everything
528 // if( HUD_deque.at(i)->enabled()) {
529 pHUDInstr = HUD_deque[i - 1];
530 if( pHUDInstr->enabled()) {
531 // We should to respond to a dial instead
532 // or as well to the of time of day. Of
533 // course, we have no dial!
534 if( day_night_sw == DAY) {
535 switch (brightness) {
537 glColor3f (0.1, 0.9, 0.1);
541 glColor3f (0.1, 0.7, 0.0);
545 glColor3f (0.0, 0.5, 0.0);
549 if( day_night_sw == NIGHT) {
550 switch (brightness) {
552 glColor3f (0.9, 0.1, 0.1);
556 glColor3f (0.7, 0.0, 0.1);
561 glColor3f (0.5, 0.0, 0.0);
564 else { // Just in case default
565 glColor3f (0.1, 0.9, 0.1);
568 // fgPrintf( FG_COCKPIT, FG_DEBUG, "HUD Code %d Status %d\n",
569 // hud->code, hud->status );
571 // HUD_deque.at(i)->draw(); // Responsible for broken or fixed variants.
572 // No broken displays honored just now.
576 glEnable(GL_DEPTH_TEST);
577 glEnable(GL_LIGHTING);
578 glMatrixMode(GL_PROJECTION);
580 glMatrixMode(GL_MODELVIEW);
585 /* Revision 1.15 1998/07/08 14:41:08 curt
586 /* Renamed polar3d.h to polar3d.hxx
588 * Revision 1.14 1998/07/06 21:31:20 curt
589 * Removed an extraneous ^M.
591 * Revision 1.13 1998/07/03 13:16:28 curt
592 * Added Charlie Hotchkiss's HUD updates and improvementes.
594 * Revision 1.11 1998/06/05 18:17:10 curt
595 * Added the declaration of memmove needed by the stl which apparently
596 * solaris only defines for cc compilations and not for c++ (__STDC__)
598 * Revision 1.10 1998/05/17 16:58:12 curt
599 * Added a View Frustum Culling ratio display to the hud.
601 * Revision 1.9 1998/05/16 13:04:14 curt
602 * New updates from Charlie Hotchkiss.
604 * Revision 1.8 1998/05/13 18:27:54 curt
605 * Added an fov to hud display.
607 * Revision 1.7 1998/05/11 18:13:11 curt
608 * Complete C++ rewrite of all cockpit code by Charlie Hotchkiss.
610 * Revision 1.22 1998/04/18 04:14:02 curt
611 * Moved fg_debug.c to it's own library.
613 * Revision 1.21 1998/04/03 21:55:28 curt
614 * Converting to Gnu autoconf system.
617 * Revision 1.20 1998/03/09 22:48:40 curt
618 * Minor "formatting" tweaks.
620 * Revision 1.19 1998/02/23 20:18:28 curt
621 * Incorporated Michele America's hud changes.
623 * Revision 1.18 1998/02/21 14:53:10 curt
624 * Added Charlie's HUD changes.
626 * Revision 1.17 1998/02/20 00:16:21 curt
629 * Revision 1.16 1998/02/19 13:05:49 curt
630 * Incorporated some HUD tweaks from Michelle America.
631 * Tweaked the sky's sunset/rise colors.
632 * Other misc. tweaks.
634 * Revision 1.15 1998/02/16 13:38:39 curt
635 * Integrated changes from Charlie Hotchkiss.
637 * Revision 1.14 1998/02/12 21:59:41 curt
638 * Incorporated code changes contributed by Charlie Hotchkiss
639 * <chotchkiss@namg.us.anritsu.com>
641 * Revision 1.12 1998/02/09 15:07:48 curt
644 * Revision 1.11 1998/02/07 15:29:34 curt
645 * Incorporated HUD changes and struct/typedef changes from Charlie Hotchkiss
646 * <chotchkiss@namg.us.anritsu.com>
648 * Revision 1.10 1998/02/03 23:20:14 curt
649 * Lots of little tweaks to fix various consistency problems discovered by
650 * Solaris' CC. Fixed a bug in fg_debug.c with how the fgPrintf() wrapper
651 * passed arguments along to the real printf(). Also incorporated HUD changes
652 * by Michele America.
654 * Revision 1.9 1998/01/31 00:43:04 curt
655 * Added MetroWorks patches from Carmen Volpe.
657 * Revision 1.8 1998/01/27 00:47:51 curt
658 * Incorporated Paul Bleisch's <bleisch@chromatic.com> new debug message
659 * system and commandline/config file processing code.
661 * Revision 1.7 1998/01/19 18:40:20 curt
662 * Tons of little changes to clean up the code and to remove fatal errors
663 * when building with the c++ compiler.
665 * Revision 1.6 1997/12/15 23:54:34 curt
666 * Add xgl wrappers for debugging.
667 * Generate terrain normals on the fly.
669 * Revision 1.5 1997/12/10 22:37:39 curt
670 * Prepended "fg" on the name of all global structures that didn't have it yet.
671 * i.e. "struct WEATHER {}" became "struct fgWEATHER {}"
673 * Revision 1.4 1997/09/23 00:29:32 curt
674 * Tweaks to get things to compile with gcc-win32.
676 * Revision 1.3 1997/09/05 14:17:26 curt
677 * More tweaking with stars.
679 * Revision 1.2 1997/09/04 02:17:30 curt
682 * Revision 1.1 1997/08/29 18:03:22 curt