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.h>
49 #include <Scenery/scenery.hxx>
50 #include <Time/fg_timer.hxx>
51 #include <Weather/weather.h>
55 // The following routines obtain information concerntin the aircraft's
56 // current state and return it to calling instrument display routines.
57 // They should eventually be member functions of the aircraft.
60 //using namespace std;
69 instr_ptr ( instr_item * pHudInstr = 0) : pHI( pHudInstr){}
70 ~instr_ptr() { if( pHI ) delete pHI; }
71 instr_ptr & operator = (const instr_ptr & rhs);
72 instr_ptr( const instr_ptr & image );
77 operator = ( const instr_ptr & rhs )
79 if( !(this == &rhs )) {
80 pHI = new instr_item( *(rhs.pHI));
86 instr_ptr ( const instr_ptr & image ) :
88 pHI = new instr_item( *(image.pHI));
91 deque< instr_item * > HUD_deque;
97 locRECT( UINT left, UINT top, UINT right, UINT bottom);
98 RECT get_rect(void) { return rect;}
101 locRECT :: locRECT( UINT left, UINT top, UINT right, UINT bottom)
106 rect.bottom = bottom;
111 // #define drawOneLine(x1,y1,x2,y2) glBegin(GL_LINES);
112 // glVertex2f ((x1),(y1)); glVertex2f ((x2),(y2)); glEnd();
115 void drawOneLine( UINT x1, UINT y1, UINT x2, UINT y2)
123 void drawOneLine( RECT &rect)
126 glVertex2f(rect.left, rect.top);
127 glVertex2f(rect.right, rect.bottom);
132 // The following code deals with painting the "instrument" on the display
134 /* textString - Bitmap font string */
136 static void textString(int x, int y, char *msg, void *font)
140 glutBitmapCharacter(font, *msg);
145 /* strokeString - Stroke font string */
147 static void strokeString(int x, int y, char *msg, void *font)
150 glTranslatef(x, y, 0);
151 glScalef(.04, .04, .04);
153 glutStrokeCharacter(font, *msg);
162 // Abstract Base Class instr_item
164 UINT instr_item :: instances; // Initial value of zero
166 // constructor ( No default provided )
169 instr_item( RECT scr_pos,
170 DBLFNPTR data_source,
171 ReadOriented orientation,
173 handle ( ++instances ),
174 scrn_pos ( scr_pos ),
175 load_value_fn ( data_source ),
176 oriented ( orientation ),
177 is_enabled ( working ),
179 brightness ( BRT_DARK )
181 int hitemp, widetemp;
184 // Check for inverted rect coords. We must have top/right > bottom
185 // left corners or derived classes will draw their boxes very oddly.
186 // This is the only place we can reliably validate this data. Note
187 // that the box may be entirely or partly located off the screen.
188 // This needs consideration and possibly a member function to move
189 // the box, a keen idea for supporting "editing" of the HUD.
190 if( scrn_pos.top < scrn_pos.bottom ) {
191 xtemp = scrn_pos.bottom;
192 scrn_pos.bottom = scrn_pos.top;
193 scrn_pos.top = xtemp;
195 if( scrn_pos.left > scrn_pos.right ) {
196 xtemp = scrn_pos.left;
197 scrn_pos.left = scrn_pos.right;
198 scrn_pos.right = xtemp;
201 // Insure that the midpoint marker will fall exactly at the
202 // middle of the bar.
203 if( !((scr_pos.top-scr_pos.bottom) % 2)) {
206 if( !((scr_pos.right - scr_pos.left ) % 2)) {
209 // Set up convenience values for centroid of the box and
210 // the span values according to orientation
212 hitemp = scr_pos.top - scr_pos.bottom;
213 widetemp = scr_pos.right - scr_pos.left;
214 if((orientation == ReadTOP) || (orientation == ReadBOTTOM)) {
220 // Here we work out the centroid for the corrected box.
221 mid_span.x = scr_pos.left + ((scr_pos.right - scr_pos.left) >> 1);
222 mid_span.y = scr_pos.bottom + ((scr_pos.top - scr_pos.bottom) >> 1);
227 instr_item ( const instr_item & image ):
228 handle ( ++instances ),
229 scrn_pos ( image.scrn_pos ),
230 load_value_fn( image.load_value_fn),
231 oriented ( image.oriented ),
232 is_enabled ( image.is_enabled ),
233 broken ( image.broken ),
234 brightness ( image.brightness ),
235 scr_span ( image.scr_span ),
236 mid_span ( image.mid_span )
240 // assignment operator
242 instr_item & instr_item :: operator = ( const instr_item & rhs )
244 if( !(this == &rhs )) { // Not an identity assignment
245 scrn_pos = rhs.scrn_pos;
246 load_value_fn = rhs.load_value_fn;
247 oriented = rhs.oriented;
248 is_enabled = rhs.is_enabled;
250 brightness = rhs.brightness;
257 instr_item :: ~instr_item ()
269 // break_display This is emplaced to provide hooks for making
270 // instruments unreliable. The default behavior is
271 // to simply not display, but more sophisticated behavior is available
272 // by over riding the function which is virtual in this class.
275 break_display ( bool bad )
282 SetBrightness ( int level )
284 brightness = level; // This is all we will do for now. Later the
285 // brightness levels will be sensitive both to
286 // the control knob and the outside light levels
287 // to emulated night vision effects.
290 UINT instr_item :: get_Handle( void )
295 //======================= Top of instr_label class =========================
297 instr_label( RECT region,
298 DBLFNPTR data_source,
299 const char *label_format,
300 const char *pre_label_string,
301 const char *post_label_string,
302 ReadOriented orientation,
303 fgLabelJust justification,
307 instr_item( region, data_source,
308 orientation, working ),
309 pformat ( label_format ),
310 pre_str ( pre_label_string ),
311 post_str ( post_label_string ),
312 justify ( justification ),
313 fontSize ( font_size ),
318 // I put this in to make it easy to construct a class member using the current
322 instr_label :: ~instr_label()
327 instr_label :: instr_label( const instr_label & image) :
328 instr_item((const instr_item &)image),
329 pformat ( image.pformat ),
330 pre_str ( image.pre_str ),
331 post_str ( image.post_str ),
332 blink ( image.blink )
336 instr_label & instr_label ::operator = (const instr_label & rhs )
338 if( !(this == &rhs)) {
339 instr_item::operator = (rhs);
340 pformat = rhs.pformat;
341 fontSize = rhs.fontSize;
343 justify = rhs.justify;
344 pre_str = rhs.pre_str;
345 post_str = rhs.post_str;
352 // draw Draws a label anywhere in the HUD
356 draw( void ) // Required method in base class
358 char format_buffer[80];
359 char label_buffer[80];
362 RECT scrn_rect = get_location();
364 if( pre_str != NULL) {
365 if( post_str != NULL ) {
366 sprintf( format_buffer, "%s%s%s", pre_str, pformat, post_str );
369 sprintf( format_buffer, "%s%s", pre_str, pformat );
373 if( post_str != NULL ) {
374 sprintf( format_buffer, "%s%s", pformat, post_str );
376 } // else do nothing if both pre and post strings are nulls. Interesting.
378 sprintf( label_buffer, format_buffer, get_value() );
380 fgPrintf( FG_COCKPIT, FG_DEBUG, format_buffer );
381 fgPrintf( FG_COCKPIT, FG_DEBUG, "\n" );
382 fgPrintf( FG_COCKPIT, FG_DEBUG, label_buffer );
383 fgPrintf( FG_COCKPIT, FG_DEBUG, "\n" );
385 lenstr = strlen( label_buffer );
387 posincr = 0; // default to RIGHT_JUST ... center located calc: -lenstr*8;
389 if( justify == CENTER_JUST ) {
390 posincr = - (lenstr << 2); // -lenstr*4;
393 if( justify == LEFT_JUST ) {
394 posincr = - (lenstr << 8); // 0;
398 if( fontSize == SMALL ) {
399 textString( scrn_rect.left + posincr, scrn_rect.bottom,
400 label_buffer, GLUT_BITMAP_8_BY_13);
403 if( fontSize == LARGE ) {
404 textString( scrn_rect.left + posincr, scrn_rect.bottom,
405 label_buffer, GLUT_BITMAP_9_BY_15);
410 //============== Top of instr_scale class memeber definitions ===============
413 // 1. instr_scales divide the specified location into half and then
414 // the half opposite the read direction in half again. A bar is
415 // then drawn along the second divider. Scale ticks are drawn
416 // between the middle and quarter section lines (minor division
417 // markers) or just over the middle line.
419 // 2. This class was not intended to be instanciated. See moving_scale
420 // and guage_instr classes.
421 //============================================================================
423 instr_scale ( RECT the_box,
433 instr_item( the_box, load_fn, orient, working),
434 range_shown ( show_range ),
435 Maximum_value( maxValue ),
436 Minimum_value( minValue ),
437 Maj_div ( major_divs ),
438 Min_div ( minor_divs ),
443 scale_factor = (double)get_span() / range_shown;
444 if( show_range < 0 ) {
445 range_shown = -range_shown;
447 temp = (Maximum_value - Minimum_value) / 100;
448 if( range_shown < temp ) {
454 instr_scale( const instr_scale & image ) :
455 instr_item( (const instr_item &) image),
456 range_shown ( image.range_shown ),
457 Maximum_value( image.Maximum_value ),
458 Minimum_value( image.Minimum_value ),
459 Maj_div ( image.Maj_div ),
460 Min_div ( image.Min_div ),
461 Modulo ( image.Modulo ),
462 scale_factor ( image.scale_factor )
466 instr_scale & instr_scale :: operator = (const instr_scale & rhs )
468 if( !(this == &rhs)) {
469 instr_item::operator = (rhs);
470 Minimum_value = rhs.Minimum_value;
471 Maximum_value = rhs.Maximum_value;
472 Maj_div = rhs.Maj_div;
473 Min_div = rhs.Min_div;
475 scale_factor = rhs.scale_factor;
476 range_shown = rhs.range_shown;
481 instr_scale :: ~ instr_scale () {}
483 //========== Top of moving_scale_instr class member definitions =============
486 moving_scale( RECT the_box,
487 DBLFNPTR data_source,
488 ReadOriented orientation,
496 instr_scale( the_box,
497 data_source, orientation,
499 max_value, min_value,
500 major_divs, minor_divs, modulus,
502 val_span ( value_span)
504 half_width_units = range_to_show() / 2.0;
511 moving_scale( const moving_scale & image):
512 instr_scale( (const instr_scale & ) image)
516 moving_scale & moving_scale ::
517 operator = (const moving_scale & rhs )
519 if( !( this == &rhs)){
520 instr_scale::operator = (rhs);
526 draw( void ) // (HUD_scale * pscale )
535 POINT mid_scr = get_centroid();
536 POINT bias_bar; // eliminates some orientation checks
537 double cur_value = get_value();
538 RECT scrn_rect = get_location();
539 ReadOriented orientation = get_orientation();
541 vmin = cur_value - half_width_units; // width units == needle travel
542 vmax = cur_value + half_width_units; // or picture unit span.
545 if( (orientation == ReadLEFT) ||( orientation == ReadRIGHT)) // Vertical scale
547 if( orientation == ReadLEFT ) { // Calculate x marker offset
548 marker_x = scrn_rect.left - 6;
549 bias_bar.x = ((scrn_rect.right - mid_scr.x)>>1) + mid_scr.x;
551 else { // We'll default this for now.
552 marker_x = mid_scr.x; // scrn_rect.right;
553 bias_bar.x = ((mid_scr.x - scrn_rect.left)>>1) + scrn_rect.left;
556 // Draw the basic markings for the scale...
558 drawOneLine( bias_bar.x, // Vertical scale bar
564 if( orientation == ReadLEFT )
567 drawOneLine( bias_bar.x, // Bottom tick bar
572 drawOneLine( bias_bar.x, // Top tick bar
577 drawOneLine( scrn_rect.right, // Middle tick bar /Index
584 drawOneLine( bias_bar.x,
589 drawOneLine( bias_bar.x,
594 drawOneLine( scrn_rect.left,
600 // Work through from bottom to top of scale. Calculating where to put
601 // minor and major ticks.
603 for( i = (int)vmin; i <= (int)vmax; i++ )
605 // if( sub_type == LIMIT ) { // Don't show ticks
606 condition = (i >= min_val()); // below Minimum value.
609 // if( sub_type == NOLIMIT ) {
613 if( condition ) // Show a tick if necessary
615 // Calculate the location of this tick
616 marker_y = scrn_rect.bottom + (int)((i - vmin) * factor());
618 // Block calculation artifact from drawing ticks below min coordinate.
619 // Calculation here accounts for text height.
621 if( marker_y < (scrn_rect.bottom + 4)) { // Magic number!!!
625 if( (i%div_min()) == 0) {
626 // if( orientation == ReadLEFT )
628 // drawOneLine( marker_x + 3, marker_y, marker_x + 6, marker_y );
629 drawOneLine( bias_bar.x, marker_y, mid_scr.x, marker_y );
632 // if( orientation == ReadRIGHT )
634 // drawOneLine( marker_x, marker_y, marker_x + 3, marker_y );
635 // drawOneLine( bias_bar.x, marker_y, mid_scr.x, marker_y );
641 if( (i%div_max()) == 0 ) {
642 // drawOneLine( marker_x, marker_y,
643 // marker_x + 6, marker_y );
645 disp_val = i % modulo();
647 disp_val += modulo();
653 sprintf( TextScale, "%d", disp_val );
654 if( orientation == ReadLEFT ) {
655 drawOneLine( mid_scr.x - 3, marker_y, bias_bar.x, marker_y );
657 textString( marker_x - 8 * strlen(TextScale) - 2, marker_y - 4,
658 TextScale, GLUT_BITMAP_8_BY_13 );
661 drawOneLine( mid_scr.x + 3, marker_y, bias_bar.x, marker_y );
662 textString( marker_x + 10, marker_y - 4,
663 TextScale, GLUT_BITMAP_8_BY_13 );
664 } // Else read oriented right
665 } // End if modulo division by major interval is zero
666 } // End if major interval divisor non-zero
667 } // End if condition
668 } // End for range of i from vmin to vmax
669 } // End if VERTICAL SCALE TYPE
670 else { // Horizontal scale by default
672 if( orientation == ReadTOP ) {
673 bias_bar.y = ((mid_scr.y - scrn_rect.bottom)>>1 ) + scrn_rect.bottom;
674 marker_y = bias_bar.y; // Don't use now
676 else { // We will assume no other possibility at this time.
677 bias_bar.y = ((scrn_rect.top - mid_scr.y)>>1 ) + mid_scr.y;
678 marker_y = bias_bar.y; // Don't use now
681 drawOneLine( scrn_rect.left,
686 if( orientation == ReadTOP )
688 drawOneLine( scrn_rect.left,
693 drawOneLine( scrn_rect.right,
698 drawOneLine( mid_scr.x,
705 if( orientation == ReadBOTTOM )
707 drawOneLine( scrn_rect.left,
712 drawOneLine( scrn_rect.right,
717 drawOneLine( mid_scr.x,
724 for( i = (int)vmin; i <= (int)vmax; i++ ) // increment is faster than addition
726 // if( sub_type == LIMIT ) {
727 condition = (i >= min_val());
730 // if( sub_type == NOLIMIT ) {
735 marker_x = scrn_rect.left + (int)((i - vmin) * factor());
737 if( (i%(int)div_min()) == 0 ) {
738 // if( orientation == ReadTOP )
740 // drawOneLine( marker_x, marker_y, marker_x, marker_y + 3 );
741 drawOneLine( marker_x, bias_bar.y, marker_x, mid_scr.y );
744 // drawOneLine( marker_x, marker_y + 3, marker_x, marker_y + 6 );
745 // drawOneLine( marker_x, bias_bar.y, marker_x, mid_scr.y );
750 if( (i%(int)div_max())==0 )
753 disp_val = i % modulo();
755 disp_val += modulo();
761 sprintf( TextScale, "%d", disp_val );
762 if( orientation == ReadTOP )
764 // drawOneLine( marker_x, marker_y, marker_x, marker_y+6 );
765 drawOneLine( marker_x, mid_scr.y + 3,marker_x, bias_bar.y );
766 textString ( marker_x - 4 * strlen(TextScale), marker_y + 14,
767 TextScale, GLUT_BITMAP_8_BY_13 );
770 // drawOneLine( marker_x, marker_y, marker_x, marker_y+6 );
771 drawOneLine( marker_x, mid_scr.y - 3,marker_x, bias_bar.y );
772 textString ( marker_x - 4 * strlen(TextScale), mid_scr.y - 14,
773 TextScale, GLUT_BITMAP_8_BY_13 );
783 //============== Top of guage_instr class member definitions ==============
786 guage_instr( RECT the_box,
788 ReadOriented readway,
795 instr_scale( the_box,
797 maxValue, maxValue, minValue,
798 major_divs, minor_divs,
810 guage_instr( const guage_instr & image):
811 instr_scale( (instr_scale &) image)
815 guage_instr & guage_instr ::
816 operator = (const guage_instr & rhs )
818 if( !(this == &rhs)) {
819 instr_scale::operator = (rhs);
824 // As implemented, draw only correctly draws a horizontal or vertical
825 // scale. It should contain a variation that permits clock type displays.
826 // Now is supports "tickless" displays such as control surface indicators.
827 // This routine should be worked over before using. Current value would be
828 // fetched and not used if not commented out. Clearly that is intollerable.
830 void guage_instr :: draw (void)
838 double vmin = min_val();
839 double vmax = max_val();
840 POINT mid_scr = get_centroid();
841 // double cur_value = get_value();
842 RECT scrn_rect = get_location();
843 ReadOriented orientation = get_orientation();
845 if( (orientation == ReadLEFT) ||( orientation == ReadRIGHT)) // Vertical scale
847 mid_scr = get_centroid();
848 if( orientation == ReadLEFT ) // Calculate x marker offset
849 marker_x = scrn_rect.left - 6;
850 else // We'll default this for now.
851 marker_x = scrn_rect.right;
853 // Draw the basic markings for the scale...
855 if( orientation == ReadLEFT )
858 drawOneLine( scrn_rect.right - 3, // Bottom tick bar
863 drawOneLine( scrn_rect.right - 3, // Top tick bar
869 drawOneLine( scrn_rect.right,
874 drawOneLine( scrn_rect.right,
880 // Work through from bottom to top of scale. Calculating where to put
881 // minor and major ticks.
883 for( i = (int)vmin; i <= (int)vmax; i++ )
885 // Calculate the location of this tick
886 marker_y = scrn_rect.bottom + (int)((i - vmin) * factor());
889 if( (i%div_min()) == 0) {
890 if( orientation == ReadLEFT )
892 drawOneLine( marker_x + 3, marker_y, marker_x + 6, marker_y );
895 drawOneLine( marker_x, marker_y, marker_x + 3, marker_y );
900 if( (i%div_max()) == 0 ) {
901 drawOneLine( marker_x, marker_y,
902 marker_x + 6, marker_y );
904 disp_val = i % modulo();
906 disp_val += modulo();
912 sprintf( TextScale, "%d", disp_val );
913 if( orientation == ReadLEFT ) {
914 textString( marker_x - 8 * strlen(TextScale) - 2, marker_y - 4,
915 TextScale, GLUT_BITMAP_8_BY_13 );
918 if( orientation == ReadRIGHT ) {
919 textString( marker_x + 10, marker_y - 4,
920 TextScale, GLUT_BITMAP_8_BY_13 );
924 } // End if condition
925 } // End for range of i from vmin to vmax
926 } // End if VERTICAL SCALE TYPE
927 else { // Horizontal scale by default
929 if( orientation == ReadTOP ) {
930 marker_y = scrn_rect.bottom;
933 if( orientation == ReadBOTTOM ) {
934 marker_y = scrn_rect.bottom - 6;
937 drawOneLine( scrn_rect.left,
942 if( orientation == ReadTOP )
944 drawOneLine( scrn_rect.left,
947 scrn_rect.bottom + 3 );
949 drawOneLine( scrn_rect.right,
952 scrn_rect.bottom + 6 );
955 if( orientation == ReadBOTTOM )
957 drawOneLine( scrn_rect.left,
960 scrn_rect.bottom - 6 );
962 drawOneLine( scrn_rect.right,
965 scrn_rect.bottom - 6 );
969 for( i = (int)vmin; i <= (int)vmax; i++ ) // increment is faster than addition
971 marker_x = scrn_rect.left + (int)((i - vmin) * factor());
973 if( (i%div_min()) == 0 ) {
974 if( orientation == ReadTOP )
976 drawOneLine( marker_x, marker_y, marker_x, marker_y + 3 );
979 if( orientation == ReadBOTTOM )
981 drawOneLine( marker_x, marker_y + 3, marker_x, marker_y + 6 );
984 } // End if minor tick called for.
985 } // End if minor ticks are of interest
987 if( (i%div_max())==0 )
989 // Modulo implies a "clock" style instrument. Needs work.
991 disp_val = i % modulo();
993 disp_val += modulo();
996 else { // Scale doesn't roll around.
999 sprintf( TextScale, "%d", disp_val );
1000 if( orientation == ReadTOP )
1002 drawOneLine( marker_x, marker_y, marker_x, marker_y+6 );
1003 textString ( marker_x - 4 * strlen(TextScale), marker_y + 14,
1004 TextScale, GLUT_BITMAP_8_BY_13 );
1007 if( orientation == ReadBOTTOM )
1009 drawOneLine( marker_x, marker_y, marker_x, marker_y+6 );
1010 textString ( marker_x - 4 * strlen(TextScale), marker_y - 14,
1011 TextScale, GLUT_BITMAP_8_BY_13 );
1013 } // End else if not ReadTOP
1014 } // End if major division point.
1015 } // End if major divisions of interest.
1021 //============ Top of dual_instr_item class member definitions ============
1024 dual_instr_item ( RECT the_box,
1025 DBLFNPTR chn1_source,
1026 DBLFNPTR chn2_source,
1028 ReadOriented readway ):
1029 instr_item( the_box, chn1_source, readway, working),
1030 alt_data_source( chn2_source )
1035 dual_instr_item( const dual_instr_item & image) :
1036 instr_item ((instr_item &) image ),
1037 alt_data_source( image.alt_data_source)
1041 dual_instr_item & dual_instr_item ::
1042 operator = (const dual_instr_item & rhs )
1044 if( !(this == &rhs)) {
1045 instr_item::operator = (rhs);
1046 alt_data_source = rhs.alt_data_source;
1051 //============ Top of fgTBI_instr class member definitions ==============
1054 fgTBI_instr( RECT the_box,
1055 DBLFNPTR chn1_source,
1056 DBLFNPTR chn2_source,
1061 dual_instr_item( the_box,
1066 BankLimit (maxBankAngle),
1067 SlewLimit (maxSlipAngle),
1068 scr_hole (gap_width )
1072 fgTBI_instr :: ~fgTBI_instr() {}
1074 fgTBI_instr :: fgTBI_instr( const fgTBI_instr & image):
1075 dual_instr_item( (const dual_instr_item &) image),
1076 BankLimit( image.BankLimit),
1077 SlewLimit( image.SlewLimit),
1078 scr_hole ( image.scr_hole )
1082 fgTBI_instr & fgTBI_instr ::
1083 operator = (const fgTBI_instr & rhs )
1085 if( !(this == &rhs)) {
1086 dual_instr_item::operator = (rhs);
1087 BankLimit = rhs.BankLimit;
1088 SlewLimit = rhs.SlewLimit;
1089 scr_hole = rhs.scr_hole;
1095 // Draws a Turn Bank Indicator on the screen
1098 void fgTBI_instr :: draw( void )
1102 int x_t_inc1, y_t_inc1;
1104 int d_bottom_x, d_bottom_y;
1105 int d_right_x, d_right_y;
1106 int d_top_x, d_top_y;
1107 int d_left_x, d_left_y;
1109 int inc_b_x, inc_b_y;
1110 int inc_r_x, inc_r_y;
1111 int inc_t_x, inc_t_y;
1112 int inc_l_x, inc_l_y;
1113 RECT My_box = get_location();
1114 POINT centroid = get_centroid();
1115 int tee_height = My_box.top - My_box.bottom; // Hack, hack.
1117 // struct fgFLIGHT *f = ¤t_aircraft.flight;
1118 double sin_bank, cos_bank;
1119 double bank_angle, sideslip_angle;
1120 double ss_const; // sideslip angle pixels per rad
1122 bank_angle = current_ch2(); // Roll limit +/- 30 degrees
1123 if( bank_angle < -FG_PI_2/3 ) {
1124 bank_angle = -FG_PI_2/3;
1125 }else if( bank_angle > FG_PI_2/3 ) {
1126 bank_angle = FG_PI_2/3;
1128 sideslip_angle = current_ch1(); // Sideslip limit +/- 20 degrees
1129 if( sideslip_angle < -FG_PI/9 ) {
1130 sideslip_angle = -FG_PI/9;
1131 } else if( sideslip_angle > FG_PI/9 ) {
1132 sideslip_angle = FG_PI/9;
1135 // sin_bank = sin( FG_2PI-FG_Phi );
1136 // cos_bank = cos( FG_2PI-FG_Phi );
1137 sin_bank = sin(FG_2PI-bank_angle);
1138 cos_bank = cos(FG_2PI-bank_angle);
1140 x_inc1 = (int)(get_span() * cos_bank);
1141 y_inc1 = (int)(get_span() * sin_bank);
1142 x_inc2 = (int)(scr_hole * cos_bank);
1143 y_inc2 = (int)(scr_hole * sin_bank);
1145 x_t_inc1 = (int)(tee_height * sin_bank);
1146 y_t_inc1 = (int)(tee_height * cos_bank);
1149 d_bottom_y = (int)(-scr_hole);
1150 d_right_x = (int)(scr_hole);
1153 d_top_y = (int)(scr_hole);
1154 d_left_x = (int)(-scr_hole);
1157 ss_const = (get_span()*2)/(FG_2PI/9); // width represents 40 degrees
1159 d_bottom_x += (int)(sideslip_angle*ss_const);
1160 d_right_x += (int)(sideslip_angle*ss_const);
1161 d_left_x += (int)(sideslip_angle*ss_const);
1162 d_top_x += (int)(sideslip_angle*ss_const);
1164 inc_b_x = (int)(d_bottom_x*cos_bank-d_bottom_y*sin_bank);
1165 inc_b_y = (int)(d_bottom_x*sin_bank+d_bottom_y*cos_bank);
1166 inc_r_x = (int)(d_right_x*cos_bank-d_right_y*sin_bank);
1167 inc_r_y = (int)(d_right_x*sin_bank+d_right_y*cos_bank);
1168 inc_t_x = (int)(d_top_x*cos_bank-d_top_y*sin_bank);
1169 inc_t_y = (int)(d_top_x*sin_bank+d_top_y*cos_bank);
1170 inc_l_x = (int)(d_left_x*cos_bank-d_left_y*sin_bank);
1171 inc_l_y = (int)(d_left_x*sin_bank+d_left_y*cos_bank);
1175 drawOneLine( centroid.x - x_inc1, centroid.y - y_inc1, \
1176 centroid.x + x_inc1, centroid.y + y_inc1 );
1180 drawOneLine( centroid.x - x_inc1, centroid.y - y_inc1, \
1181 centroid.x - x_inc2, centroid.y - y_inc2 );
1182 drawOneLine( centroid.x + x_inc2, centroid.y + y_inc2, \
1183 centroid.x + x_inc1, centroid.y + y_inc1 );
1187 drawOneLine( centroid.x + x_inc2, \
1188 centroid.y + y_inc2, \
1189 centroid.x + x_inc2 + x_t_inc1, \
1190 centroid.y + y_inc2 - y_t_inc1 );
1191 drawOneLine( centroid.x - x_inc2, \
1192 centroid.y - y_inc2, \
1193 centroid.x - x_inc2 + x_t_inc1, \
1194 centroid.y - y_inc2 - y_t_inc1 );
1196 // draw sideslip diamond (it is not yet positioned correctly )
1197 drawOneLine( centroid.x + inc_b_x, \
1198 centroid.y + inc_b_y, \
1199 centroid.x + inc_r_x, \
1200 centroid.y + inc_r_y );
1201 drawOneLine( centroid.x + inc_r_x, \
1202 centroid.y + inc_r_y, \
1203 centroid.x + inc_t_x, \
1204 centroid.y + inc_t_y );
1205 drawOneLine( centroid.x + inc_t_x, \
1206 centroid.y + inc_t_y, \
1207 centroid.x + inc_l_x, \
1208 centroid.y + inc_l_y );
1209 drawOneLine( centroid.x + inc_l_x, \
1210 centroid.y + inc_l_y, \
1211 centroid.x + inc_b_x, \
1212 centroid.y + inc_b_y );
1216 //====================== Top of HudLadder Class =======================
1218 HudLadder( RECT the_box,
1219 DBLFNPTR ptch_source,
1220 DBLFNPTR roll_source,
1227 dual_instr_item( the_box,
1232 width_units ( span_units ),
1233 div_units ( major_div < 0? -major_div: major_div ),
1234 minor_div ( minor_div ),
1235 label_pos ( lbl_pos ),
1236 scr_hole ( screen_hole ),
1237 vmax ( span_units/2 ),
1240 if( !width_units ) {
1243 factor = (double)get_span() / (double) width_units;
1252 HudLadder( const HudLadder & image ) :
1253 dual_instr_item( (dual_instr_item &) image),
1254 width_units ( image.width_units ),
1255 div_units ( image.div_units ),
1256 label_pos ( image.label_pos ),
1257 scr_hole ( image.scr_hole ),
1258 vmax ( image.vmax ),
1259 vmin ( image.vmin ),
1260 factor ( image.factor )
1263 HudLadder & HudLadder ::
1264 operator = ( const HudLadder & rhs )
1266 if( !(this == &rhs)) {
1267 (dual_instr_item &)(*this) = (dual_instr_item &)rhs;
1268 width_units = rhs.width_units;
1269 div_units = rhs.div_units;
1270 label_pos = rhs.label_pos;
1271 scr_hole = rhs.scr_hole;
1274 factor = rhs.factor;
1280 // Draws a climb ladder in the center of the HUD
1283 void HudLadder :: draw( void )
1285 double roll_value, pitch_value;
1292 int new_x_ini, new_x_end;
1293 int new_y_ini, new_y_end;
1295 POINT centroid = get_centroid();
1296 RECT box = get_location();
1297 int half_span = (box.right - box.left) >> 1;
1298 char TextLadder[80];
1301 roll_value = current_ch2();
1302 pitch_value = current_ch1() * RAD_TO_DEG;
1304 vmin = (int)(pitch_value - (double)width_units/2.0);
1305 vmax = (int)(pitch_value + (double)width_units/2.0);
1307 scr_min = box.bottom; // centroid.y - ((box.top - box.bottom) >> 1);
1308 // scr_max = box.top; // scr_min + (box.top - box.bottom);
1309 // marker_x = centroid.x - half_span;
1312 drawOneLine( centroid.x - 5, centroid.y, centroid.x, centroid.y + 5);
1313 drawOneLine( centroid.x, centroid.y + 5, centroid.x + 5, centroid.y);
1314 drawOneLine( centroid.x + 5, centroid.y, centroid.x, centroid.y - 5);
1315 drawOneLine( centroid.x, centroid.y - 5, centroid.x - 5, centroid.y);
1317 for( i=(int)vmin; i<=(int)vmax; i+=1 )
1322 marker_y = scr_min + (int)((i-vmin)*factor);
1324 if( i%div_units==0 )
1326 sprintf( TextLadder, "%d", i );
1330 x_ini = centroid.x - half_span;
1333 x_ini = centroid.x - half_span - 10;
1336 x_end = centroid.x + half_span;
1338 new_x_ini = centroid.x + (int)( \
1339 (x_ini - centroid.x) * cos(roll_value) - \
1340 (y_ini - centroid.y) * sin(roll_value));
1341 new_y_ini = centroid.y + (int)( \
1342 (x_ini - centroid.x) * sin(roll_value) + \
1343 (y_ini - centroid.y) * cos(roll_value));
1344 new_x_end = centroid.x + (int)( \
1345 (x_end - centroid.x) * cos(roll_value) - \
1346 (y_end - centroid.y) * sin(roll_value));
1347 new_y_end = centroid.y + (int)( \
1348 (x_end - centroid.x) * sin(roll_value) + \
1349 (y_end - centroid.y) * cos(roll_value));
1353 drawOneLine( new_x_ini, new_y_ini, new_x_end, new_y_end );
1357 glEnable(GL_LINE_STIPPLE);
1358 glLineStipple( 1, 0x00FF );
1359 drawOneLine( new_x_ini, new_y_ini, new_x_end, new_y_end );
1360 glDisable(GL_LINE_STIPPLE);
1362 textString( new_x_ini - 8 * strlen(TextLadder) - 8,
1364 TextLadder, GLUT_BITMAP_8_BY_13 );
1365 textString( new_x_end + 10,
1367 TextLadder, GLUT_BITMAP_8_BY_13 );
1372 x_ini = centroid.x - half_span;
1375 x_ini = centroid.x - half_span - 10;
1378 x_end = centroid.x - half_span + scr_hole/2;
1380 new_x_ini = centroid.x+ (int)( \
1381 (x_ini - centroid.x) * cos(roll_value) -\
1382 (y_ini - centroid.y) * sin(roll_value));
1383 new_y_ini = centroid.y+ (int)( \
1384 (x_ini - centroid.x) * sin(roll_value) +\
1385 (y_ini - centroid.y) * cos(roll_value));
1386 new_x_end = centroid.x+ (int)( \
1387 (x_end - centroid.x) * cos(roll_value) -\
1388 (y_end - centroid.y) * sin(roll_value));
1389 new_y_end = centroid.y+ (int)( \
1390 (x_end - centroid.x) * sin(roll_value) +\
1391 (y_end - centroid.y) * cos(roll_value));
1395 drawOneLine( new_x_ini, new_y_ini, new_x_end, new_y_end );
1399 glEnable(GL_LINE_STIPPLE);
1400 glLineStipple( 1, 0x00FF );
1401 drawOneLine( new_x_ini, new_y_ini, new_x_end, new_y_end );
1402 glDisable(GL_LINE_STIPPLE);
1404 textString( new_x_ini - 8 * strlen(TextLadder) - 8,
1406 TextLadder, GLUT_BITMAP_8_BY_13 );
1408 x_ini = centroid.x + half_span - scr_hole/2;
1411 x_end = centroid.x + half_span;
1414 x_end = centroid.x + half_span + 10;
1417 new_x_ini = centroid.x + (int)( \
1418 (x_ini-centroid.x)*cos(roll_value) -\
1419 (y_ini-centroid.y)*sin(roll_value));
1420 new_y_ini = centroid.y + (int)( \
1421 (x_ini-centroid.x)*sin(roll_value) +\
1422 (y_ini-centroid.y)*cos(roll_value));
1423 new_x_end = centroid.x + (int)( \
1424 (x_end-centroid.x)*cos(roll_value) -\
1425 (y_end-centroid.y)*sin(roll_value));
1426 new_y_end = centroid.y + (int)( \
1427 (x_end-centroid.x)*sin(roll_value) +\
1428 (y_end-centroid.y)*cos(roll_value));
1432 drawOneLine( new_x_ini, new_y_ini, new_x_end, new_y_end );
1436 glEnable(GL_LINE_STIPPLE);
1437 glLineStipple( 1, 0x00FF );
1438 drawOneLine( new_x_ini, new_y_ini, new_x_end, new_y_end );
1439 glDisable(GL_LINE_STIPPLE);
1441 textString( new_x_end+10, new_y_end-4,
1442 TextLadder, GLUT_BITMAP_8_BY_13 );
1446 /* if( i%div_max()==0 )
1448 drawOneLine( marker_x, marker_y, marker_x+6, marker_y );
1449 sprintf( TextScale, "%d", i );
1450 if( orientation == LEFT )
1452 textString( marker_x-8*strlen(TextScale)-2, marker_y-4,
1453 TextScale, GLUT_BITMAP_8_BY_13 );
1455 else if( orientation == RIGHT )
1457 textString( marker_x+10, marker_y-4,
1458 TextScale, GLUT_BITMAP_8_BY_13 );
1466 //========================= End of Class Implementations===================
1469 // Constructs a HUD object and then adds in instruments. At the present
1470 // the instruments are hard coded into the routine. Ultimately these need
1471 // to be defined by the aircraft's instrumentation records so that the
1472 // display for a Piper Cub doesn't show the speed range of a North American
1473 // mustange and the engine readouts of a B36!
1476 #define INSTRDEFS 16
1478 int fgHUDInit( fgAIRCRAFT * /* current_aircraft */ )
1484 fgPrintf( FG_COCKPIT, FG_INFO, "Initializing current aircraft HUD\n" );
1486 HUD_deque.erase( HUD_deque.begin(), HUD_deque.end()); // empty the HUD deque
1491 // For now lets just hardcode the hud here.
1492 // In the future, hud information has to come from the same place
1493 // aircraft information came from.
1495 // fgHUDSetTimeMode( hud, NIGHT );
1496 // fgHUDSetBrightness( hud, BRT_LIGHT );
1498 for( index = 0; index <= INSTRDEFS; index++) {
1501 // fgHUDAddHorizon( hud, 330, 100, 40, 5, 10, get_roll, get_sideslip );
1502 loc.left = 330 - 40;
1504 loc.right = 330 + 40;
1506 HIptr = (instr_item *) new fgTBI_instr( loc );
1509 case 1: // Artificial Horizon
1510 // fgHUDAddLadder ( hud, 330, 285, 120, 180, 70, 10,
1511 // NONE, 45, get_roll, get_pitch );
1512 loc.left = 270; // 330 - 60
1513 loc.top = 375; // 285 + 90
1514 loc.right = 390; // 330 + 60
1515 loc.bottom = 195; // 285 - 90
1516 HIptr = (instr_item *) new HudLadder( loc );
1520 // fgHUDAddScale ( hud, VERTICAL, LIMIT, 200, 180, 380, 5, 10,
1521 // LEFT, 0, 100, 50, 0, get_speed );
1526 HIptr = (instr_item *) new moving_scale( loc,
1536 case 3: // Angle of Attack
1537 // fgHUDAddScale ( hud, HORIZONTAL, NOLIMIT, 180, 250, 410, 1, 5,
1538 // BOTTOM, -40, 50, 21, 0, get_aoa );
1543 HIptr = (instr_item *) new moving_scale( loc,
1553 case 4: // GYRO COMPASS
1554 // fgHUDAddScale ( hud, HORIZONTAL, NOLIMIT, 380, 200, 460, 5, 10,
1555 // TOP, 0, 50, 50, 360, get_heading );
1560 HIptr = (instr_item *) new moving_scale( loc,
1571 // fgHUDAddScale ( hud, VERTICAL, LIMIT, 460, 180, 380, 25, 100,
1572 // RIGHT, 0, 15000, 250, 0, get_altitude);
1577 HIptr = (instr_item *) new moving_scale( loc,
1587 case 6: // Digital KIAS
1588 // fgHUDAddLabel ( hud, 160, 150, SMALL, NOBLINK,
1589 // RIGHT_JUST, NULL, " Kts", "%5.0f", get_speed );
1591 loc.top = 180; // Ignore
1592 loc.right = 200; // Ignore
1594 HIptr = (instr_item *) new instr_label ( loc,
1606 case 7: // Digital Altimeter
1607 // fgHUDAddLabel ( hud, 160, 135, SMALL, NOBLINK,
1608 // RIGHT_JUST, NULL, " m", "%5.0f", get_altitude );
1610 loc.top = 145; // Ignore
1611 loc.right = 200; // Ignore
1613 HIptr = (instr_item *) new instr_label ( loc,
1625 case 8: // Roll indication diagnostic
1626 // fgHUDAddLabel ( hud, 160, 120, SMALL, NOBLINK,
1627 // RIGHT_JUST, NULL, " Roll", "%5.2f", get_roll );
1629 loc.top = 130; // Ignore
1630 loc.right = 200; // Ignore
1632 HIptr = (instr_item *) new instr_label ( loc,
1644 case 9: // Angle of attack diagnostic
1645 // fgHUDAddLabel ( hud, 440, 150, SMALL, NOBLINK,
1646 // RIGHT_JUST, NULL, " AOA", "%5.2f", get_aoa );
1648 loc.top = 160; // Ignore
1649 loc.right = 500; // Ignore
1651 HIptr = (instr_item *) new instr_label ( loc,
1664 // fgHUDAddLabel ( hud, 440, 135, SMALL, NOBLINK,
1665 // RIGHT_JUST, NULL, " Heading", "%5.0f", get_heading );
1667 loc.top = 145; // Ignore
1668 loc.right = 500; // Ignore
1670 HIptr = (instr_item *) new instr_label ( loc,
1683 // fgHUDAddLabel ( hud, 440, 120, SMALL, NOBLINK,
1684 // RIGHT_JUST, NULL, " Sideslip", "%5.2f", get_sideslip );
1686 loc.top = 130; // Ignore
1687 loc.right = 500; // Ignore
1689 HIptr = (instr_item *) new instr_label ( loc,
1703 loc.top = 90; // Ignore
1704 loc.right = 440; // Ignore
1706 HIptr = (instr_item *) new instr_label( loc, get_throttleval,
1719 loc.top = 70; // Ignore
1720 loc.right = 500; // Ignore
1722 HIptr = (instr_item *) new instr_label( loc, get_elevatorval,
1735 loc.top = 100; // Ignore
1736 loc.right = 500; // Ignore
1738 HIptr = (instr_item *) new instr_label( loc, get_aileronval,
1751 loc.top = 100; // Ignore
1752 loc.right = 500; // Ignore
1754 HIptr = (instr_item *) new instr_label( loc, get_frame_rate,
1767 loc.top = 100; // Ignore
1768 loc.right = 500; // Ignore
1770 HIptr = (instr_item *) new instr_label( loc, get_fov,
1781 // fgHUDAddControlSurfaces( hud, 10, 10, NULL );
1785 // loc.bottom = 180;
1786 // HIptr = (instr_item *) new
1791 if( HIptr ) { // Anything to install?
1792 HUD_deque.insert( HUD_deque.begin(), HIptr);
1796 // fgHUDAddControl( hud, HORIZONTAL, 50, 25, get_aileronval ); // was 10, 10
1797 // fgHUDAddControl( hud, VERTICAL, 150, 25, get_elevatorval ); // was 10, 10
1798 // fgHUDAddControl( hud, HORIZONTAL, 250, 25, get_rudderval ); // was 10, 10
1799 return 0; // For now. Later we may use this for an error code.
1805 // Performs a once around the list of calls to instruments installed in
1806 // the HUD object with requests for redraw. Kinda. It will when this is
1809 int global_day_night_switch = DAY;
1811 void fgUpdateHUD( void ) {
1814 // int day_night_sw = current_aircraft.controls->day_night_switch;
1815 int day_night_sw = global_day_night_switch;
1816 int hud_displays = HUD_deque.size();
1817 instr_item *pHUDInstr;
1819 if( !hud_displays ) { // Trust everyone, but ALWAYS cut the cards!
1823 pHUDInstr = HUD_deque[0];
1824 brightness = pHUDInstr->get_brightness();
1825 // brightness = HUD_deque.at(0)->get_brightness();
1827 glMatrixMode(GL_PROJECTION);
1831 gluOrtho2D(0, 640, 0, 480);
1832 glMatrixMode(GL_MODELVIEW);
1836 glColor3f(1.0, 1.0, 1.0);
1839 glDisable(GL_DEPTH_TEST);
1840 glDisable(GL_LIGHTING);
1844 for( i = hud_displays; i; --i) { // Draw everything
1845 // if( HUD_deque.at(i)->enabled()) {
1846 pHUDInstr = HUD_deque[i - 1];
1847 if( pHUDInstr->enabled()) {
1848 // We should to respond to a dial instead
1849 // or as well to the of time of day. Of
1850 // course, we have no dial!
1851 if( day_night_sw == DAY) {
1852 switch (brightness) {
1854 glColor3f (0.1, 0.9, 0.1);
1858 glColor3f (0.1, 0.7, 0.0);
1862 glColor3f (0.0, 0.5, 0.0);
1866 if( day_night_sw == NIGHT) {
1867 switch (brightness) {
1869 glColor3f (0.9, 0.1, 0.1);
1873 glColor3f (0.7, 0.0, 0.1);
1878 glColor3f (0.5, 0.0, 0.0);
1881 else { // Just in case default
1882 glColor3f (0.1, 0.9, 0.1);
1885 // fgPrintf( FG_COCKPIT, FG_DEBUG, "HUD Code %d Status %d\n",
1886 // hud->code, hud->status );
1888 // HUD_deque.at(i)->draw(); // Responsible for broken or fixed variants.
1889 // No broken displays honored just now.
1893 glEnable(GL_DEPTH_TEST);
1894 glEnable(GL_LIGHTING);
1895 glMatrixMode(GL_PROJECTION);
1897 glMatrixMode(GL_MODELVIEW);
1902 /* Revision 1.9 1998/05/16 13:04:14 curt
1903 /* New updates from Charlie Hotchkiss.
1905 * Revision 1.8 1998/05/13 18:27:54 curt
1906 * Added an fov to hud display.
1908 * Revision 1.7 1998/05/11 18:13:11 curt
1909 * Complete C++ rewrite of all cockpit code by Charlie Hotchkiss.
1911 * Revision 1.22 1998/04/18 04:14:02 curt
1912 * Moved fg_debug.c to it's own library.
1914 * Revision 1.21 1998/04/03 21:55:28 curt
1915 * Converting to Gnu autoconf system.
1918 * Revision 1.20 1998/03/09 22:48:40 curt
1919 * Minor "formatting" tweaks.
1921 * Revision 1.19 1998/02/23 20:18:28 curt
1922 * Incorporated Michele America's hud changes.
1924 * Revision 1.18 1998/02/21 14:53:10 curt
1925 * Added Charlie's HUD changes.
1927 * Revision 1.17 1998/02/20 00:16:21 curt
1928 * Thursday's tweaks.
1930 * Revision 1.16 1998/02/19 13:05:49 curt
1931 * Incorporated some HUD tweaks from Michelle America.
1932 * Tweaked the sky's sunset/rise colors.
1933 * Other misc. tweaks.
1935 * Revision 1.15 1998/02/16 13:38:39 curt
1936 * Integrated changes from Charlie Hotchkiss.
1938 * Revision 1.14 1998/02/12 21:59:41 curt
1939 * Incorporated code changes contributed by Charlie Hotchkiss
1940 * <chotchkiss@namg.us.anritsu.com>
1942 * Revision 1.12 1998/02/09 15:07:48 curt
1945 * Revision 1.11 1998/02/07 15:29:34 curt
1946 * Incorporated HUD changes and struct/typedef changes from Charlie Hotchkiss
1947 * <chotchkiss@namg.us.anritsu.com>
1949 * Revision 1.10 1998/02/03 23:20:14 curt
1950 * Lots of little tweaks to fix various consistency problems discovered by
1951 * Solaris' CC. Fixed a bug in fg_debug.c with how the fgPrintf() wrapper
1952 * passed arguments along to the real printf(). Also incorporated HUD changes
1953 * by Michele America.
1955 * Revision 1.9 1998/01/31 00:43:04 curt
1956 * Added MetroWorks patches from Carmen Volpe.
1958 * Revision 1.8 1998/01/27 00:47:51 curt
1959 * Incorporated Paul Bleisch's <bleisch@chromatic.com> new debug message
1960 * system and commandline/config file processing code.
1962 * Revision 1.7 1998/01/19 18:40:20 curt
1963 * Tons of little changes to clean up the code and to remove fatal errors
1964 * when building with the c++ compiler.
1966 * Revision 1.6 1997/12/15 23:54:34 curt
1967 * Add xgl wrappers for debugging.
1968 * Generate terrain normals on the fly.
1970 * Revision 1.5 1997/12/10 22:37:39 curt
1971 * Prepended "fg" on the name of all global structures that didn't have it yet.
1972 * i.e. "struct WEATHER {}" became "struct fgWEATHER {}"
1974 * Revision 1.4 1997/09/23 00:29:32 curt
1975 * Tweaks to get things to compile with gcc-win32.
1977 * Revision 1.3 1997/09/05 14:17:26 curt
1978 * More tweaking with stars.
1980 * Revision 1.2 1997/09/04 02:17:30 curt
1983 * Revision 1.1 1997/08/29 18:03:22 curt