1 /**************************************************************************
2 * hud.c -- hud defines and prototypes
4 * Written by Michele America, started September 1997.
6 * Copyright (C) 1997 Michele F. America - nomimarketing@mail.telepac.pt
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 **************************************************************************/
36 # include <values.h> // for MAXINT
41 #include <Include/fg_constants.h>
42 #include <Aircraft/aircraft.h>
43 #include <Main/fg_debug.h>
44 #include <Math/fg_random.h>
45 #include <Math/mat3.h>
46 #include <Math/polar.h>
47 #include <Scenery/scenery.h>
48 #include <Time/fg_timer.h>
49 #include <Weather/weather.h>
53 #define drawOneLine(x1,y1,x2,y2) glBegin(GL_LINES); \
54 glVertex2f ((x1),(y1)); glVertex2f ((x2),(y2)); glEnd();
57 // The following routines obtain information concerntin the aircraft's
58 // current state and return it to calling instrument display routines.
59 // They should eventually be member functions of the aircraft.
62 double get_throttleval( void )
64 fgCONTROLS *pcontrols;
66 pcontrols = current_aircraft.controls;
67 return pcontrols->throttle[0]; // Hack limiting to one engine
70 double get_aileronval( void )
72 fgCONTROLS *pcontrols;
74 pcontrols = current_aircraft.controls;
75 return pcontrols->aileron;
78 double get_elevatorval( void )
80 fgCONTROLS *pcontrols;
82 pcontrols = current_aircraft.controls;
83 return pcontrols->elevator;
86 double get_elev_trimval( void )
88 fgCONTROLS *pcontrols;
90 pcontrols = current_aircraft.controls;
91 return pcontrols->elevator_trim;
94 double get_rudderval( void )
96 fgCONTROLS *pcontrols;
98 pcontrols = current_aircraft.controls;
99 return pcontrols->rudder;
102 double get_speed( void )
106 f = current_aircraft.flight;
107 return( FG_V_equiv_kts ); // Make an explicit function call.
110 double get_aoa( void )
114 f = current_aircraft.flight;
115 return( FG_Gamma_vert_rad * RAD_TO_DEG );
118 double get_roll( void )
122 f = current_aircraft.flight;
126 double get_pitch( void )
130 f = current_aircraft.flight;
134 double get_heading( void )
138 f = current_aircraft.flight;
139 return( FG_Psi*RAD_TO_DEG );
142 double get_altitude( void )
145 // double rough_elev;
147 f = current_aircraft.flight;
148 // rough_elev = mesh_altitude(FG_Longitude * RAD_TO_ARCSEC,
149 // FG_Latitude * RAD_TO_ARCSEC);
151 return( FG_Altitude * FEET_TO_METER /* -rough_elev */ );
155 // The following code deals with painting the "instrument" on the display
157 /* textString - Bitmap font string */
159 static void textString(int x, int y, char *msg, void *font)
163 glutBitmapCharacter(font, *msg);
168 /* strokeString - Stroke font string */
170 static void strokeString(int x, int y, char *msg, void *font)
173 glTranslatef(x, y, 0);
174 glScalef(.04, .04, .04);
176 glutStrokeCharacter(font, *msg);
185 Draws a measuring scale anywhere on the HUD
188 Needs: HUD_scale struct
191 static void drawscale( HUD_scale * pscale )
202 double cur_value = (*(pscale->load_value))();
204 vmin = cur_value - pscale->width_units / 2.0; // width units == needle travel
205 vmax = cur_value + pscale->width_units / 2.0; // or picture unit span.
207 scr_span = pscale->scr_max - pscale->scr_min; // Run of scan in pix coord
208 scr_span |= 1; // If span is odd number of units, mid will be correct.
209 // If not it will be high by one coordinate unit. This is
210 // an artifact of integer division needed for screen loc's.
212 mid_scr = (scr_span >> 1) + pscale->scr_min; // Middle is half that +
215 // Calculate the number of screen units per indicator unit
216 // We must force floating point calculation or the factor
217 // will be low and miss locate tics by several units.
219 factor = (double)scr_span / (double)pscale->width_units;
221 // Separate calculations for location of markings by scale
224 if( pscale->type == VERTICAL ) // Vertical scale
227 if( pscale->orientation == LEFT ) // Calculate x marker offset
228 marker_x = pscale->scr_pos-6;
230 if( pscale->orientation == RIGHT )
231 marker_x = pscale->scr_pos;
233 // Draw the basic markings for the scale...
235 drawOneLine( pscale->scr_pos, // Vertical bar
239 if( pscale->orientation == LEFT )
241 drawOneLine( pscale->scr_pos-3, // Bottom tick bar
246 drawOneLine( pscale->scr_pos-3, // Top tick bar
251 drawOneLine( pscale->scr_pos, // Middle tick bar /Index
258 if( pscale->orientation == RIGHT )
260 drawOneLine( pscale->scr_pos,
265 drawOneLine( pscale->scr_pos,
270 drawOneLine( pscale->scr_pos,
276 // Work through from bottom to top of scale. Calculating where to put
277 // minor and major ticks.
279 for( i = vmin; i <= vmax; i++ )
281 if( pscale->sub_type == LIMIT ) { // Don't show ticks
282 condition = (i >= pscale->minimum_value); // below Minimum value.
285 if( pscale->sub_type == NOLIMIT ) {
289 if( condition ) // Show a tick if necessary
291 // Calculate the location of this tick
292 marker_y = pscale->scr_min + (i - vmin) * factor;
294 // Block calculation artifact from drawing ticks below min coordinate.
295 // Calculation here accounts for text height.
297 if( marker_y < (pscale->scr_min + 4)) { // Magic number!!!
300 if( (i%pscale->div_min) == 0) {
301 if( pscale->orientation == LEFT )
303 drawOneLine( marker_x + 3, marker_y, marker_x + 6, marker_y );
306 if( pscale->orientation == RIGHT )
308 drawOneLine( marker_x, marker_y, marker_x + 3, marker_y );
312 if( (i%pscale->div_max) == 0 ) {
313 drawOneLine( marker_x, marker_y,
314 marker_x + 6, marker_y );
315 sprintf( TextScale, "%d", i );
316 if( pscale->orientation == LEFT ) {
317 textString( marker_x - 8 * strlen(TextScale) - 2, marker_y - 4,
318 TextScale, GLUT_BITMAP_8_BY_13 );
321 if( pscale->orientation == RIGHT ) {
322 textString( marker_x + 10, marker_y - 4,
323 TextScale, GLUT_BITMAP_8_BY_13 );
327 } // End if condition
328 } // End for range of i from vmin to vmax
329 } // End if VERTICAL SCALE TYPE
330 if( pscale->type == HORIZONTAL ) // Horizontal scale
332 if( pscale->orientation == TOP ) {
333 marker_y = pscale->scr_pos;
336 if( pscale->orientation == BOTTOM ) {
337 marker_y = pscale->scr_pos - 6;
340 drawOneLine( pscale->scr_min,
344 if( pscale->orientation == TOP )
346 drawOneLine( pscale->scr_min,
351 drawOneLine( pscale->scr_max,
356 drawOneLine( mid_scr,
363 if( pscale->orientation == BOTTOM )
365 drawOneLine( pscale->scr_min,
370 drawOneLine( pscale->scr_max,
375 drawOneLine( mid_scr,
382 for( i = vmin; i <= vmax; i++ ) // increment is faster than addition
384 if( pscale->sub_type == LIMIT ) {
385 condition = (i >= pscale->minimum_value);
388 if( pscale->sub_type == NOLIMIT ) {
393 marker_x = pscale->scr_min+(i-vmin)*factor;
394 if( i%pscale->div_min==0 ) {
395 if( pscale->orientation == TOP )
397 drawOneLine( marker_x, marker_y, marker_x, marker_y+3 );
400 if( pscale->orientation == BOTTOM )
402 drawOneLine( marker_x, marker_y+3, marker_x, marker_y+6 );
406 if( i%pscale->div_max==0 )
408 sprintf( TextScale, "%d", i );
409 if( pscale->orientation == TOP )
411 drawOneLine( marker_x, marker_y, marker_x, marker_y+6 );
412 textString ( marker_x-4*strlen(TextScale), marker_y+14,
413 TextScale, GLUT_BITMAP_8_BY_13 );
416 if( pscale->orientation == BOTTOM )
418 drawOneLine( marker_x, marker_y, marker_x, marker_y+6 );
419 textString ( marker_x+10, marker_y-4,
420 TextScale, GLUT_BITMAP_8_BY_13 );
431 // Draws a climb ladder in the center of the HUD
434 static void drawladder( HUD_ladder *ladder )
437 double roll_value, pitch_value;
438 int marker_x, marker_y;
442 int scr_min, scr_max;
445 int new_x_ini, new_x_end;
446 int new_y_ini, new_y_end;
452 roll_value = (*ladder->load_roll)();
453 pitch_value = (*ladder->load_pitch)()*RAD_TO_DEG;
455 vmin = pitch_value - ladder->width_units/2;
456 vmax = pitch_value + ladder->width_units/2;
458 scr_min = ladder->y_pos - (ladder->scr_height/2);
459 scr_max = scr_min + ladder->scr_height;
462 mid_scr = scr_min + (scr_max-scr_min)/2;
465 marker_x = ladder->x_pos - ladder->scr_width/2;
467 factor = (scr_max-scr_min)/ladder->width_units;
469 for( i=vmin; i<=vmax; i+=1 )
474 marker_y = scr_min+(i-vmin)*factor;
475 if( i%ladder->div_units==0 )
477 sprintf( TextLadder, "%d", i );
478 if( ladder->scr_hole == 0 )
481 x_ini = ladder->x_pos - ladder->scr_width/2;
484 x_ini = ladder->x_pos - ladder->scr_width/2 - 10;
487 x_end = ladder->x_pos + ladder->scr_width/2;
489 new_x_ini = ladder->x_pos + \
490 (x_ini - ladder->x_pos) * cos(roll_value) - \
491 (y_ini - ladder->y_pos) * sin(roll_value);
492 new_y_ini = ladder->y_pos + \
493 (x_ini - ladder->x_pos) * sin(roll_value) + \
494 (y_ini - ladder->y_pos) * cos(roll_value);
495 new_x_end = ladder->x_pos + \
496 (x_end - ladder->x_pos) * cos(roll_value) - \
497 (y_end - ladder->y_pos) * sin(roll_value);
498 new_y_end = ladder->y_pos + \
499 (x_end - ladder->x_pos) * sin(roll_value) + \
500 (y_end - ladder->y_pos) * cos(roll_value);
504 drawOneLine( new_x_ini, new_y_ini, new_x_end, new_y_end );
508 glEnable(GL_LINE_STIPPLE);
509 glLineStipple( 1, 0x00FF );
510 drawOneLine( new_x_ini, new_y_ini, new_x_end, new_y_end );
511 glDisable(GL_LINE_STIPPLE);
513 textString( new_x_ini - 8 * strlen(TextLadder) - 8,
515 TextLadder, GLUT_BITMAP_8_BY_13 );
516 textString( new_x_end + 10,
518 TextLadder, GLUT_BITMAP_8_BY_13 );
523 x_ini = ladder->x_pos - ladder->scr_width/2;
526 x_ini = ladder->x_pos - ladder->scr_width/2 - 10;
529 x_end = ladder->x_pos - ladder->scr_width/2 + ladder->scr_hole/2;
531 new_x_ini = ladder->x_pos+ \
532 (x_ini - ladder->x_pos) * cos(roll_value) -\
533 (y_ini - ladder->y_pos) * sin(roll_value);
534 new_y_ini = ladder->y_pos+ \
535 (x_ini - ladder->x_pos) * sin(roll_value) +\
536 (y_ini - ladder->y_pos) * cos(roll_value);
537 new_x_end = ladder->x_pos+ \
538 (x_end - ladder->x_pos) * cos(roll_value) -\
539 (y_end - ladder->y_pos) * sin(roll_value);
540 new_y_end = ladder->y_pos+ \
541 (x_end - ladder->x_pos) * sin(roll_value) +\
542 (y_end - ladder->y_pos) * cos(roll_value);
546 drawOneLine( new_x_ini, new_y_ini, new_x_end, new_y_end );
550 glEnable(GL_LINE_STIPPLE);
551 glLineStipple( 1, 0x00FF );
552 drawOneLine( new_x_ini, new_y_ini, new_x_end, new_y_end );
553 glDisable(GL_LINE_STIPPLE);
555 textString( new_x_ini - 8 * strlen(TextLadder) - 8,
557 TextLadder, GLUT_BITMAP_8_BY_13 );
559 x_ini = ladder->x_pos + ladder->scr_width/2 - ladder->scr_hole/2;
562 x_end = ladder->x_pos + ladder->scr_width/2;
565 x_end = ladder->x_pos + ladder->scr_width/2 + 10;
568 new_x_ini = ladder->x_pos + \
569 (x_ini-ladder->x_pos)*cos(roll_value) -\
570 (y_ini-ladder->y_pos)*sin(roll_value);
571 new_y_ini = ladder->y_pos + \
572 (x_ini-ladder->x_pos)*sin(roll_value) +\
573 (y_ini-ladder->y_pos)*cos(roll_value);
574 new_x_end = ladder->x_pos + \
575 (x_end-ladder->x_pos)*cos(roll_value) -\
576 (y_end-ladder->y_pos)*sin(roll_value);
577 new_y_end = ladder->y_pos + \
578 (x_end-ladder->x_pos)*sin(roll_value) +\
579 (y_end-ladder->y_pos)*cos(roll_value);
583 drawOneLine( new_x_ini, new_y_ini, new_x_end, new_y_end );
587 glEnable(GL_LINE_STIPPLE);
588 glLineStipple( 1, 0x00FF );
589 drawOneLine( new_x_ini, new_y_ini, new_x_end, new_y_end );
590 glDisable(GL_LINE_STIPPLE);
592 textString( new_x_end+10, new_y_end-4,
593 TextLadder, GLUT_BITMAP_8_BY_13 );
596 /* if( i%pscale->div_max==0 )
598 drawOneLine( marker_x, marker_y, marker_x+6, marker_y );
599 sprintf( TextScale, "%d", i );
600 if( pscale->orientation == LEFT )
602 textString( marker_x-8*strlen(TextScale)-2, marker_y-4,
603 TextScale, GLUT_BITMAP_8_BY_13 );
605 else if( pscale->orientation == RIGHT )
607 textString( marker_x+10, marker_y-4,
608 TextScale, GLUT_BITMAP_8_BY_13 );
617 // Draws an artificial horizon line in the center of the HUD
618 // (with or without a center hole)
620 // Needs: x_center, y_center, length, hole
623 static void drawhorizon( HUD_horizon *horizon )
627 // struct fgFLIGHT *f = ¤t_aircraft.flight;
628 double sin_bank, cos_bank;
631 bank_angle = (*horizon->load_value)();
633 // sin_bank = sin( FG_2PI-FG_Phi );
634 // cos_bank = cos( FG_2PI-FG_Phi );
635 sin_bank = sin(FG_2PI-bank_angle);
636 cos_bank = cos(FG_2PI-bank_angle);
637 x_inc1 = (int)(horizon->scr_width * cos_bank);
638 y_inc1 = (int)(horizon->scr_width * sin_bank);
639 x_inc2 = (int)(horizon->scr_hole * cos_bank);
640 y_inc2 = (int)(horizon->scr_hole * sin_bank);
642 if( horizon->scr_hole == 0 )
644 drawOneLine( horizon->x_pos - x_inc1, horizon->y_pos - y_inc1, \
645 horizon->x_pos + x_inc1, horizon->y_pos + y_inc1 );
649 drawOneLine( horizon->x_pos - x_inc1, horizon->y_pos - y_inc1, \
650 horizon->x_pos - x_inc2, horizon->y_pos - y_inc2 );
651 drawOneLine( horizon->x_pos + x_inc2, horizon->y_pos + y_inc2, \
652 horizon->x_pos + x_inc1, horizon->y_pos + y_inc1 );
656 // drawControlSurfaces()
657 // Draws a representation of the control surfaces in their current state
658 // anywhere in the HUD
661 static void drawControlSurfaces( HUD_control_surfaces *ctrl_surf )
669 x_ini = ctrl_surf->x_pos;
670 y_ini = ctrl_surf->y_pos;
674 drawOneLine( x_ini, y_ini, x_end, y_ini );
675 drawOneLine( x_ini, y_ini, x_ini, y_end );
676 drawOneLine( x_ini, y_end, x_end, y_end );
677 drawOneLine( x_end, y_end, x_end, y_ini );
678 drawOneLine( x_ini + 30, y_ini, x_ini + 30, y_end );
679 drawOneLine( x_ini + 30, y_ini + 30, x_ini + 90, y_ini + 30 );
680 drawOneLine( x_ini + 90, y_ini, x_ini + 90, y_end );
681 drawOneLine( x_ini + 120, y_ini, x_ini + 120, y_end );
683 pCtls = current_aircraft.controls;
685 /* Draw elevator diagram */
686 textString( x_ini + 1, y_end-11, "E", GLUT_BITMAP_8_BY_13 );
687 drawOneLine( x_ini + 15, y_ini + 5, x_ini + 15, y_ini + 55 );
688 drawOneLine( x_ini + 14, y_ini + 30, x_ini + 16, y_ini + 30 );
689 if( pCtls->elevator <= -0.01 || pCtls->elevator >= 0.01 )
691 drawOneLine( x_ini + 10, y_ini + 5 + (int)(((pCtls->elevator + 1.0)/2)*50.0), \
692 x_ini + 20, y_ini + 5 + (int)(((pCtls->elevator + 1.0)/2)*50.0) );
696 drawOneLine( x_ini + 7, y_ini + 5 + (int)(((pCtls->elevator + 1.0)/2)*50.0), \
697 x_ini + 23, y_ini + 5 + (int)(((pCtls->elevator + 1.0)/2)*50.0) );
700 /* Draw aileron diagram */
701 textString( x_ini + 30 + 1, y_end-11, "A", GLUT_BITMAP_8_BY_13 );
702 drawOneLine( x_ini + 35, y_end-15, x_ini + 85, y_end-15 );
703 drawOneLine( x_ini + 60, y_end-14, x_ini + 60, y_end-16 );
704 if( pCtls->aileron <= -0.01 || pCtls->aileron >= 0.01 )
706 drawOneLine( x_ini + 35 + (int)(((pCtls->aileron + 1.0)/2)*50.0), y_end-20, \
707 x_ini + 35 + (int)(((pCtls->aileron + 1.0)/2)*50.0), y_end-10 );
711 drawOneLine( x_ini + 35 + (int)(((pCtls->aileron + 1.0) / 2) * 50.0),
713 x_ini + 35 + (int)(((pCtls->aileron + 1.0) / 2) * 50.0),
717 /* Draw rudder diagram */
718 textString ( x_ini + 30 + 1, y_ini + 21, "R", GLUT_BITMAP_8_BY_13 );
719 drawOneLine( x_ini + 35, y_ini + 15, x_ini + 85, y_ini + 15 );
720 drawOneLine( x_ini + 60, y_ini + 14, x_ini + 60, y_ini + 16 );
722 if( pCtls->rudder <= -0.01 || pCtls->rudder >= 0.01 )
724 drawOneLine( x_ini + 35 + (int)(((pCtls->rudder + 1.0) / 2) * 50.0),
726 x_ini + 35 + (int)(((pCtls->rudder + 1.0) / 2) * 50.0),
731 drawOneLine( x_ini + 35 + (int)(((pCtls->rudder + 1.0) / 2) * 50.0),
733 x_ini + 35 + (int)(((pCtls->rudder + 1.0) / 2) * 50.0),
738 /* Draw throttle diagram */
739 textString( x_ini + 90 + 1, y_end-11, "T", GLUT_BITMAP_8_BY_13 );
740 textString( x_ini + 90 + 1, y_end-21, "r", GLUT_BITMAP_8_BY_13 );
741 drawOneLine( x_ini + 105, y_ini + 5, x_ini + 105, y_ini + 55 );
742 drawOneLine( x_ini + 100, y_ini + 5 + (int)(pCtls->throttle[0]*50.0), \
743 x_ini + 110, y_ini + 5 + (int)(pCtls->throttle[0]*50.0) );
746 /* Draw elevator trim diagram */
747 textString( x_ini + 121, y_end-11, "T", GLUT_BITMAP_8_BY_13 );
748 textString( x_ini + 121, y_end-22, "m", GLUT_BITMAP_8_BY_13 );
749 drawOneLine( x_ini + 135, y_ini + 5, x_ini + 135, y_ini + 55 );
750 drawOneLine( x_ini + 134, y_ini + 30, x_ini + 136, y_ini + 30 );
751 if( pCtls->elevator_trim <= -0.01 || pCtls->elevator_trim >= 0.01 )
753 drawOneLine( x_ini + 130, y_ini + 5 + (int)(((pCtls->elevator_trim + 1)/2)*50.0), \
754 x_ini + 140, y_ini + 5 + (int)(((pCtls->elevator_trim + 1.0)/2)*50.0) );
758 drawOneLine( x_ini + 127, y_ini + 5 + (int)(((pCtls->elevator_trim + 1.0)/2)*50.0), \
759 x_ini + 143, y_ini + 5 + (int)(((pCtls->elevator_trim + 1.0)/2)*50.0) );
765 // Draws a label anywhere in the HUD
769 static void drawlabel( HUD_label *label )
776 if( !label ) { // Eliminate the possible, but absurd case.
780 if( label->pre_str != NULL) {
781 if( label->post_str != NULL ) {
782 sprintf( buffer, "%s%s%s", label->pre_str, \
787 sprintf( buffer, "%s%s", label->pre_str, \
792 if( label->post_str != NULL ) {
793 sprintf( buffer, "%s%s", label->format, \
796 } // else do nothing if both pre and post strings are nulls. Interesting.
799 sprintf( string, buffer, (*label->load_value)() );
801 fgPrintf( FG_COCKPIT, FG_DEBUG, buffer );
802 fgPrintf( FG_COCKPIT, FG_DEBUG, "\n" );
803 fgPrintf( FG_COCKPIT, FG_DEBUG, string );
804 fgPrintf( FG_COCKPIT, FG_DEBUG, "\n" );
806 lenstr = strlen( string );
807 if( label->justify == LEFT_JUST ) {
811 if( label->justify == CENTER_JUST ) {
815 if( label->justify == RIGHT_JUST ) {
821 if( label->size == SMALL ) {
822 textString( label->x_pos + posincr, label->y_pos,
823 string, GLUT_BITMAP_8_BY_13);
826 if( label->size == LARGE ) {
827 textString( label->x_pos + posincr, label->y_pos,
828 string, GLUT_BITMAP_9_BY_15);
832 // The following routines concern HUD object/component object construction
837 // Constructs a HUD object and then adds in instruments. At the present
838 // the instruments are hard coded into the routine. Ultimately these need
839 // to be defined by the aircraft's instrumentation records so that the
840 // display for a Piper Cub doesn't show the speed range of a North American
841 // mustange and the engine readouts of a B36!
843 Hptr fgHUDInit( fgAIRCRAFT *current_aircraft )
847 fgPrintf( FG_COCKPIT, FG_INFO, "Initializing HUD\n" );
849 hud = (Hptr)calloc(sizeof( HUD),1);
856 // For now lets just hardcode the hud here.
857 // In the future, hud information has to come from the same place
858 // aircraft information came from.
860 fgHUDSetTimeMode( hud, NIGHT );
861 fgHUDSetBrightness( hud, BRT_LIGHT );
863 // Small, original HUD configuration
864 // fgHUDAddHorizon( hud, 590, 50, 40, 20, get_roll );
865 // fgHUDAddLadder ( hud, 330, 190, 90, 180, 70, 10,
866 // NONE, 45, get_roll, get_pitch );
867 // fgHUDAddScale ( hud, VERTICAL, LIMIT, 220, 100, 280, 5, 10,
868 // LEFT, 0, 100, 50, get_speed );
869 // fgHUDAddScale ( hud, VERTICAL, NOLIMIT, 440, 100, 280, 1, 5, RIGHT,
870 // -40, 50, 25, get_aoa );
871 // fgHUDAddScale ( hud, HORIZONTAL, NOLIMIT, 280, 220, 440, 5, 10,
872 // TOP, 0, 50, 50, get_heading );
873 // fgHUDAddLabel ( hud, 180, 85, SMALL, NOBLINK,
874 // RIGHT_JUST, NULL, " Kts", "%5.0f", get_speed );
875 // fgHUDAddLabel ( hud, 180, 73, SMALL, NOBLINK,
876 // RIGHT_JUST, NULL, " m", "%5.0f", get_altitude );
877 // fgHUDAddControlSurfaces( hud, 10, 10, NULL );
879 // Bigger and placed a bit higher HUD configuration
880 fgHUDAddHorizon( hud, 590, 50, 40, 20, get_roll );
881 fgHUDAddLadder ( hud, 330, 270, 120, 180, 70, 10,
882 NONE, 45, get_roll, get_pitch );
883 fgHUDAddScale ( hud, VERTICAL, LIMIT, 200, 180, 380, 5, 10,
884 LEFT, 0, 100, 50, get_speed );
885 fgHUDAddScale ( hud, VERTICAL, NOLIMIT, 460, 180, 380, 1, 5,
886 RIGHT, -40, 50, 25, get_aoa );
887 fgHUDAddScale ( hud, HORIZONTAL, NOLIMIT, 380, 200, 460, 5, 10,
888 TOP, 0, 50, 50, get_heading );
889 fgHUDAddLabel ( hud, 160, 165, SMALL, NOBLINK,
890 RIGHT_JUST, NULL, " Kts", "%5.0f", get_speed );
891 fgHUDAddLabel ( hud, 160, 153, SMALL, NOBLINK,
892 RIGHT_JUST, NULL, " m", "%5.0f", get_altitude );
893 fgHUDAddControlSurfaces( hud, 10, 10, NULL );
895 // fgHUDAddControl( hud, HORIZONTAL, 50, 25, get_aileronval ); // was 10, 10
896 // fgHUDAddControl( hud, VERTICAL, 150, 25, get_elevatorval ); // was 10, 10
897 // fgHUDAddControl( hud, HORIZONTAL, 250, 25, get_rudderval ); // was 10, 10
904 // This is a stand in for linked list code that will get replaced later
905 // by some more elegant list handling code.
907 void add_instrument( Hptr hud, HIptr pinstrument )
909 if( !hud || !pinstrument ) {
913 pinstrument->next = hud->instruments;
914 hud->instruments = pinstrument;
920 // Constructs a HUD_horizon "object" and installs it into the hud instrument
923 Hptr fgHUDAddHorizon( Hptr hud, \
928 double (*load_value)() )
930 HUD_horizon *phorizon;
931 HUD_instr *pinstrument;
936 // construct the parent object
937 pinstrument = (HIptr)calloc(sizeof(HUD_instr),1);
938 if( pinstrument == NULL ) {
941 pinstrument->type = HUDhorizon; // ARTIFICIAL_HORIZON;
943 // Construct the horizon
944 phorizon = (HUD_horizon *) calloc( sizeof(HUD_horizon),1);
945 if( phorizon == NULL ) {
949 phorizon->x_pos = x_pos;
950 phorizon->y_pos = y_pos;
951 phorizon->scr_width = length;
952 phorizon->scr_hole = hole_len;
953 phorizon->load_value = load_value;
954 // Install the horizon in the parent.
955 pinstrument->instr = phorizon;
956 // Install the instrument into hud.
957 add_instrument( hud, pinstrument);
964 // Constructs a HUD_scale "object" and installs it into the hud instrument
967 Hptr fgHUDAddScale( Hptr hud, \
979 double (*load_value)() )
982 HUD_instr *pinstrument;
988 pinstrument = (HIptr)calloc(sizeof(HUD_instr),1);
989 if( pinstrument == NULL ) {
993 pinstrument->type = HUDscale;
995 pscale = ( HUD_scale *)calloc(sizeof(HUD_scale),1);
996 if( pscale == NULL ) {
1000 pscale->sub_type = sub_type;
1001 pscale->scr_pos = scr_pos;
1002 pscale->scr_min = scr_min;
1003 pscale->scr_max = scr_max;
1004 pscale->div_min = div_min;
1005 pscale->div_max = div_max;
1006 pscale->orientation = orientation;
1007 pscale->minimum_value = min_value;
1008 pscale->maximum_value = max_value;
1009 pscale->width_units = width_units;
1010 pscale->load_value = load_value;
1011 // Install the scale
1012 pinstrument->instr = pscale;
1013 // Install the instrument into hud.
1014 add_instrument( hud, pinstrument);
1021 // Constructs a HUD_Label object and installs it into the hud instrument
1023 Hptr fgHUDAddLabel( Hptr hud, \
1032 double (*load_value)() )
1035 HUD_instr *pinstrument;
1041 pinstrument = (HIptr)calloc(sizeof(HUD_instr),1);
1042 if( pinstrument == NULL ) {
1045 pinstrument->type = HUDlabel;
1047 plabel = (HUD_label *)calloc(sizeof(HUD_label),1);
1048 if( plabel == NULL ){
1052 plabel->x_pos = x_pos;
1053 plabel->y_pos = y_pos;
1054 plabel->size = size;
1055 plabel->blink = blink;
1056 plabel->justify = justify;
1057 plabel->pre_str = pre_str;
1058 plabel->post_str = post_str;
1059 plabel->format = format;
1060 plabel->load_value = load_value;
1061 // Install the label
1062 pinstrument->instr = plabel;
1063 // Install the instrument into hud.
1064 add_instrument( hud, pinstrument);
1071 // Contains code that constructs a ladder "object" and installs it as
1072 // a hud instrument in the hud instrument list.
1074 Hptr fgHUDAddLadder( Hptr hud, \
1083 double (*load_roll)(),
1084 double (*load_pitch)() )
1086 HUD_ladder *pladder;
1087 HUD_instr *pinstrument;
1093 pinstrument = (HIptr)calloc(sizeof(HUD_instr),1);
1094 if( pinstrument == NULL )
1097 pinstrument->type = HUDladder;
1099 pladder = (HUD_ladder *)calloc(sizeof(HUD_ladder),1);
1100 if( pladder == NULL )
1103 pladder->type = 0; // Not used.
1104 pladder->x_pos = x_pos;
1105 pladder->y_pos = y_pos;
1106 pladder->scr_width = scr_width;
1107 pladder->scr_height = scr_height;
1108 pladder->scr_hole = hole_len;
1109 pladder->div_units = div_units;
1110 pladder->label_position = label_pos;
1111 pladder->width_units = width_units;
1112 pladder->load_roll = load_roll;
1113 pladder->load_pitch = load_pitch;
1115 pinstrument->instr = pladder;
1116 // Install the instrument into hud.
1117 add_instrument( hud, pinstrument);
1121 // fgHUDAddControlSurfaces()
1123 // Adds the control surface indicators which make up for the lack of seat
1124 // of the pants feel. Should be unnecessary with joystick and pedals
1125 // enabled. But that is another improvement. Also, what of flaps? Spoilers?
1126 // This may need to be expanded or flattened into multiple indicators,
1127 // vertical and horizontal.
1129 Hptr fgHUDAddControlSurfaces( Hptr hud,
1132 double (*load_value)() )
1134 HUD_control_surfaces *pcontrol_surfaces;
1135 HUD_instr *pinstrument;
1142 pinstrument = (HIptr)calloc(sizeof(HUD_instr),1);
1143 if( !pinstrument ) {
1146 pinstrument->type = HUDcontrol_surfaces;
1149 pcontrol_surfaces = (HUD_control_surfaces *)calloc(sizeof(HUD_control),1);
1150 if( !pcontrol_surfaces ) {
1154 pcontrol_surfaces->x_pos = x_pos;
1155 pcontrol_surfaces->y_pos = y_pos;
1156 pcontrol_surfaces->load_value = load_value;
1158 pinstrument->instr = pcontrol_surfaces;
1160 add_instrument( hud, pinstrument);
1169 Hptr fgHUDAddControl( Hptr hud, \
1178 double (*load_value)() )
1180 HUD_control *pcontrol;
1181 HUD_instr *pinstrument;
1188 pinstrument = (HIptr)calloc(sizeof(HUD_instr),1);
1189 if( !pinstrument ) {
1192 pinstrument->type = HUDcontrol;
1195 pcontrol = (HUD_control *)calloc(sizeof(HUD_control),1);
1196 if( !(pcontrol == NULL) ) {
1199 pcontrol->ctrl_x = ctrl_x;
1200 pcontrol->ctrl_y = ctrl_y;
1201 pcontrol->ctrl_length = ctrl_length;
1202 pcontrol->orientation = orientation;
1203 pcontrol->alignment = alignment;
1204 pcontrol->min_value = min_value;
1205 pcontrol->max_value = max_value;
1206 pcontrol->width_units = width_units;
1207 pcontrol->load_value = load_value;
1209 pinstrument->instr = pcontrol;
1211 add_instrument( hud, pinstrument);
1217 Hptr fgHUDAddMovingHorizon( Hptr hud, \
1227 Hptr fgHUDAddCircularLadder( Hptr hud, \
1237 Hptr fgHUDAddNumDisp( Hptr hud, \
1252 // Performs a once around the list of calls to instruments installed in
1253 // the HUD object with requests for redraw. Kinda. It will when this is
1257 void fgUpdateHUD( Hptr hud ) {
1260 glMatrixMode(GL_PROJECTION);
1264 gluOrtho2D(0, 640, 0, 480);
1265 glMatrixMode(GL_MODELVIEW);
1269 glColor3f(1.0, 1.0, 1.0);
1272 glDisable(GL_DEPTH_TEST);
1273 glDisable(GL_LIGHTING);
1277 if( hud->time_of_day==DAY) {
1278 switch (hud->brightness) {
1280 glColor3f (0.1, 0.9, 0.1);
1283 glColor3f (0.1, 0.7, 0.0);
1286 glColor3f (0.0, 0.5, 0.0);
1289 else if( hud->time_of_day==NIGHT) {
1290 switch (hud->brightness) {
1292 glColor3f (0.9, 0.1, 0.1);
1295 glColor3f (0.7, 0.0, 0.1);
1298 glColor3f (0.5, 0.0, 0.0);
1302 fgPrintf( FG_COCKPIT, FG_DEBUG, "HUD Code %d Status %d\n",
1303 hud->code, hud->status );
1305 phud_instr = hud->instruments;
1306 while( phud_instr ) {
1307 /* printf("Drawing Instrument %d\n", phud_instr->type); */
1309 switch (phud_instr->type) {
1310 case HUDhorizon: // ARTIFICIAL HORIZON
1311 drawhorizon( (pHUDhorizon)phud_instr->instr );
1314 case HUDscale: // Need to simplify this call.
1315 drawscale ( (pHUDscale) phud_instr->instr );
1319 drawlabel ( (pHUDlabel) phud_instr->instr );
1323 drawladder( (pHUDladder) phud_instr->instr );
1327 // drawControl( (pHUDcontrol) phud_instr->instr );
1330 case HUDcontrol_surfaces:
1331 drawControlSurfaces( (pHUDControlSurfaces) phud_instr->instr );
1334 default:; // Ignore anything you don't know about.
1337 phud_instr = phud_instr->next;
1340 glEnable(GL_DEPTH_TEST);
1341 glEnable(GL_LIGHTING);
1342 glMatrixMode(GL_PROJECTION);
1344 glMatrixMode(GL_MODELVIEW);
1348 void fgHUDSetTimeMode( Hptr hud, int time_of_day )
1351 hud->time_of_day = time_of_day;
1355 void fgHUDSetBrightness( Hptr hud, int brightness )
1358 hud->brightness = brightness;
1363 /* Revision 1.16 1998/02/19 13:05:49 curt
1364 /* Incorporated some HUD tweaks from Michelle America.
1365 /* Tweaked the sky's sunset/rise colors.
1366 /* Other misc. tweaks.
1368 * Revision 1.15 1998/02/16 13:38:39 curt
1369 * Integrated changes from Charlie Hotchkiss.
1371 * Revision 1.14 1998/02/12 21:59:41 curt
1372 * Incorporated code changes contributed by Charlie Hotchkiss
1373 * <chotchkiss@namg.us.anritsu.com>
1375 * Revision 1.12 1998/02/09 15:07:48 curt
1378 * Revision 1.11 1998/02/07 15:29:34 curt
1379 * Incorporated HUD changes and struct/typedef changes from Charlie Hotchkiss
1380 * <chotchkiss@namg.us.anritsu.com>
1382 * Revision 1.10 1998/02/03 23:20:14 curt
1383 * Lots of little tweaks to fix various consistency problems discovered by
1384 * Solaris' CC. Fixed a bug in fg_debug.c with how the fgPrintf() wrapper
1385 * passed arguments along to the real printf(). Also incorporated HUD changes
1386 * by Michele America.
1388 * Revision 1.9 1998/01/31 00:43:04 curt
1389 * Added MetroWorks patches from Carmen Volpe.
1391 * Revision 1.8 1998/01/27 00:47:51 curt
1392 * Incorporated Paul Bleisch's <bleisch@chromatic.com> new debug message
1393 * system and commandline/config file processing code.
1395 * Revision 1.7 1998/01/19 18:40:20 curt
1396 * Tons of little changes to clean up the code and to remove fatal errors
1397 * when building with the c++ compiler.
1399 * Revision 1.6 1997/12/15 23:54:34 curt
1400 * Add xgl wrappers for debugging.
1401 * Generate terrain normals on the fly.
1403 * Revision 1.5 1997/12/10 22:37:39 curt
1404 * Prepended "fg" on the name of all global structures that didn't have it yet.
1405 * i.e. "struct WEATHER {}" became "struct fgWEATHER {}"
1407 * Revision 1.4 1997/09/23 00:29:32 curt
1408 * Tweaks to get things to compile with gcc-win32.
1410 * Revision 1.3 1997/09/05 14:17:26 curt
1411 * More tweaking with stars.
1413 * Revision 1.2 1997/09/04 02:17:30 curt
1416 * Revision 1.1 1997/08/29 18:03:22 curt