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 fgHUDAddHorizon( hud, 590, 50, 40, 20, get_roll );
861 fgHUDAddLadder ( hud, 330, 190, 90, 180, 70, 10,
862 NONE, 45, get_roll, get_pitch );
863 fgHUDAddScale ( hud, VERTICAL, LIMIT, 220, 100, 280, 5, 10,
864 LEFT, 0, 100, 50, get_speed );
865 fgHUDAddScale ( hud, VERTICAL, NOLIMIT, 440, 100, 280, 1, 5,
866 RIGHT, -40, 50, 25, get_aoa );
867 fgHUDAddScale ( hud, HORIZONTAL, NOLIMIT, 280, 220, 440, 5, 10,
868 TOP, 0, 50, 50, get_heading );
869 fgHUDAddLabel ( hud, 180, 85, SMALL, NOBLINK,
870 RIGHT_JUST, NULL, " Kts", "%5.0f", get_speed );
871 fgHUDAddLabel ( hud, 180, 73, SMALL, NOBLINK,
872 RIGHT_JUST, NULL, " m", "%5.0f", get_altitude );
873 fgHUDAddControlSurfaces( hud, 10, 10, NULL );
875 // fgHUDAddControl( hud, HORIZONTAL, 50, 25, get_aileronval ); // was 10, 10
876 // fgHUDAddControl( hud, VERTICAL, 150, 25, get_elevatorval ); // was 10, 10
877 // fgHUDAddControl( hud, HORIZONTAL, 250, 25, get_rudderval ); // was 10, 10
885 // This is a stand in for linked list code that will get replaced later
886 // by some more elegant list handling code.
888 void add_instrument( Hptr hud, HIptr pinstrument )
890 if( !hud || !pinstrument ) {
894 pinstrument->next = hud->instruments;
895 hud->instruments = pinstrument;
901 // Constructs a HUD_horizon "object" and installs it into the hud instrument
904 Hptr fgHUDAddHorizon( Hptr hud, \
909 double (*load_value)() )
911 HUD_horizon *phorizon;
912 HUD_instr *pinstrument;
917 // construct the parent object
918 pinstrument = (HIptr)calloc(sizeof(HUD_instr),1);
919 if( pinstrument == NULL ) {
922 pinstrument->type = HUDhorizon; // ARTIFICIAL_HORIZON;
924 // Construct the horizon
925 phorizon = (HUD_horizon *) calloc( sizeof(HUD_horizon),1);
926 if( phorizon == NULL ) {
930 phorizon->x_pos = x_pos;
931 phorizon->y_pos = y_pos;
932 phorizon->scr_width = length;
933 phorizon->scr_hole = hole_len;
934 phorizon->load_value = load_value;
935 // Install the horizon in the parent.
936 pinstrument->instr = phorizon;
937 // Install the instrument into hud.
938 add_instrument( hud, pinstrument);
945 // Constructs a HUD_scale "object" and installs it into the hud instrument
948 Hptr fgHUDAddScale( Hptr hud, \
960 double (*load_value)() )
963 HUD_instr *pinstrument;
969 pinstrument = (HIptr)calloc(sizeof(HUD_instr),1);
970 if( pinstrument == NULL ) {
974 pinstrument->type = HUDscale;
976 pscale = ( HUD_scale *)calloc(sizeof(HUD_scale),1);
977 if( pscale == NULL ) {
981 pscale->sub_type = sub_type;
982 pscale->scr_pos = scr_pos;
983 pscale->scr_min = scr_min;
984 pscale->scr_max = scr_max;
985 pscale->div_min = div_min;
986 pscale->div_max = div_max;
987 pscale->orientation = orientation;
988 pscale->minimum_value = min_value;
989 pscale->maximum_value = max_value;
990 pscale->width_units = width_units;
991 pscale->load_value = load_value;
993 pinstrument->instr = pscale;
994 // Install the instrument into hud.
995 add_instrument( hud, pinstrument);
1002 // Constructs a HUD_Label object and installs it into the hud instrument
1004 Hptr fgHUDAddLabel( Hptr hud, \
1013 double (*load_value)() )
1016 HUD_instr *pinstrument;
1022 pinstrument = (HIptr)calloc(sizeof(HUD_instr),1);
1023 if( pinstrument == NULL ) {
1026 pinstrument->type = HUDlabel;
1028 plabel = (HUD_label *)calloc(sizeof(HUD_label),1);
1029 if( plabel == NULL ){
1033 plabel->x_pos = x_pos;
1034 plabel->y_pos = y_pos;
1035 plabel->size = size;
1036 plabel->blink = blink;
1037 plabel->justify = justify;
1038 plabel->pre_str = pre_str;
1039 plabel->post_str = post_str;
1040 plabel->format = format;
1041 plabel->load_value = load_value;
1042 // Install the label
1043 pinstrument->instr = plabel;
1044 // Install the instrument into hud.
1045 add_instrument( hud, pinstrument);
1052 // Contains code that constructs a ladder "object" and installs it as
1053 // a hud instrument in the hud instrument list.
1055 Hptr fgHUDAddLadder( Hptr hud, \
1064 double (*load_roll)(),
1065 double (*load_pitch)() )
1067 HUD_ladder *pladder;
1068 HUD_instr *pinstrument;
1074 pinstrument = (HIptr)calloc(sizeof(HUD_instr),1);
1075 if( pinstrument == NULL )
1078 pinstrument->type = HUDladder;
1080 pladder = (HUD_ladder *)calloc(sizeof(HUD_ladder),1);
1081 if( pladder == NULL )
1084 pladder->type = 0; // Not used.
1085 pladder->x_pos = x_pos;
1086 pladder->y_pos = y_pos;
1087 pladder->scr_width = scr_width;
1088 pladder->scr_height = scr_height;
1089 pladder->scr_hole = hole_len;
1090 pladder->div_units = div_units;
1091 pladder->label_position = label_pos;
1092 pladder->width_units = width_units;
1093 pladder->load_roll = load_roll;
1094 pladder->load_pitch = load_pitch;
1096 pinstrument->instr = pladder;
1097 // Install the instrument into hud.
1098 add_instrument( hud, pinstrument);
1102 // fgHUDAddControlSurfaces()
1104 // Adds the control surface indicators which make up for the lack of seat
1105 // of the pants feel. Should be unnecessary with joystick and pedals
1106 // enabled. But that is another improvement. Also, what of flaps? Spoilers?
1107 // This may need to be expanded or flattened into multiple indicators,
1108 // vertical and horizontal.
1110 Hptr fgHUDAddControlSurfaces( Hptr hud,
1113 double (*load_value)() )
1115 HUD_control_surfaces *pcontrol_surfaces;
1116 HUD_instr *pinstrument;
1123 pinstrument = (HIptr)calloc(sizeof(HUD_instr),1);
1124 if( !pinstrument ) {
1127 pinstrument->type = HUDcontrol_surfaces;
1130 pcontrol_surfaces = (HUD_control_surfaces *)calloc(sizeof(HUD_control),1);
1131 if( !pcontrol_surfaces ) {
1135 pcontrol_surfaces->x_pos = x_pos;
1136 pcontrol_surfaces->y_pos = y_pos;
1137 pcontrol_surfaces->load_value = load_value;
1139 pinstrument->instr = pcontrol_surfaces;
1141 add_instrument( hud, pinstrument);
1150 Hptr fgHUDAddControl( Hptr hud, \
1159 double (*load_value)() )
1161 HUD_control *pcontrol;
1162 HUD_instr *pinstrument;
1169 pinstrument = (HIptr)calloc(sizeof(HUD_instr),1);
1170 if( !pinstrument ) {
1173 pinstrument->type = HUDcontrol;
1176 pcontrol = (HUD_control *)calloc(sizeof(HUD_control),1);
1177 if( !(pcontrol == NULL) ) {
1180 pcontrol->ctrl_x = ctrl_x;
1181 pcontrol->ctrl_y = ctrl_y;
1182 pcontrol->ctrl_length = ctrl_length;
1183 pcontrol->orientation = orientation;
1184 pcontrol->alignment = alignment;
1185 pcontrol->min_value = min_value;
1186 pcontrol->max_value = max_value;
1187 pcontrol->width_units = width_units;
1188 pcontrol->load_value = load_value;
1190 pinstrument->instr = pcontrol;
1192 add_instrument( hud, pinstrument);
1198 Hptr fgHUDAddMovingHorizon( Hptr hud, \
1208 Hptr fgHUDAddCircularLadder( Hptr hud, \
1218 Hptr fgHUDAddNumDisp( Hptr hud, \
1233 // Performs a once around the list of calls to instruments installed in
1234 // the HUD object with requests for redraw. Kinda. It will when this is
1238 void fgUpdateHUD( Hptr hud ) {
1241 glMatrixMode(GL_PROJECTION);
1245 gluOrtho2D(0, 640, 0, 480);
1246 glMatrixMode(GL_MODELVIEW);
1250 glColor3f(1.0, 1.0, 1.0);
1253 glDisable(GL_DEPTH_TEST);
1254 glDisable(GL_LIGHTING);
1257 glColor3f (0.1, 0.9, 0.1);
1259 fgPrintf( FG_COCKPIT, FG_DEBUG, "HUD Code %d Status %d\n",
1260 hud->code, hud->status );
1262 phud_instr = hud->instruments;
1263 while( phud_instr ) {
1264 /* printf("Drawing Instrument %d\n", phud_instr->type); */
1266 switch (phud_instr->type) {
1267 case HUDhorizon: // ARTIFICIAL HORIZON
1268 drawhorizon( (pHUDhorizon)phud_instr->instr );
1271 case HUDscale: // Need to simplify this call.
1272 drawscale ( (pHUDscale) phud_instr->instr );
1276 drawlabel ( (pHUDlabel) phud_instr->instr );
1280 drawladder( (pHUDladder) phud_instr->instr );
1284 // drawControl( (pHUDcontrol) phud_instr->instr );
1287 case HUDcontrol_surfaces:
1288 drawControlSurfaces( (pHUDControlSurfaces) phud_instr->instr );
1291 default:; // Ignore anything you don't know about.
1294 phud_instr = phud_instr->next;
1297 glEnable(GL_DEPTH_TEST);
1298 glEnable(GL_LIGHTING);
1299 glMatrixMode(GL_PROJECTION);
1301 glMatrixMode(GL_MODELVIEW);
1307 /* Revision 1.15 1998/02/16 13:38:39 curt
1308 /* Integrated changes from Charlie Hotchkiss.
1310 * Revision 1.14 1998/02/12 21:59:41 curt
1311 * Incorporated code changes contributed by Charlie Hotchkiss
1312 * <chotchkiss@namg.us.anritsu.com>
1314 * Revision 1.12 1998/02/09 15:07:48 curt
1317 * Revision 1.11 1998/02/07 15:29:34 curt
1318 * Incorporated HUD changes and struct/typedef changes from Charlie Hotchkiss
1319 * <chotchkiss@namg.us.anritsu.com>
1321 * Revision 1.10 1998/02/03 23:20:14 curt
1322 * Lots of little tweaks to fix various consistency problems discovered by
1323 * Solaris' CC. Fixed a bug in fg_debug.c with how the fgPrintf() wrapper
1324 * passed arguments along to the real printf(). Also incorporated HUD changes
1325 * by Michele America.
1327 * Revision 1.9 1998/01/31 00:43:04 curt
1328 * Added MetroWorks patches from Carmen Volpe.
1330 * Revision 1.8 1998/01/27 00:47:51 curt
1331 * Incorporated Paul Bleisch's <bleisch@chromatic.com> new debug message
1332 * system and commandline/config file processing code.
1334 * Revision 1.7 1998/01/19 18:40:20 curt
1335 * Tons of little changes to clean up the code and to remove fatal errors
1336 * when building with the c++ compiler.
1338 * Revision 1.6 1997/12/15 23:54:34 curt
1339 * Add xgl wrappers for debugging.
1340 * Generate terrain normals on the fly.
1342 * Revision 1.5 1997/12/10 22:37:39 curt
1343 * Prepended "fg" on the name of all global structures that didn't have it yet.
1344 * i.e. "struct WEATHER {}" became "struct fgWEATHER {}"
1346 * Revision 1.4 1997/09/23 00:29:32 curt
1347 * Tweaks to get things to compile with gcc-win32.
1349 * Revision 1.3 1997/09/05 14:17:26 curt
1350 * More tweaking with stars.
1352 * Revision 1.2 1997/09/04 02:17:30 curt
1355 * Revision 1.1 1997/08/29 18:03:22 curt