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/misc/exception.hxx>
38 # define exception c_exception
45 #include <stdio.h> // char related functions
46 #include <string.h> // strcmp()
48 #include <simgear/constants.h>
49 #include <simgear/debug/logstream.hxx>
50 #include <simgear/props/props.hxx>
51 #include <simgear/misc/sg_path.hxx>
53 #include <Aircraft/aircraft.hxx>
54 #include <Autopilot/newauto.hxx>
56 #include <Main/globals.hxx>
57 #include <Main/fg_props.hxx>
59 #include <NetworkOLK/network.h>
61 #include <Scenery/scenery.hxx>
63 #if defined ( __sun__ ) || defined ( __sgi )
65 extern void *memmove(void *, const void *, size_t);
73 // The following routines obtain information concerning the aircraft's
74 // current state and return it to calling instrument display routines.
75 // They should eventually be member functions of the aircraft.
78 deque< instr_item * > HUD_deque;
80 fgTextList HUD_TextList;
81 fgLineList HUD_LineList;
82 fgLineList HUD_StippleLineList;
84 fntRenderer *HUDtext = 0;
85 float HUD_TextSize = 0;
89 static float hud_trans_alpha = 0.67f;
92 //$$$ begin - added, Neetha, 28 Nov 2k
100 static float span_units;
101 static float division_units;
102 static float minor_division = 0;
103 static UINT screen_hole;
106 static string loadfn;
108 static float maxValue;
109 static float minValue;
110 static float scaling;
111 static UINT major_divs;
112 static UINT minor_divs;
113 static UINT modulator;
114 static int dp_showing = 0;
115 static string label_format;
116 static string prelabel;
117 static string postlabel;
120 static float maxBankAngle;
121 static float maxSlipAngle;
122 static UINT gap_width;
123 static bool latitude;
124 static bool longitude;
125 static bool tick_bottom;
126 static bool tick_top;
127 static bool tick_right;
128 static bool tick_left;
129 static bool cap_bottom;
131 static bool cap_right;
132 static bool cap_left;
133 static float marker_off;
135 static bool enable_pointer;
136 static string type_pointer;
137 static bool frl_spot;
139 static bool vel_vector;
143 static bool climb_dive;
145 static float glide_slope_val;
146 static bool worm_energy;
147 static bool waypoint;
148 static string type_tick;//hud
149 static string length_tick;//hud
150 static bool label_box;//hud
151 static int digits; //suma
152 static float radius; //suma
153 static int divisions; //suma
154 static int zoom; //suma
155 static int zenith; //suma
156 static int nadir ; //suma
157 static int hat; //suma
158 static bool tsi; //suma
159 static float rad; //suma
162 static FLTFNPTR load_fn;
163 static fgLabelJust justification;
164 static const char *pre_label_string = 0;
165 static const char *post_label_string = 0;
167 int readHud( istream &input );
168 int readInstrument ( const SGPropertyNode * node);
169 static instr_item * readLadder ( const SGPropertyNode * node);
170 static instr_item * readCard ( const SGPropertyNode * node);
171 static instr_item * readLabel( const SGPropertyNode * node);
172 static instr_item * readTBI( const SGPropertyNode * node);
173 //$$$ end - added, Neetha, 28 Nov 2k
175 static void drawHUD();
176 static void fgUpdateHUDVirtual();
178 void fgHUDalphaInit( void );
184 locRECT( UINT left, UINT top, UINT right, UINT bottom);
185 RECT get_rect(void) { return rect;}
188 locRECT :: locRECT( UINT left, UINT top, UINT right, UINT bottom)
193 rect.bottom = bottom;
198 //========================= End of Class Implementations===================
201 // Constructs a HUD object and then adds in instruments. At the present
202 // the instruments are hard coded into the routine. Ultimately these need
203 // to be defined by the aircraft's instrumentation records so that the
204 // display for a Piper Cub doesn't show the speed range of a North American
205 // mustange and the engine readouts of a B36!
210 //$$$ begin - added, Neetha, 28 Nov 2k
212 readLadder(const SGPropertyNode * node)
217 name = node->getStringValue("name");
218 x = node->getIntValue("x");
219 y = node->getIntValue("y");
220 width = node->getIntValue("width");
221 height = node->getIntValue("height");
222 factor = node->getFloatValue("compression_factor");
223 span_units = node->getFloatValue("span_units");
224 division_units = node->getFloatValue("division_units");
225 screen_hole = node->getIntValue("screen_hole");
226 lbl_pos = node->getIntValue("lbl_pos");
227 frl_spot = node->getBoolValue("enable_frl",false);
228 target = node->getBoolValue("enable_target_spot",false);
229 vel_vector = node->getBoolValue("enable_velocity_vector",false);
230 drift = node->getBoolValue("enable_drift_marker",false);
231 alpha = node->getBoolValue("enable_alpha_bracket",false);
232 energy = node->getBoolValue("enable_energy_marker",false);
233 climb_dive = node->getBoolValue("enable_climb_dive_marker",false);
234 glide = node->getBoolValue("enable_glide_slope_marker",false);
235 glide_slope_val = node->getFloatValue("glide_slope",-4.0);
236 worm_energy = node->getBoolValue("enable_energy_marker",false);
237 waypoint = node->getBoolValue("enable_waypoint_marker",false);
238 working = node->getBoolValue("working");
239 zenith = node->getIntValue("zenith"); //suma
240 nadir = node->getIntValue("nadir"); //suma
241 hat = node->getIntValue("hat");
242 // The factor assumes a base of 55 degrees per 640 pixels.
243 // Invert to convert the "compression" factor to a
244 // pixels-per-degree number.
249 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 ) {
998 fgUpdateHUDVirtual();
1002 static const float normal_aspect = float(640) / float(480);
1003 // note: aspect_ratio is Y/X
1004 float current_aspect = 1.0f/globals->get_current_view()->get_aspect_ratio();
1005 if( current_aspect > normal_aspect ) {
1006 float aspect_adjust = current_aspect / normal_aspect;
1007 float adjust = 320.0f*aspect_adjust - 320.0f;
1008 fgUpdateHUD( -adjust, 0.0f, 640.0f+adjust, 480.0f );
1010 float aspect_adjust = normal_aspect / current_aspect;
1011 float adjust = 240.0f*aspect_adjust - 240.0f;
1012 fgUpdateHUD( 0.0f, -adjust, 640.0f, 480.0f+adjust );
1016 void fgUpdateHUDVirtual()
1018 FGViewer* view = globals->get_current_view();
1020 // Standard fgfs projection, with essentially meaningless clip
1021 // planes (we'll map the whole HUD plane to z=-1)
1022 glMatrixMode(GL_PROJECTION);
1025 gluPerspective(view->get_v_fov(), 1/view->get_aspect_ratio(), 0.1, 10);
1027 glMatrixMode(GL_MODELVIEW);
1031 // Standard fgfs view direction computation
1033 lookat[0] = -sin(SG_DEGREES_TO_RADIANS * view->getHeadingOffset_deg());
1034 lookat[1] = tan(SG_DEGREES_TO_RADIANS * view->getPitchOffset_deg());
1035 lookat[2] = -cos(SG_DEGREES_TO_RADIANS * view->getHeadingOffset_deg());
1036 if(fabs(lookat[1]) > 9999) lookat[1] = 9999; // FPU sanity
1037 gluLookAt(0, 0, 0, lookat[0], lookat[1], lookat[2], 0, 1, 0);
1039 // Map the -1:1 square to a 55.0x41.25 degree wide patch at z=1.
1040 // This is the default fgfs field of view, which the HUD files are
1041 // written to assume.
1042 float dx = 0.52056705; // tan(55/2)
1043 float dy = dx * 0.75; // assumes 4:3 aspect ratio
1045 m[0] = dx; m[4] = 0; m[ 8] = 0; m[12] = 0;
1046 m[1] = 0; m[5] = dy; m[ 9] = 0; m[13] = 0;
1047 m[2] = 0; m[6] = 0; m[10] = 1; m[14] = 0;
1048 m[3] = 0; m[7] = 0; m[11] = 0; m[15] = 1;
1051 // Convert the 640x480 "HUD standard" coordinate space to a square
1052 // about the origin in the range [-1:1] at depth of -1
1053 glScalef(1./320, 1./240, 1);
1054 glTranslatef(-320, -240, -1);
1059 // Clean up our mess
1060 glMatrixMode(GL_PROJECTION);
1062 glMatrixMode(GL_MODELVIEW);
1066 void fgUpdateHUD( GLfloat x_start, GLfloat y_start,
1067 GLfloat x_end, GLfloat y_end )
1069 glMatrixMode(GL_PROJECTION);
1072 gluOrtho2D(x_start, x_end, y_start, y_end);
1074 glMatrixMode(GL_MODELVIEW);
1080 glMatrixMode(GL_PROJECTION);
1082 glMatrixMode(GL_MODELVIEW);
1088 if( !HUD_deque.size() ) { // Trust everyone, but ALWAYS cut the cards!
1092 HUD_TextList.erase();
1093 HUD_LineList.erase();
1094 // HUD_StippleLineList.erase();
1096 glDisable(GL_DEPTH_TEST);
1097 glDisable(GL_LIGHTING);
1099 static const SGPropertyNode * antialiased_node
1100 = fgGetNode("/sim/hud/antialiased");
1102 if( antialiased_node->getBoolValue() ) {
1103 glEnable(GL_LINE_SMOOTH);
1104 // glEnable(GL_BLEND);
1105 glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
1106 glHint(GL_LINE_SMOOTH_HINT,GL_DONT_CARE);
1112 if( global_day_night_switch == HUD_DAY) {
1113 switch (HUD_deque[0]->get_brightness())
1116 set_hud_color (0.1f, 0.9f, 0.1f);
1119 case HUD_BRT_MEDIUM:
1120 set_hud_color (0.1f, 0.7f, 0.0f);
1124 set_hud_color (0.0f, 0.6f, 0.0f);
1128 set_hud_color( 0.0f, 0.0f, 0.0f);
1132 set_hud_color (0.1f, 0.9f, 0.1f);
1135 if( global_day_night_switch == HUD_NIGHT) {
1136 switch (HUD_deque[0]->get_brightness())
1139 set_hud_color (0.9f, 0.1f, 0.1f);
1142 case HUD_BRT_MEDIUM:
1143 set_hud_color (0.7f, 0.0f, 0.1f);
1147 set_hud_color (0.6f, 0.0f, 0.0f);
1151 set_hud_color( 0.0f, 0.0f, 0.0f);
1155 set_hud_color (0.6f, 0.0f, 0.0f);
1157 } else { // Just in case default
1158 set_hud_color (0.1f, 0.9f, 0.1f);
1162 for_each(HUD_deque.begin(), HUD_deque.end(), HUDdraw());
1164 HUD_TextList.add( fgText(40, 10, get_formated_gmt_time(), 0) );
1166 #ifdef FG_NETWORK_OLK
1167 if ( net_hud_display ) {
1174 // char scratch[128];
1175 // HUD_TextList.add( fgText( "AUTOPILOT", 20, apY) );
1177 FGAutopilot *AP = globals->get_autopilot();
1179 if( AP->get_HeadingEnabled() ) {
1180 HUD_TextList.add( fgText( 40, apY, AP->get_TargetHeadingStr()) );
1183 if( AP->get_AltitudeEnabled() ) {
1184 HUD_TextList.add( fgText( 40, apY, AP->get_TargetAltitudeStr()) );
1187 if( AP->get_HeadingMode() == FGAutopilot::FG_HEADING_WAYPOINT )
1189 if ( strlen( AP->get_TargetWP1Str() ) ) {
1190 HUD_TextList.add( fgText( 40, apY, AP->get_TargetWP1Str() ) );
1193 if ( strlen( AP->get_TargetWP2Str() ) ) {
1194 HUD_TextList.add( fgText( 40, apY, AP->get_TargetWP2Str() ) );
1197 if ( strlen( AP->get_TargetWP3Str() ) ) {
1198 HUD_TextList.add( fgText( 40, apY, AP->get_TargetWP3Str() ) );
1203 HUD_TextList.draw();
1205 HUD_LineList.draw();
1207 // glEnable(GL_LINE_STIPPLE);
1208 // glLineStipple( 1, 0x00FF );
1209 // HUD_StippleLineList.draw();
1210 // glDisable(GL_LINE_STIPPLE);
1212 if( antialiased_node->getBoolValue() ) {
1213 // glDisable(GL_BLEND);
1214 glDisable(GL_LINE_SMOOTH);
1218 glEnable(GL_DEPTH_TEST);
1219 glEnable(GL_LIGHTING);