1 // hud.cxx -- hud defines and prototypes
3 // Written by Michele America, started September 1997.
5 // Copyright (C) 1997 Michele F. America - micheleamerica@geocities.com
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.
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.
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.
33 # define exception c_exception
42 # include <values.h> // for MAXINT
45 #include <Aircraft/aircraft.hxx>
46 #include <Debug/logstream.hxx>
48 #include <Include/fg_constants.h>
49 #include <Main/options.hxx>
50 #include <Math/fg_random.h>
51 #include <Math/mat3.h>
52 #include <Math/polar3d.hxx>
53 #include <Network/network.h>
54 #include <Scenery/scenery.hxx>
55 #include <Time/fg_timer.hxx>
57 #if defined ( __sun__ ) || defined ( __sgi )
59 extern void *memmove(void *, const void *, size_t);
67 // The following routines obtain information concerning the aircraft's
68 // current state and return it to calling instrument display routines.
69 // They should eventually be member functions of the aircraft.
72 deque< instr_item * > HUD_deque;
74 fgTextList HUD_TextList;
75 fgLineList HUD_LineList;
76 fgLineList HUD_StippleLineList;
82 locRECT( UINT left, UINT top, UINT right, UINT bottom);
83 RECT get_rect(void) { return rect;}
86 locRECT :: locRECT( UINT left, UINT top, UINT right, UINT bottom)
96 void drawOneLine( UINT x1, UINT y1, UINT x2, UINT y2)
104 void drawOneLine( RECT &rect)
107 glVertex2f(rect.left, rect.top);
108 glVertex2f(rect.right, rect.bottom);
113 // The following code deals with painting the "instrument" on the display
115 /* textString - Bitmap font string */
117 void textString( int x, int y, char *msg, void *font ){
121 // puDrawString ( NULL, msg, x, y );
125 glutBitmapCharacter(font, *msg);
132 /* strokeString - Stroke font string */
133 void strokeString(int x, int y, char *msg, void *font, float theta)
138 float sintheta,costheta;
144 glRotatef(theta * RAD_TO_DEG, 0.0, 0.0, 1.0);
145 sintheta = sin(theta);
146 costheta = cos(theta);
147 xx = (int)(x * costheta + y * sintheta);
148 yy = (int)(y * costheta - x * sintheta);
149 glTranslatef( xx, yy, 0);
150 glScalef(.1, .1, 0.0);
151 while( (c=*msg++) ) {
152 glutStrokeCharacter(font, c);
158 int getStringWidth ( char *str )
160 if ( HUDtext && str )
163 guiFntHandle->getBBox ( str, HUD_TextSize, 0, &l, &r, NULL, NULL ) ;
164 return FloatToInt( r - l );
169 //========================= End of Class Implementations===================
172 // Constructs a HUD object and then adds in instruments. At the present
173 // the instruments are hard coded into the routine. Ultimately these need
174 // to be defined by the aircraft's instrumentation records so that the
175 // display for a Piper Cub doesn't show the speed range of a North American
176 // mustange and the engine readouts of a B36!
181 int fgHUDInit( fgAIRCRAFT * /* current_aircraft */ )
188 int min_x = 25; //off/2;
189 int max_x = 615; //640-(off/2);
191 int max_y = 430; //480-off;
194 unsigned int text_h = 10;
195 unsigned int ladr_w2 = 60;
201 font_size = (current_options.get_xsize() > 1000) ? LARGE : SMALL;
205 FG_LOG( FG_COCKPIT, FG_INFO, "Initializing current aircraft HUD" );
207 // deque < instr_item * > :: iterator first = HUD_deque.begin();
208 // deque < instr_item * > :: iterator last = HUD_deque.end();
209 // HUD_deque.erase( first, last); // empty the HUD deque
211 HUD_deque.erase( HUD_deque.begin(), HUD_deque.end()); // empty the HUD deque
216 // For now lets just hardcode the hud here.
217 // In the future, hud information has to come from the same place
218 // aircraft information came from.
220 // fgHUDSetTimeMode( hud, NIGHT );
221 // fgHUDSetBrightness( hud, BRT_LIGHT );
224 int x = 290; /*cen_x-30*/
225 int y = 45; /*off-5*/
226 // HIptr = (instr_item *) new fgTBI_instr( x, y, ladr_w2, text_h );
227 HIptr = (instr_item *) new fgTBI_instr( 290, 45, 60, 10 );
228 HUD_deque.insert( HUD_deque.begin(), HIptr);
230 // case 1: // Artificial Horizon
231 HIptr = (instr_item *) new HudLadder( cen_x-ladr_w2, cen_y-ladr_h2,
232 2*ladr_w2, 2*ladr_h2 );
233 HUD_deque.insert( HUD_deque.begin(), HIptr);
235 // case 4: // GYRO COMPASS
236 HIptr = (instr_item *) new hud_card( cen_x-(compass_w/2),
249 HUD_deque.insert( HUD_deque.begin(), HIptr);
252 HIptr = (instr_item *) new hud_card( max_x - 35 -15, // 15 to balance speed card
257 // HUDS_RIGHT | HUDS_VERT,
258 HUDS_LEFT | HUDS_VERT,
266 HUD_deque.insert( HUD_deque.begin(), HIptr);
269 HIptr = (instr_item *) new guage_instr( cen_x-50, // x
270 cen_y + ladr_h2 -20, // y
273 get_aileronval, // data source
274 HUDS_BOTTOM | HUDS_NOTEXT,
278 HUD_deque.insert( HUD_deque.begin(), HIptr);
280 // case 3: // Radio Altimeter
281 HIptr = (instr_item *) new hud_card( cen_x + ladr_w2 + gap + 13 + ladr_t,
286 HUDS_LEFT | HUDS_VERT,
294 HUD_deque.insert( HUD_deque.begin(), HIptr);
297 HIptr = (instr_item *) new guage_instr( cen_x -ladr_w2 -gap -13 -20 -ladr_t,
301 get_elevatorval, // data source
302 HUDS_RIGHT | HUDS_VERT | HUDS_NOTEXT,
303 -100.0, // Scale data
306 HUD_deque.insert( HUD_deque.begin(), HIptr);
309 HIptr = (instr_item *) new guage_instr( cen_x-50, // x
310 cen_y -gap -ladr_w2 -20, //-85 // y
313 get_rudderval, // data source
314 HUDS_TOP | HUDS_NOTEXT,
318 HUD_deque.insert( HUD_deque.begin(), HIptr);
321 HIptr = (instr_item *) new hud_card( min_x +10 +5, //min_x +18,
326 // HUDS_LEFT | HUDS_VERT,
327 HUDS_RIGHT | HUDS_VERT,
336 HUD_deque.insert( HUD_deque.begin(), HIptr);
339 HIptr = (instr_item *) new guage_instr( min_x-10, // x
343 get_throttleval, // data source
344 // HUDS_VERT | HUDS_RIGHT | HUDS_NOTEXT,
345 HUDS_VERT | HUDS_LEFT | HUDS_NOTEXT, 100.0,
349 HUD_deque.insert( HUD_deque.begin(), HIptr);
350 // Remove this when below uncommented
352 HIptr = (instr_item *) new instr_label( 10,
366 HUD_deque.insert( HUD_deque.begin(), HIptr);
368 HIptr = (instr_item *) new lat_label( (cen_x - (compass_w/2))/2,
382 HUD_deque.insert( HUD_deque.begin(), HIptr);
384 HIptr = (instr_item *) new lon_label(((cen_x+compass_w/2)+(2*cen_x))/2,
397 HUD_deque.insert( HUD_deque.begin(), HIptr);
400 // case 10: // Digital KIAS
401 HIptr = (instr_item *) new instr_label ( 110,
415 HUD_deque.insert( HUD_deque.begin(), HIptr);
417 // case 11: // Digital Rate of Climb
418 HIptr = (instr_item *) new instr_label ( 110,
432 HUD_deque.insert( HUD_deque.begin(), HIptr);
434 // case 12: // Roll indication diagnostic
435 HIptr = (instr_item *) new instr_label ( 110,
449 HUD_deque.insert( HUD_deque.begin(), HIptr);
451 // case 13: // Angle of attack diagnostic
452 HIptr = (instr_item *) new instr_label ( 440,
466 HUD_deque.insert( HUD_deque.begin(), HIptr);
469 HIptr = (instr_item *) new instr_label ( 440,
483 HUD_deque.insert( HUD_deque.begin(), HIptr);
486 HIptr = (instr_item *) new instr_label ( 440,
500 HUD_deque.insert( HUD_deque.begin(), HIptr);
503 HIptr = (instr_item *) new instr_label( 440,
517 HUD_deque.insert( HUD_deque.begin(), HIptr);
520 HIptr = (instr_item *) new instr_label( 440,
534 HUD_deque.insert( HUD_deque.begin(), HIptr);
537 HIptr = (instr_item *) new instr_label( 440,
551 HUD_deque.insert( HUD_deque.begin(), HIptr);
554 HIptr = (instr_item *) new instr_label( 10,
568 HUD_deque.insert( HUD_deque.begin(), HIptr);
571 switch( current_options.get_tris_or_culled() ) {
573 HIptr = (instr_item *) new instr_label( 10,
589 HIptr = (instr_item *) new instr_label( 10,
608 HIptr = (instr_item *) new instr_label( 10,
622 HUD_deque.insert( HUD_deque.begin(), HIptr);
627 // if( HIptr ) { // Anything to install?
628 // HUD_deque.insert( HUD_deque.begin(), HIptr);
634 return 0; // For now. Later we may use this for an error code.
638 int fgHUDInit2( fgAIRCRAFT * /* current_aircraft */ )
640 // instr_item *HIptr;
646 // int max_x = 640-off;
650 // int cen_y = 480 / 2;
658 font_size = (current_options.get_xsize() > 1000) ? LARGE : SMALL;
662 FG_LOG( FG_COCKPIT, FG_INFO, "Initializing current aircraft HUD" );
664 // deque < instr_item * > :: iterator first = HUD_deque.begin();
665 // deque < instr_item * > :: iterator last = HUD_deque.end();
666 // HUD_deque.erase( first, last); // empty the HUD deque
667 HUD_deque.erase( HUD_deque.begin(), HUD_deque.end());
672 // For now lets just hardcode the hud here.
673 // In the future, hud information has to come from the same place
674 // aircraft information came from.
676 // fgHUDSetTimeMode( hud, NIGHT );
677 // fgHUDSetBrightness( hud, BRT_LIGHT );
684 // case 4: // GYRO COMPASS
685 p =new hud_card( cen_x-(compass_w/2),
698 HUD_deque.push_front( p );
700 p = new lat_label( (cen_x - compass_w/2)/2,
713 HUD_deque.push_front( p );
715 // p = new instr_label( 140, 450, 60, 10,
726 // HUD_deque.push_front( p );
728 p = new lon_label(((cen_x+compass_w/2)+(2*cen_x))/2,
741 HUD_deque.push_front( p );
745 p = new instr_label( x_pos, 25, 60, 10,
756 HUD_deque.push_front( p );
758 p = new instr_label( x_pos, 40, 120, 10,
769 HUD_deque.push_front( p );
771 p = new instr_label( x_pos, 55, 120, 10,
782 HUD_deque.push_front( p );
784 p = new instr_label( x_pos, 70, 90, 10,
795 HUD_deque.push_front( p );
799 p = new instr_label ( x_pos,
813 HUD_deque.push_front( p );
815 p = new instr_label( x_pos, 55, 40, 30,
826 HUD_deque.push_front( p );
828 if ( current_options.get_units() == fgOPTIONS::FG_UNITS_FEET ) {
829 strcpy(units, " ft");
833 p = new instr_label( x_pos, 40, 40, 10,
844 HUD_deque.push_front( p );
846 p = new instr_label( x_pos, 25, 40, 10,
857 HUD_deque.push_front( p );
859 p = new instr_label( x_pos, 10, 60, 10,
870 HUD_deque.push_front( p );
872 p = new fgTBI_instr( 290, 55, 60, 10 ); // 270
873 HUD_deque.push_front( p );
875 p = new guage_instr( 270, //250, // x
876 390, //360, //400, //45, //420, // y
879 get_aileronval, // data source
880 HUDS_BOTTOM | HUDS_NOTEXT,
884 HUD_deque.push_front( p );
886 p = new guage_instr( 20, // x
890 get_elevatorval, // data source
891 HUDS_RIGHT | HUDS_VERT | HUDS_NOTEXT,
892 -100.0, // Scale data
895 HUD_deque.push_front( p );
897 p = new guage_instr( 270, //250, // x
901 get_rudderval, // data source
902 HUDS_TOP | HUDS_NOTEXT,
906 HUD_deque.push_front( p );
908 p = new guage_instr( 600, // x
912 get_throttleval, // data source
913 HUDS_VERT | HUDS_LEFT | HUDS_NOTEXT,
917 HUD_deque.push_front( p );
919 return 0; // For now. Later we may use this for an error code.
922 int global_day_night_switch = DAY;
924 void HUD_brightkey( bool incr_bright )
926 instr_item *pHUDInstr = HUD_deque[0];
927 int brightness = pHUDInstr->get_brightness();
929 if( current_options.get_hud_status() ) {
931 switch (brightness) {
933 current_options.set_hud_status(0);
937 brightness = BRT_LIGHT;
941 brightness = BRT_MEDIUM;
945 brightness = BRT_DARK;
949 brightness = BRT_BLACK;
953 switch (brightness) {
955 brightness = BRT_MEDIUM;
959 brightness = BRT_DARK;
963 brightness = BRT_BLACK;
968 current_options.set_hud_status(0);
973 current_options.set_hud_status(1);
975 if( DAY == global_day_night_switch ) {
976 brightness = BRT_BLACK;
979 brightness = BRT_DARK;
980 global_day_night_switch = DAY;
984 if( NIGHT == global_day_night_switch ) {
985 brightness = BRT_DARK;
988 brightness = BRT_MEDIUM;
989 global_day_night_switch = NIGHT;
993 pHUDInstr->SetBrightness( brightness );
998 // Performs a once around the list of calls to instruments installed in
999 // the HUD object with requests for redraw. Kinda. It will when this is
1002 void fgUpdateHUD( void ) {
1004 // int day_night_sw = current_aircraft.controls->day_night_switch;
1005 int day_night_sw = global_day_night_switch;
1006 int hud_displays = HUD_deque.size();
1007 instr_item *pHUDInstr;
1010 if( !hud_displays ) { // Trust everyone, but ALWAYS cut the cards!
1014 HUD_TextList.erase();
1015 HUD_LineList.erase();
1016 // HUD_StippleLineList.erase();
1018 pHUDInstr = HUD_deque[0];
1019 brightness = pHUDInstr->get_brightness();
1020 // brightness = HUD_deque.at(0)->get_brightness();
1022 glMatrixMode(GL_PROJECTION);
1026 gluOrtho2D(0, 640, 0, 480);
1027 glMatrixMode(GL_MODELVIEW);
1031 glColor3f(1.0, 1.0, 1.0);
1034 glDisable(GL_DEPTH_TEST);
1035 glDisable(GL_LIGHTING);
1037 // We can do translucency, so why not. :-)
1038 // glEnable ( GL_BLEND ) ;
1039 // glBlendFunc ( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ) ;
1041 if( day_night_sw == DAY) {
1042 switch (brightness) {
1044 // glColor4f (0.1, 0.9, 0.1, 0.75);
1045 glColor3f (0.1, 0.9, 0.1);
1049 // glColor4f (0.1, 0.7, 0.0, 0.75);
1050 glColor3f (0.1, 0.7, 0.0);
1054 // glColor4f (0.0, 0.6, 0.0, 0.75);
1055 glColor3f(0.0, 0.6, 0.0);
1059 // glColor4f( 0.0, 0.0, 0.0, 0.75);
1060 glColor3f( 0.0, 0.0, 0.0);
1067 if( day_night_sw == NIGHT) {
1068 switch (brightness) {
1070 // glColor4f (0.9, 0.1, 0.1, 0.75);
1071 glColor3f (0.9, 0.1, 0.1);
1075 // glColor4f (0.7, 0.0, 0.1, 0.75);
1076 glColor3f (0.7, 0.0, 0.1);
1081 // glColor4f (0.6, 0.0, 0.0, 0.75);
1082 glColor3f (0.6, 0.0, 0.0);
1085 else { // Just in case default
1086 // glColor4f (0.1, 0.9, 0.1, 0.75);
1087 glColor3f (0.1, 0.9, 0.1);
1091 deque < instr_item * > :: iterator current = HUD_deque.begin();
1092 deque < instr_item * > :: iterator last = HUD_deque.end();
1094 for ( ; current != last; ++current ) {
1095 pHUDInstr = *current;
1097 if( pHUDInstr->enabled()) {
1098 // fgPrintf( FG_COCKPIT, FG_DEBUG, "HUD Code %d Status %d\n",
1099 // hud->code, hud->status );
1101 // HUD_deque.at(i)->draw(); // Responsible for broken or fixed variants.
1102 // No broken displays honored just now.
1106 char *gmt_str = get_formated_gmt_time();
1107 HUD_TextList.add( fgText( 40, 10, gmt_str) );
1109 #ifdef FG_NETWORK_OLK
1110 if ( net_hud_display ) {
1115 HUD_TextList.draw();
1117 line_width = (current_options.get_xsize() > 1000) ? 1.0 : 0.5;
1118 glLineWidth(line_width);
1119 HUD_LineList.draw();
1121 // glEnable(GL_LINE_STIPPLE);
1122 // glLineStipple( 1, 0x00FF );
1123 // HUD_StippleLineList.draw();
1124 // glDisable(GL_LINE_STIPPLE);
1126 // glDisable( GL_BLEND );
1128 glEnable(GL_DEPTH_TEST);
1129 glEnable(GL_LIGHTING);
1130 glMatrixMode(GL_PROJECTION);
1132 glMatrixMode(GL_MODELVIEW);