1 // hud.cxx -- hud defines and prototypes
3 // Written by Michele America, started September 1997.
5 // Copyright (C) 1997 Michele F. America - micheleamerica@geocities.com
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License as
9 // published by the Free Software Foundation; either version 2 of the
10 // License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 // General Public License for more details.
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 #include <simgear/compiler.h>
24 #include <simgear/structure/exception.hxx>
38 # define exception c_exception
44 #include <stdio.h> // char related functions
45 #include <string.h> // strcmp()
49 #include <simgear/constants.h>
50 #include <simgear/debug/logstream.hxx>
51 #include <simgear/props/props.hxx>
52 #include <simgear/misc/sg_path.hxx>
54 #include <Aircraft/aircraft.hxx>
55 #include <Autopilot/xmlauto.hxx>
57 #include <Main/globals.hxx>
58 #include <Main/fg_props.hxx>
59 #include <Scenery/scenery.hxx>
61 #if defined ( __sun__ ) || defined ( __sgi )
63 extern void *memmove(void *, const void *, size_t);
71 // The following routines obtain information concerning the aircraft's
72 // current state and return it to calling instrument display routines.
73 // They should eventually be member functions of the aircraft.
76 deque< instr_item * > HUD_deque;
78 fgTextList HUD_TextList;
79 fgLineList HUD_LineList;
80 fgLineList HUD_StippleLineList;
82 fntRenderer *HUDtext = 0;
83 float HUD_TextSize = 0;
87 static float hud_trans_alpha = 0.67f;
90 //$$$ begin - added, Neetha, 28 Nov 2k
98 static float span_units;
99 static float division_units;
100 static float minor_division = 0;
101 static UINT screen_hole;
104 static string loadfn;
106 static float maxValue;
107 static float minValue;
108 static float scaling;
109 static UINT major_divs;
110 static UINT minor_divs;
111 static UINT modulator;
112 static int dp_showing = 0;
113 static string label_format;
114 static string prelabel;
115 static string postlabel;
118 static float maxBankAngle;
119 static float maxSlipAngle;
120 static UINT gap_width;
121 static bool latitude;
122 static bool longitude;
123 static bool tick_bottom;
124 static bool tick_top;
125 static bool tick_right;
126 static bool tick_left;
127 static bool cap_bottom;
129 static bool cap_right;
130 static bool cap_left;
131 static float marker_off;
133 static bool enable_pointer;
134 static string type_pointer;
135 static bool frl_spot;
137 static bool vel_vector;
141 static bool climb_dive;
143 static float glide_slope_val;
144 static bool worm_energy;
145 static bool waypoint;
146 static string type_tick;//hud
147 static string length_tick;//hud
148 static bool label_box;//hud
149 static int digits; //suma
150 static float radius; //suma
151 static int divisions; //suma
152 static int zoom; //suma
153 static int zenith; //suma
154 static int nadir ; //suma
155 static int hat; //suma
156 static bool tsi; //suma
157 static float rad; //suma
160 static FLTFNPTR load_fn;
161 static fgLabelJust justification;
162 static const char *pre_label_string = 0;
163 static const char *post_label_string = 0;
165 int readHud( istream &input );
166 int readInstrument ( const SGPropertyNode * node);
167 static instr_item * readLadder ( const SGPropertyNode * node);
168 static instr_item * readCard ( const SGPropertyNode * node);
169 static instr_item * readLabel( const SGPropertyNode * node);
170 static instr_item * readTBI( const SGPropertyNode * node);
171 //$$$ end - added, Neetha, 28 Nov 2k
173 static void drawHUD();
174 static void fgUpdateHUDVirtual();
176 void fgHUDalphaInit( void );
182 locRECT( UINT left, UINT top, UINT right, UINT bottom);
183 RECT get_rect(void) { return rect;}
186 locRECT :: locRECT( UINT left, UINT top, UINT right, UINT bottom)
191 rect.bottom = bottom;
196 //========================= End of Class Implementations===================
199 // Constructs a HUD object and then adds in instruments. At the present
200 // the instruments are hard coded into the routine. Ultimately these need
201 // to be defined by the aircraft's instrumentation records so that the
202 // display for a Piper Cub doesn't show the speed range of a North American
203 // mustange and the engine readouts of a B36!
208 //$$$ begin - added, Neetha, 28 Nov 2k
210 readLadder(const SGPropertyNode * node)
215 name = node->getStringValue("name");
216 x = node->getIntValue("x");
217 y = node->getIntValue("y");
218 width = node->getIntValue("width");
219 height = node->getIntValue("height");
220 factor = node->getFloatValue("compression_factor");
221 span_units = node->getFloatValue("span_units");
222 division_units = node->getFloatValue("division_units");
223 screen_hole = node->getIntValue("screen_hole");
224 lbl_pos = node->getIntValue("lbl_pos");
225 frl_spot = node->getBoolValue("enable_frl",false);
226 target = node->getBoolValue("enable_target_spot",false);
227 vel_vector = node->getBoolValue("enable_velocity_vector",false);
228 drift = node->getBoolValue("enable_drift_marker",false);
229 alpha = node->getBoolValue("enable_alpha_bracket",false);
230 energy = node->getBoolValue("enable_energy_marker",false);
231 climb_dive = node->getBoolValue("enable_climb_dive_marker",false);
232 glide = node->getBoolValue("enable_glide_slope_marker",false);
233 glide_slope_val = node->getFloatValue("glide_slope",-4.0);
234 worm_energy = node->getBoolValue("enable_energy_marker",false);
235 waypoint = node->getBoolValue("enable_waypoint_marker",false);
236 working = node->getBoolValue("working");
237 zenith = node->getIntValue("zenith"); //suma
238 nadir = node->getIntValue("nadir"); //suma
239 hat = node->getIntValue("hat");
240 // The factor assumes a base of 55 degrees per 640 pixels.
241 // Invert to convert the "compression" factor to a
242 // pixels-per-degree number.
243 if(fgGetBool("/sim/hud/enable3d", true))
248 factor = (640./55.) / factor;
252 SG_LOG(SG_INPUT, SG_INFO, "Done reading instrument " << name);
254 p = (instr_item *) new HudLadder( name, x, y,
255 width, height, factor,
257 span_units, division_units, minor_division,
258 screen_hole, lbl_pos, frl_spot, target, vel_vector,
259 drift, alpha, energy, climb_dive,
260 glide, glide_slope_val, worm_energy,
261 waypoint, working, zenith, nadir, hat);
268 readCard(const SGPropertyNode * node)
273 name = node->getStringValue("name");
274 x = node->getIntValue("x");
275 y = node->getIntValue("y");
276 width = node->getIntValue("width");
277 height = node->getIntValue("height");
278 loadfn = node->getStringValue("loadfn");
279 options = node->getIntValue("options");
280 maxValue = node->getFloatValue("maxValue");
281 minValue = node->getFloatValue("minValue");
282 scaling = node->getFloatValue("disp_scaling");
283 major_divs = node->getIntValue("major_divs");
284 minor_divs = node->getIntValue("minor_divs");
285 modulator = node->getIntValue("modulator");
286 span_units = node->getFloatValue("value_span");
287 type = node->getStringValue("type");
288 tick_bottom = node->getBoolValue("tick_bottom",false);
289 tick_top = node->getBoolValue("tick_top",false);
290 tick_right = node->getBoolValue("tick_right",false);
291 tick_left = node->getBoolValue("tick_left",false);
292 cap_bottom = node->getBoolValue("cap_bottom",false);
293 cap_top = node->getBoolValue("cap_top",false);
294 cap_right = node->getBoolValue("cap_right",false);
295 cap_left = node->getBoolValue("cap_left",false);
296 marker_off = node->getFloatValue("marker_offset",0.0);
297 enable_pointer = node->getBoolValue("enable_pointer",true);
298 type_pointer = node->getStringValue("pointer_type");
299 type_tick = node->getStringValue("tick_type");//hud Can be 'circle' or 'line'
300 length_tick = node->getStringValue("tick_length");//hud For variable length
301 working = node->getBoolValue("working");
302 radius = node->getFloatValue("radius"); //suma
303 divisions = node->getIntValue("divisions"); //suma
304 zoom = node->getIntValue("zoom"); //suma
306 SG_LOG(SG_INPUT, SG_INFO, "Done reading instrument " << name);
310 span_units = maxValue - minValue;
313 if (loadfn=="anzg") {
315 } else if (loadfn=="heading") {
316 load_fn = get_heading;
317 } else if (loadfn=="aoa") {
319 } else if (loadfn=="climb") {
320 load_fn = get_climb_rate;
321 } else if (loadfn=="altitude") {
322 load_fn = get_altitude;
323 } else if (loadfn=="agl") {
325 } else if (loadfn=="speed") {
327 } else if (loadfn=="view_direction") {
328 load_fn = get_view_direction;
329 } else if (loadfn=="aileronval") {
330 load_fn = get_aileronval;
331 } else if (loadfn=="elevatorval") {
332 load_fn = get_elevatorval;
333 } else if (loadfn=="elevatortrimval") {
334 load_fn = get_elev_trimval;
335 } else if (loadfn=="rudderval") {
336 load_fn = get_rudderval;
337 } else if (loadfn=="throttleval") {
338 load_fn = get_throttleval;
342 if ( (type == "dial") | (type == "tape") ) {
343 p = (instr_item *) new hud_card( x,
351 major_divs, minor_divs,
375 p = (instr_item *) new gauge_instr( x, // x
379 load_fn, // data source
383 major_divs, minor_divs,
393 readLabel(const SGPropertyNode * node)
397 int font_size = (fgGetInt("/sim/startup/xsize") > 1000) ? HUD_FONT_LARGE : HUD_FONT_SMALL;
399 name = node->getStringValue("name");
400 x = node->getIntValue("x");
401 y = node->getIntValue("y");
402 width = node->getIntValue("width");
403 height = node->getIntValue("height");
404 loadfn = node->getStringValue("data_source");
405 label_format = node->getStringValue("label_format");
406 prelabel = node->getStringValue("pre_label_string");
407 postlabel = node->getStringValue("post_label_string");
408 scaling = node->getFloatValue("scale_data");
409 options = node->getIntValue("options");
410 justi = node->getIntValue("justification");
411 blinking = node->getIntValue("blinking");
412 latitude = node->getBoolValue("latitude",false);
413 longitude = node->getBoolValue("longitude",false);
414 label_box = node->getBoolValue("label_box",false);//hud
415 working = node->getBoolValue("working");
416 digits = node->getIntValue("digits"); //suma
419 SG_LOG(SG_INPUT, SG_INFO, "Done reading instrument " << name);
423 justification = LEFT_JUST;
426 justification = CENTER_JUST;
429 justification = RIGHT_JUST;
434 if ( prelabel == "NULL" ) {
435 pre_label_string = NULL;
437 if ( prelabel == "blank" ) {
438 pre_label_string = " ";
440 pre_label_string = prelabel.c_str();
444 if ( postlabel == "blank" ) {
445 post_label_string = " ";
447 if ( postlabel == "NULL" ) {
448 post_label_string = NULL;
450 if ( postlabel == "units" ) {
451 post_label_string = units;
453 post_label_string = postlabel.c_str();
458 if ( loadfn== "aux1" ) {
460 } else if ( loadfn == "aux2" ) {
462 } else if ( loadfn == "aux3" ) {
464 } else if ( loadfn == "aux4" ) {
466 } else if ( loadfn == "aux5" ) {
468 } else if ( loadfn == "aux6" ) {
470 } else if ( loadfn == "aux7" ) {
472 } else if ( loadfn == "aux8" ) {
474 } else if ( loadfn == "aux9" ) {
476 } else if ( loadfn == "aux10" ) {
478 } else if ( loadfn == "aux11" ) {
480 } else if ( loadfn == "aux12" ) {
482 } else if ( loadfn == "aux13" ) {
484 } else if ( loadfn == "aux14" ) {
486 } else if ( loadfn == "aux15" ) {
488 } else if ( loadfn == "aux16" ) {
490 } else if ( loadfn == "aux17" ) {
492 } else if ( loadfn == "aux18" ) {
494 } else if ( loadfn == "ax" ) {
496 } else if ( loadfn == "speed" ) {
498 } else if ( loadfn == "mach" ) {
500 } else if ( loadfn == "altitude" ) {
501 load_fn = get_altitude;
502 } else if ( loadfn == "agl" ) {
504 } else if ( loadfn == "framerate" ) {
505 load_fn = get_frame_rate;
506 } else if ( loadfn == "heading" ) {
507 load_fn = get_heading;
508 } else if ( loadfn == "fov" ) {
510 } else if ( loadfn == "vfc_tris_culled" ) {
511 load_fn = get_vfc_tris_culled;
512 } else if ( loadfn == "vfc_tris_drawn" ) {
513 load_fn = get_vfc_tris_drawn;
514 } else if ( loadfn == "aoa" ) {
516 } else if ( loadfn == "latitude" ) {
517 load_fn = get_latitude;
518 } else if ( loadfn == "anzg" ) {
520 } else if ( loadfn == "longitude" ) {
521 load_fn = get_longitude;
522 } else if (loadfn=="throttleval") {
523 load_fn = get_throttleval;
526 p = (instr_item *) new instr_label ( x,
531 label_format.c_str(),
549 readTBI(const SGPropertyNode * node)
554 name = node->getStringValue("name");
555 x = node->getIntValue("x");
556 y = node->getIntValue("y");
557 width = node->getIntValue("width");
558 height = node->getIntValue("height");
559 maxBankAngle = node->getFloatValue("maxBankAngle");
560 maxSlipAngle = node->getFloatValue("maxSlipAngle");
561 gap_width = node->getIntValue("gap_width");
562 working = node->getBoolValue("working");
563 tsi = node->getBoolValue("tsi"); //suma
564 rad = node->getFloatValue("rad"); //suma
566 SG_LOG(SG_INPUT, SG_INFO, "Done reading instrument " << name);
569 p = (instr_item *) new fgTBI_instr( x,
586 int readInstrument(const SGPropertyNode * node)
588 static const SGPropertyNode *startup_units_node
589 = fgGetNode("/sim/startup/units");
593 if ( !strcmp(startup_units_node->getStringValue(), "feet") ) {
594 strcpy(units, " ft");
599 const SGPropertyNode * ladder_group = node->getNode("ladders");
601 if (ladder_group != 0) {
602 int nLadders = ladder_group->nChildren();
603 for (int j = 0; j < nLadders; j++) {
605 HIptr = readLadder(ladder_group->getChild(j));
606 HUD_deque.insert( HUD_deque.begin(), HIptr);
611 const SGPropertyNode * card_group = node->getNode("cards");
612 if (card_group != 0) {
613 int nCards = card_group->nChildren();
614 for (int j = 0; j < nCards; j++) {
616 HIptr = readCard(card_group->getChild(j));
617 HUD_deque.insert( HUD_deque.begin(), HIptr);
622 const SGPropertyNode * label_group = node->getNode("labels");
623 if (label_group != 0) {
624 int nLabels = label_group->nChildren();
625 for (int j = 0; j < nLabels; j++) {
627 HIptr = readLabel(label_group->getChild(j));
628 HUD_deque.insert( HUD_deque.begin(), HIptr);
633 const SGPropertyNode * tbi_group = node->getNode("tbis");
634 if (tbi_group != 0) {
635 int nTbis = tbi_group->nChildren();
636 for (int j = 0; j < nTbis; j++) {
638 HIptr = readTBI(tbi_group->getChild(j));
639 HUD_deque.insert( HUD_deque.begin(), HIptr);
644 }//end readinstrument
647 int readHud( istream &input )
653 readProperties(input, &root);
654 } catch (const sg_exception &e) {
655 guiErrorMessage("Error reading HUD: ", e);
660 SG_LOG(SG_INPUT, SG_INFO, "Read properties for " <<
661 root.getStringValue("name"));
664 HUD_deque.erase( HUD_deque.begin(), HUD_deque.end()); // empty the HUD deque
667 SG_LOG(SG_INPUT, SG_INFO, "Reading Hud instruments");
669 const SGPropertyNode * instrument_group = root.getChild("instruments");
670 int nInstruments = instrument_group->nChildren();
672 for (int i = 0; i < nInstruments; i++) {
674 const SGPropertyNode * node = instrument_group->getChild(i);
676 SGPath path( globals->get_fg_root() );
677 path.append(node->getStringValue("path"));
679 SG_LOG(SG_INPUT, SG_INFO, "Reading Instrument "
684 SGPropertyNode root2;
686 readProperties(path.str(), &root2);
687 } catch (const sg_exception &e) {
688 guiErrorMessage("Error reading HUD instrument: ", e);
691 readInstrument(&root2);
698 int fgHUDInit( fgAIRCRAFT * /* current_aircraft */ )
703 SG_LOG( SG_COCKPIT, SG_INFO, "Initializing current aircraft HUD" );
706 fgGetString("/sim/hud/path", "Huds/Default/default.xml");
707 SGPath path(globals->get_fg_root());
708 path.append(hud_path);
710 ifstream input(path.c_str());
712 SG_LOG(SG_INPUT, SG_ALERT,
713 "Cannot read Hud configuration from " << path.str());
723 // this chunk of code is not necessarily thread safe if the
724 // compiler optimizer reorders these statements. Note that
725 // "delete ptr" does not set "ptr = NULL". We have to do that
727 fntRenderer *tmp = HUDtext;
732 // HUD_TextSize = fgGetInt("/sim/startup/xsize") / 60;
734 HUDtext = new fntRenderer();
735 HUDtext -> setFont ( guiFntHandle ) ;
736 HUDtext -> setPointSize ( HUD_TextSize ) ;
737 HUD_TextList.setFont( HUDtext );
739 return 0; // For now. Later we may use this for an error code.
743 int fgHUDInit2( fgAIRCRAFT * /* current_aircraft */ )
748 SG_LOG( SG_COCKPIT, SG_INFO, "Initializing current aircraft HUD" );
750 SGPath path(globals->get_fg_root());
751 path.append("Huds/Minimal/default.xml");
754 ifstream input(path.c_str());
756 SG_LOG(SG_INPUT, SG_ALERT,
757 "Cannot read Hud configuration from " << path.str());
763 return 0; // For now. Later we may use this for an error code.
766 //$$$ End - added, Neetha, 28 Nov 2k
768 static int global_day_night_switch = HUD_DAY;
770 void HUD_masterswitch( bool incr )
772 if ( fgGetBool("/sim/hud/visibility") ) {
773 if ( global_day_night_switch == HUD_DAY ) {
774 global_day_night_switch = HUD_NIGHT;
776 fgSetBool("/sim/hud/visibility", false);
779 fgSetBool("/sim/hud/visibility", true);
780 global_day_night_switch = HUD_DAY;
784 void HUD_brightkey( bool incr_bright )
786 instr_item *pHUDInstr = HUD_deque[0];
787 int brightness = pHUDInstr->get_brightness();
789 if( fgGetBool("/sim/hud/visibility") ) {
794 brightness = HUD_BRT_BLACK;
798 brightness = HUD_BRT_LIGHT;
802 brightness = HUD_BRT_MEDIUM;
806 brightness = HUD_BRT_DARK;
810 brightness = HUD_BRT_BLACK;
816 brightness = HUD_BRT_MEDIUM;
820 brightness = HUD_BRT_DARK;
824 brightness = HUD_BRT_BLACK;
828 brightness = HUD_BRT_LIGHT;
832 fgSetBool("/sim/hud/visibility", false);
836 fgSetBool("/sim/hud/visibility", true);
839 pHUDInstr->SetBrightness( brightness );
843 #define fgAP_CLAMP(val,min,max) ( (val) = (val) > (max) ? (max) : (val) < (min) ? (min) : (val) )
845 static puDialogBox *HUDalphaDialog;
846 static puText *HUDalphaText;
847 static puSlider *HUDalphaHS0;
848 //static puText *HUDtextText;
849 //static puSlider *HUDalphaHS1;
850 static char SliderText[2][ 8 ];
852 static void alpha_adj( puObject *hs ) {
855 hs-> getValue ( &val ) ;
856 fgAP_CLAMP ( val, 0.1, 1.0 ) ;
857 // printf ( "maxroll_adj( %p ) %f %f\n", hs, val, MaxRollAdjust * val ) ;
858 hud_trans_alpha = val;
859 sprintf( SliderText[ 0 ], "%05.2f", hud_trans_alpha );
860 HUDalphaText -> setLabel ( SliderText[ 0 ] ) ;
863 void fgHUDalphaAdjust( puObject * ) {
864 fgSetBool("/sim/hud/antialiased", true);
865 FG_PUSH_PUI_DIALOG( HUDalphaDialog );
868 static void goAwayHUDalphaAdjust (puObject *)
870 FG_POP_PUI_DIALOG( HUDalphaDialog );
873 static void cancelHUDalphaAdjust (puObject *)
875 fgSetBool("/sim/hud/antialiased", false);
876 FG_POP_PUI_DIALOG( HUDalphaDialog );
879 // Done once at system initialization
880 void fgHUDalphaInit( void ) {
882 // printf("fgHUDalphaInit\n");
883 #define HORIZONTAL FALSE
887 int DialogWidth = 240;
889 char Label[] = "HUD Adjuster";
892 int labelX = (DialogWidth / 2) -
893 ( puGetDefaultLabelFont().getStringWidth( Label ) / 2);
898 int slider_width = 220;
899 int slider_title_x = 15;
900 int slider_value_x = 160;
901 float slider_delta = 0.05f;
903 puFont HUDalphaLegendFont;
904 puFont HUDalphaLabelFont;
905 puGetDefaultFonts ( &HUDalphaLegendFont, &HUDalphaLabelFont );
907 HUDalphaDialog = new puDialogBox ( DialogX, DialogY ); {
908 int horiz_slider_height = HUDalphaLabelFont.getStringHeight() +
909 HUDalphaLabelFont.getStringDescender() +
910 PUSTR_TGAP + PUSTR_BGAP + 5;
913 HUDalphaFrame = new puFrame ( 0, 0, DialogWidth,
915 * horiz_slider_height ); */
918 HUDalphaDialogMessage = new puText ( labelX,
920 * horiz_slider_height );
921 HUDalphaDialogMessage -> setDefaultValue ( Label );
922 HUDalphaDialogMessage -> getDefaultValue ( &s );
923 HUDalphaDialogMessage -> setLabel ( s );
925 HUDalphaHS0 = new puSlider ( slider_x, slider_y,
926 slider_width, HORIZONTAL ) ;
927 HUDalphaHS0-> setDelta ( slider_delta ) ;
928 HUDalphaHS0-> setValue ( hud_trans_alpha ) ;
929 HUDalphaHS0-> setCBMode ( PUSLIDER_DELTA ) ;
930 HUDalphaHS0-> setCallback ( alpha_adj ) ;
933 HUDalphaTitle = new puText ( slider_title_x, slider_y ) ;
934 HUDalphaTitle-> setDefaultValue ( "Alpha" ) ;
935 HUDalphaTitle-> getDefaultValue ( &s ) ;
936 HUDalphaTitle-> setLabel ( s ) ;
938 HUDalphaText = new puText ( slider_value_x, slider_y ) ;
939 sprintf( SliderText[ 0 ], "%05.2f", hud_trans_alpha );
940 HUDalphaText-> setLabel ( SliderText[ 0 ] ) ;
943 HUDalphaOkButton = new puOneShot ( 10, 10, 60, 45 );
944 HUDalphaOkButton-> setLegend ( gui_msg_OK );
945 HUDalphaOkButton-> makeReturnDefault ( TRUE );
946 HUDalphaOkButton-> setCallback ( goAwayHUDalphaAdjust );
949 HUDalphaNoButton = new puOneShot ( 160, 10, 230, 45 );
950 HUDalphaNoButton-> setLegend ( gui_msg_CANCEL );
951 HUDalphaNoButton-> setCallback ( cancelHUDalphaAdjust );
953 FG_FINALIZE_PUI_DIALOG( HUDalphaDialog );
959 void fgHUDReshape(void) {
962 // this chunk of code is not necessarily thread safe if the
963 // compiler optimizer reorders these statements. Note that
964 // "delete ptr" does not set "ptr = NULL". We have to do that
966 fntRenderer *tmp = HUDtext;
971 HUD_TextSize = fgGetInt("/sim/startup/xsize") / 60;
973 HUDtext = new fntRenderer();
974 HUDtext -> setFont ( guiFntHandle ) ;
975 HUDtext -> setPointSize ( HUD_TextSize ) ;
976 HUD_TextList.setFont( HUDtext );
981 static void set_hud_color(float r, float g, float b) {
982 fgGetBool("/sim/hud/antialiased") ?
983 glColor4f(r,g,b,hud_trans_alpha) :
990 // Performs a once around the list of calls to instruments installed in
991 // the HUD object with requests for redraw. Kinda. It will when this is
994 void fgUpdateHUD( void ) {
996 static const SGPropertyNode *enable3d_node = fgGetNode("/sim/hud/enable3d");
997 if( HUD_style == 1 && enable3d_node->getBoolValue() )
999 fgUpdateHUDVirtual();
1003 static const float normal_aspect = float(640) / float(480);
1004 // note: aspect_ratio is Y/X
1005 float current_aspect = 1.0f/globals->get_current_view()->get_aspect_ratio();
1006 if( current_aspect > normal_aspect ) {
1007 float aspect_adjust = current_aspect / normal_aspect;
1008 float adjust = 320.0f*aspect_adjust - 320.0f;
1009 fgUpdateHUD( -adjust, 0.0f, 640.0f+adjust, 480.0f );
1011 float aspect_adjust = normal_aspect / current_aspect;
1012 float adjust = 240.0f*aspect_adjust - 240.0f;
1013 fgUpdateHUD( 0.0f, -adjust, 640.0f, 480.0f+adjust );
1017 void fgUpdateHUDVirtual()
1019 FGViewer* view = globals->get_current_view();
1021 // Standard fgfs projection, with essentially meaningless clip
1022 // planes (we'll map the whole HUD plane to z=-1)
1023 glMatrixMode(GL_PROJECTION);
1026 gluPerspective(view->get_v_fov(), 1/view->get_aspect_ratio(), 0.1, 10);
1028 glMatrixMode(GL_MODELVIEW);
1032 // Standard fgfs view direction computation
1034 lookat[0] = -sin(SG_DEGREES_TO_RADIANS * view->getHeadingOffset_deg());
1035 lookat[1] = tan(SG_DEGREES_TO_RADIANS * view->getPitchOffset_deg());
1036 lookat[2] = -cos(SG_DEGREES_TO_RADIANS * view->getHeadingOffset_deg());
1037 if(fabs(lookat[1]) > 9999) lookat[1] = 9999; // FPU sanity
1038 gluLookAt(0, 0, 0, lookat[0], lookat[1], lookat[2], 0, 1, 0);
1040 // Map the -1:1 square to a 55.0x41.25 degree wide patch at z=1.
1041 // This is the default fgfs field of view, which the HUD files are
1042 // written to assume.
1043 float dx = 0.52056705; // tan(55/2)
1044 float dy = dx * 0.75; // assumes 4:3 aspect ratio
1046 m[0] = dx; m[4] = 0; m[ 8] = 0; m[12] = 0;
1047 m[1] = 0; m[5] = dy; m[ 9] = 0; m[13] = 0;
1048 m[2] = 0; m[6] = 0; m[10] = 1; m[14] = 0;
1049 m[3] = 0; m[7] = 0; m[11] = 0; m[15] = 1;
1052 // Convert the 640x480 "HUD standard" coordinate space to a square
1053 // about the origin in the range [-1:1] at depth of -1
1054 glScalef(1./320, 1./240, 1);
1055 glTranslatef(-320, -240, -1);
1060 // Clean up our mess
1061 glMatrixMode(GL_PROJECTION);
1063 glMatrixMode(GL_MODELVIEW);
1067 void fgUpdateHUD( GLfloat x_start, GLfloat y_start,
1068 GLfloat x_end, GLfloat y_end )
1070 glMatrixMode(GL_PROJECTION);
1073 gluOrtho2D(x_start, x_end, y_start, y_end);
1075 glMatrixMode(GL_MODELVIEW);
1081 glMatrixMode(GL_PROJECTION);
1083 glMatrixMode(GL_MODELVIEW);
1089 if( !HUD_deque.size() ) { // Trust everyone, but ALWAYS cut the cards!
1093 HUD_TextList.erase();
1094 HUD_LineList.erase();
1095 // HUD_StippleLineList.erase();
1097 glDisable(GL_DEPTH_TEST);
1098 glDisable(GL_LIGHTING);
1100 static const SGPropertyNode *antialiased_node
1101 = fgGetNode("/sim/hud/antialiased", true);
1102 static const SGPropertyNode *heading_enabled
1103 = fgGetNode("/autopilot/locks/heading", true);
1104 static const SGPropertyNode *altitude_enabled
1105 = fgGetNode("/autopilot/locks/altitude", true);
1107 static char hud_hdg_text[256];
1108 static char hud_wp0_text[256];
1109 static char hud_wp1_text[256];
1110 static char hud_wp2_text[256];
1111 static char hud_alt_text[256];
1113 if( antialiased_node->getBoolValue() ) {
1114 glEnable(GL_LINE_SMOOTH);
1115 // glEnable(GL_BLEND);
1116 glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
1117 glHint(GL_LINE_SMOOTH_HINT,GL_DONT_CARE);
1123 if( global_day_night_switch == HUD_DAY) {
1124 switch (HUD_deque[0]->get_brightness())
1127 set_hud_color (0.1f, 0.9f, 0.1f);
1130 case HUD_BRT_MEDIUM:
1131 set_hud_color (0.1f, 0.7f, 0.0f);
1135 set_hud_color (0.0f, 0.6f, 0.0f);
1139 set_hud_color( 0.0f, 0.0f, 0.0f);
1143 set_hud_color (0.1f, 0.9f, 0.1f);
1146 if( global_day_night_switch == HUD_NIGHT) {
1147 switch (HUD_deque[0]->get_brightness())
1150 set_hud_color (0.9f, 0.1f, 0.1f);
1153 case HUD_BRT_MEDIUM:
1154 set_hud_color (0.7f, 0.0f, 0.1f);
1158 set_hud_color (0.6f, 0.0f, 0.0f);
1162 set_hud_color( 0.0f, 0.0f, 0.0f);
1166 set_hud_color (0.6f, 0.0f, 0.0f);
1168 } else { // Just in case default
1169 set_hud_color (0.1f, 0.9f, 0.1f);
1173 for_each(HUD_deque.begin(), HUD_deque.end(), HUDdraw());
1175 HUD_TextList.add( fgText(40, 10, get_formated_gmt_time(), 0) );
1181 if (strcmp( heading_enabled->getStringValue(), "dg-heading-hold") == 0 ) {
1182 snprintf( hud_hdg_text, 256, "hdg = %.1f\n",
1183 fgGetDouble("/autopilot/settings/heading-bug-deg") );
1184 HUD_TextList.add( fgText( 40, apY, hud_hdg_text ) );
1186 } else if ( strcmp(heading_enabled->getStringValue(), "true-heading-hold") == 0 ) {
1187 snprintf( hud_hdg_text, 256, "hdg = %.1f\n",
1188 fgGetDouble("/autopilot/settings/true-heading-deg") );
1189 HUD_TextList.add( fgText( 40, apY, hud_hdg_text ) );
1192 string wp0_id = fgGetString( "/autopilot/route-manager/wp[0]/id" );
1193 if ( wp0_id.length() > 0 ) {
1194 snprintf( hud_wp0_text, 256, "%5s %6.1fnm %s", wp0_id.c_str(),
1195 fgGetDouble( "/autopilot/route-manager/wp[0]/dist" ),
1196 fgGetString( "/autopilot/route-manager/wp[0]/eta" ) );
1197 HUD_TextList.add( fgText( 40, apY, hud_wp0_text ) );
1200 string wp1_id = fgGetString( "/autopilot/route-manager/wp[1]/id" );
1201 if ( wp1_id.length() > 0 ) {
1202 snprintf( hud_wp1_text, 256, "%5s %6.1fnm %s", wp1_id.c_str(),
1203 fgGetDouble( "/autopilot/route-manager/wp[1]/dist" ),
1204 fgGetString( "/autopilot/route-manager/wp[1]/eta" ) );
1205 HUD_TextList.add( fgText( 40, apY, hud_wp1_text ) );
1208 string wp2_id = fgGetString( "/autopilot/route-manager/wp-last/id" );
1209 if ( wp2_id.length() > 0 ) {
1210 snprintf( hud_wp2_text, 256, "%5s %6.1fnm %s", wp2_id.c_str(),
1211 fgGetDouble( "/autopilot/route-manager/wp-last/dist" ),
1212 fgGetString( "/autopilot/route-manager/wp-last/eta" ) );
1213 HUD_TextList.add( fgText( 40, apY, hud_wp2_text ) );
1218 if ( strcmp( altitude_enabled->getStringValue(), "altitude-hold" ) == 0 ) {
1219 snprintf( hud_alt_text, 256, "alt = %.0f\n",
1220 fgGetDouble("/autopilot/settings/target-altitude-ft") );
1221 HUD_TextList.add( fgText( 40, apY, hud_alt_text ) );
1223 } else if ( strcmp( altitude_enabled->getStringValue(), "agl-hold" ) == 0 ){
1224 snprintf( hud_alt_text, 256, "agl = %.0f\n",
1225 fgGetDouble("/autopilot/settings/target-agl-ft") );
1226 HUD_TextList.add( fgText( 40, apY, hud_alt_text ) );
1230 HUD_TextList.draw();
1232 HUD_LineList.draw();
1234 // glEnable(GL_LINE_STIPPLE);
1235 // glLineStipple( 1, 0x00FF );
1236 // HUD_StippleLineList.draw();
1237 // glDisable(GL_LINE_STIPPLE);
1239 if( antialiased_node->getBoolValue() ) {
1240 // glDisable(GL_BLEND);
1241 glDisable(GL_LINE_SMOOTH);
1245 glEnable(GL_DEPTH_TEST);
1246 glEnable(GL_LIGHTING);