1 // hud.hxx -- hud defines and prototypes (initial draft)
3 // Written by Michele America, started September 1997.
5 // Copyright (C) 1997 Michele F. America - nomimarketing@mail.telepac.pt
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
28 # error This library requires C++
31 #include <simgear/compiler.h>
44 //#ifdef HAVE_VALUES_H
45 //# include <values.h> // for MAXINT
48 #include <algorithm> // for_each()
49 #include <vector> // STL vector
50 #include <deque> // STL double ended queue
53 #include <simgear/constants.h>
55 #include <Include/fg_typedefs.h>
56 #include <Aircraft/aircraft.hxx>
57 #include <Aircraft/controls.hxx>
58 #include <FDM/flight.hxx>
60 #include <Main/globals.hxx>
61 #include <Main/viewmgr.hxx>
62 #include <Airports/runways.hxx>
64 #include "hud_opts.hxx"
69 SG_USING_NAMESPACE(std);
72 // some of Norman's crazy optimizations. :-)
80 int top, bottom, left, right;
84 // View mode definitions
86 enum VIEW_MODES{ HUD_VIEW, PANEL_VIEW, CHASE_VIEW, TOWER_VIEW };
88 // DAY, NIGHT and brightness levels need to be visible where dialogs and
89 // controls can be used to set intensity and appropriate color. This will
91 // Hud general constants
94 #define HUD_BRT_BLACK 3
95 #define HUD_BRT_DARK 4
96 #define HUD_BRT_MEDIUM 5
97 #define HUD_BRT_LIGHT 6
100 #define HUD_FONT_SMALL 1
101 #define HUD_FONT_LARGE 2
103 enum fgLabelJust{ LEFT_JUST, CENTER_JUST, RIGHT_JUST } ;
105 #define HUDS_AUTOTICKS 0x0001
106 #define HUDS_VERT 0x0002
107 #define HUDS_HORZ 0x0000
108 #define HUDS_TOP 0x0004
109 #define HUDS_BOTTOM 0x0008
110 #define HUDS_LEFT HUDS_TOP
111 #define HUDS_RIGHT HUDS_BOTTOM
112 #define HUDS_BOTH (HUDS_LEFT | HUDS_RIGHT)
113 #define HUDS_NOTICKS 0x0010
114 #define HUDS_ARITHTIC 0x0020
115 #define HUDS_DECITICS 0x0040
116 #define HUDS_NOTEXT 0x0080
119 // #define HUD_VERTICAL 1
120 // #define HUD_HORIZONTAL 2
121 // #define HUD_FREEFLOAT 3
123 // Ladder orientation modes
124 // #define HUD_LEFT 1
125 // #define HUD_RIGHT 2
127 // #define HUD_BOTTOM 2
128 // #define HUD_V_LEFT 1
129 // #define HUD_V_RIGHT 2
130 // #define HUD_H_TOP 1
131 // #define HUD_H_BOTTOM 2
136 // #define HUD_NOLIM 2
137 // #define HUD_CIRC 3
139 // #define HUD_INSTR_LADDER 1
140 // #define HUD_INSTR_CLADDER 2
141 // #define HUD_INSTR_HORIZON 3
142 // #define HUD_INSTR_LABEL 4
145 extern float get_throttleval ( void );
146 extern float get_aileronval ( void );
147 extern float get_elevatorval ( void );
148 extern float get_elev_trimval( void );
149 extern float get_rudderval ( void );
150 extern float get_speed ( void );
151 extern float get_aoa ( void );
152 extern float get_nlf ( void );
153 extern float get_roll ( void );
154 extern float get_pitch ( void );
155 extern float get_heading ( void );
156 extern float get_view_direction( void );
157 extern float get_altitude ( void );
158 extern float get_agl ( void );
159 extern float get_sideslip ( void );
160 extern float get_frame_rate ( void );
161 extern float get_latitude ( void );
162 extern float get_lat_min ( void );
163 extern float get_longitude ( void );
164 extern float get_long_min ( void );
165 extern float get_fov ( void );
166 extern float get_vfc_ratio ( void );
167 extern float get_vfc_tris_drawn ( void );
168 extern float get_vfc_tris_culled ( void );
169 extern float get_climb_rate ( void );
170 extern float get_mach( void );
171 extern char *coord_format_lat(float);
172 extern char *coord_format_lon(float);
173 //extern char *coord_format_latlon(float latitude, float longitude); // cockpit.cxx
175 // $$$ begin - added, VS Renganathan, 13 Oct 2K
176 // #define FIGHTER_HUD
177 extern float get_anzg (void);
178 extern float get_Vx (void);
179 extern float get_Vy (void);
180 extern float get_Vz (void);
181 extern float get_Ax (void);
182 extern float get_Ay (void);
183 extern float get_Az (void);
184 extern int get_iaux1 (void);
185 extern int get_iaux2 (void);
186 extern int get_iaux3 (void);
187 extern int get_iaux4 (void);
188 extern int get_iaux5 (void);
189 extern int get_iaux6 (void);
190 extern int get_iaux7 (void);
191 extern int get_iaux8 (void);
192 extern int get_iaux9 (void);
193 extern int get_iaux10 (void);
194 extern int get_iaux11 (void);
195 extern int get_iaux12 (void);
196 extern float get_aux1(void);
197 extern float get_aux2(void);
198 extern float get_aux3(void);
199 extern float get_aux4(void);
200 extern float get_aux5 (void);
201 extern float get_aux6 (void);
202 extern float get_aux7 (void);
203 extern float get_aux8(void);
204 extern float get_aux9(void);
205 extern float get_aux10(void);
206 extern float get_aux11(void);
207 extern float get_aux12(void);
208 extern float get_aux13(void);
209 extern float get_aux14(void);
210 extern float get_aux15(void);
211 extern float get_aux16(void);
212 extern float get_aux17(void);
213 extern float get_aux18(void);
214 // $$$ end - added, VS Renganathan, 13 Oct 2K
216 extern char *get_formated_gmt_time( void );
217 extern void fgHUDReshape(void);
219 enum hudinstype{ HUDno_instr,
231 typedef struct gltagRGBTRIPLE { // rgbt
239 GLfloat x0, y0, x1, y1;
242 fgLineSeg2D( GLfloat a = 0, GLfloat b =0, GLfloat c = 0, GLfloat d =0 )
243 : x0(a), y0(b), x1(c), y1(d) {}
245 fgLineSeg2D( const fgLineSeg2D & image )
246 : x0(image.x0), y0(image.y0), x1(image.x1), y1(image.y1) {}
248 fgLineSeg2D& operator= ( const fgLineSeg2D & image ) {
249 x0 = image.x0; y0 = image.y0; x1 = image.x1; y1 = image.y1; return *this;
261 class DrawLineSeg2D {
263 void operator() (const fgLineSeg2D& elem) const {
269 #define USE_HUD_TextList
270 extern fntTexFont *HUD_Font;
271 extern float HUD_TextSize;
272 extern fntRenderer *HUDtext;
273 extern float HUD_matrix[16];
281 fgText(float x = 0, float y = 0, char *c = NULL,int digits=0): x(x), y(y) //suma
287 fgText( const fgText & image )
288 : x(image.x), y(image.y),digit(image.digit) {strcpy(msg,image.msg);} //suma
290 fgText& operator = ( const fgText & image ) {
291 strcpy(msg,image.msg); x = image.x; y = image.y;digit=image.digit; //suma
295 ~fgText() {msg[0]='\0';}
297 int getStringWidth ( char *str )
299 if ( HUDtext && str ) {
301 HUD_Font->getBBox ( str, HUD_TextSize, 0, &l, &r, NULL, NULL ) ;
302 return FloatToInt( r - l );
307 int StringWidth (void )
309 if ( HUDtext && strlen( msg )) {
311 HUD_Font->getBBox ( msg, HUD_TextSize, 0, &l, &r, NULL, NULL ) ;
312 return FloatToInt( r - l );
317 // this code is changed to display Numbers with big/small digits
318 // according to MIL Standards for example Altitude above 10000 ft
319 // is shown as 10ooo. begin suma
321 void Draw(fntRenderer *fnt,int digits) {
328 //if negative value then increase the c and p values
333 while(tmp[i]!='\0') {
334 if((tmp[i]>='0') && (tmp[i]<='9'))
339 fnt->setPointSize(HUD_TextSize * 0.8);
344 fnt->start2f(x+p2,y);
347 fnt->setPointSize(HUD_TextSize * 1.2);
349 strncpy(tmp2,msg,p1);
355 fnt->setPointSize(HUD_TextSize * 1.2);
356 fnt->start2f( x, y );
360 //if digits not equal to 1
361 fnt->setPointSize(HUD_TextSize * 0.8);
362 fnt->start2f( x, y );
370 guiFnt.drawString( msg, FloatToInt(x), FloatToInt(y) );
375 vector < fgLineSeg2D > List;
377 fgLineList( void ) {}
378 ~fgLineList( void ) {}
379 void add( const fgLineSeg2D& seg ) { List.push_back(seg); }
380 void erase( void ) { List.erase( List.begin(), List.end() ); }
383 for_each( List.begin(), List.end(), DrawLineSeg2D());
390 vector< fgText > List;
392 fgTextList ( void ) { Font = 0; }
393 ~fgTextList( void ) {}
395 void setFont( fntRenderer *Renderer ) { Font = Renderer; }
396 void add( const fgText& String ) { List.push_back(String); }
397 void erase( void ) { List.erase( List.begin(), List.end() ); }
402 vector < fgText > :: iterator curString = List.begin();
403 vector < fgText > :: iterator lastString = List.end();
405 glPushAttrib( GL_COLOR_BUFFER_BIT );
406 glEnable ( GL_ALPHA_TEST ) ;
407 glEnable ( GL_BLEND ) ;
408 glAlphaFunc ( GL_GREATER, 0.1 ) ;
409 glBlendFunc ( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ) ;
412 for( ; curString != lastString; curString++ ) {
413 curString->Draw(Font,curString->digit); //suma
417 glDisable ( GL_TEXTURE_2D ) ;
423 inline void Text( fgTextList &List, float x, float y, char *s)
425 List.add( fgText( x, y, s) );
428 inline void Text( fgTextList &List, const fgText &me)
433 inline void Line( fgLineList &List, float x1, float y1, float x2, float y2)
435 List.add(fgLineSeg2D(x1,y1,x2,y2));
439 // Declare our externals
440 extern fgTextList HUD_TextList;
441 extern fgLineList HUD_LineList;
442 extern fgLineList HUD_StippleLineList;
445 class instr_item { // An Abstract Base Class (ABC)
447 static UINT instances; // More than 64K instruments? Nah!
448 static int brightness;
449 static glRGBTRIPLE color;
452 RECT scrn_pos; // Framing - affects scale dimensions
453 // and orientation. Vert vs Horz, etc.
454 FLTFNPTR load_value_fn;
455 float disp_factor; // Multiply by to get numbers shown on scale.
459 UINT scr_span; // Working values for draw;
468 FLTFNPTR data_source,
472 int digit = 0); //suma
474 instr_item( const instr_item & image );
476 instr_item & operator = ( const instr_item & rhs );
477 virtual ~instr_item ();
479 int get_brightness ( void ) { return brightness;}
480 RECT get_location ( void ) { return scrn_pos; }
481 bool is_broken ( void ) { return broken; }
482 bool enabled ( void ) { return is_enabled;}
483 bool data_available ( void ) { return !!load_value_fn; }
484 float get_value ( void ) { return load_value_fn(); }
485 float data_scaling ( void ) { return disp_factor; }
486 UINT get_span ( void ) { return scr_span; }
487 POINT get_centroid ( void ) { return mid_span; }
488 UINT get_options ( void ) { return opts; }
489 int get_digits ( void ) { return digits; } //suma
491 UINT huds_vert (UINT options) { return( options & HUDS_VERT ); }
492 UINT huds_left (UINT options) { return( options & HUDS_LEFT ); }
493 UINT huds_right (UINT options) { return( options & HUDS_RIGHT ); }
494 UINT huds_both (UINT options) {
495 return( (options & HUDS_BOTH) == HUDS_BOTH );
497 UINT huds_noticks (UINT options) { return( options & HUDS_NOTICKS ); }
498 UINT huds_notext (UINT options) { return( options & HUDS_NOTEXT ); }
499 UINT huds_top (UINT options) { return( options & HUDS_TOP ); }
500 UINT huds_bottom (UINT options) { return( options & HUDS_BOTTOM ); }
502 virtual void display_enable( bool working ) { is_enabled = !! working;}
504 virtual void update( void );
505 virtual void break_display ( bool bad );
506 virtual void SetBrightness( int illumination_level ); // fgHUDSetBright...
507 void SetPosition ( int x, int y, UINT width, UINT height );
508 UINT get_Handle( void );
509 virtual void draw( void ) = 0; // Required method in derived classes
511 void drawOneLine( float x1, float y1, float x2, float y2)
513 HUD_LineList.add(fgLineSeg2D(x1,y1,x2,y2));
515 void drawOneStippleLine( float x1, float y1, float x2, float y2)
517 HUD_StippleLineList.add(fgLineSeg2D(x1,y1,x2,y2));
519 void TextString( char *msg, float x, float y,int digit ) //suma
521 HUD_TextList.add(fgText(x, y, msg,digit)); //suma
523 int getStringWidth ( char *str )
525 if ( HUDtext && str ) {
527 HUD_Font->getBBox ( str, HUD_TextSize, 0, &l, &r, NULL, NULL ) ;
528 return FloatToInt( r - l );
533 //code to draw ticks as small circles
534 void drawOneCircle(float x1, float y1, float r)
536 glBegin(GL_LINE_LOOP); // Use polygon to approximate a circle
537 for(int count=0; count<25; count++) {
538 float cosine = r * cos(count * 2 * SG_PI/10.0);
539 float sine = r * sin(count * 2 * SG_PI/10.0);
540 glVertex2f(cosine+x1, sine+y1);
547 typedef instr_item *HIptr;
551 void operator() (HIptr elem) const {
557 //typedef deque < instr_item * > hud_deque_type;
558 //typedef hud_deque_type::iterator hud_deque_iterator;
559 //typedef hud_deque_type::const_iterator hud_deque_const_iterator;
561 extern deque< instr_item *> HUD_deque;
562 extern int HUD_style;
563 //extern hud_deque_type HUD_deque;
565 // instr_item This class has no other purpose than to maintain
566 // a linked list of instrument and derived class
570 class instr_label : public instr_item {
574 const char *post_str;
578 char format_buffer[80];
588 FLTFNPTR data_source,
589 const char *label_format,
590 const char *pre_label_string,
591 const char *post_label_string,
594 fgLabelJust justification,
601 int digit ); //suma);
605 instr_label( const instr_label & image);
606 instr_label & operator = (const instr_label & rhs );
607 virtual void draw( void ); // Required method in base class
610 typedef instr_label * pInstlabel;
613 class lat_label : public instr_item {
617 const char *post_str;
621 char format_buffer[80];
628 FLTFNPTR data_source,
629 const char *label_format,
630 const char *pre_label_string,
631 const char *post_label_string,
634 fgLabelJust justification,
638 int digits =0 );//suma
642 lat_label( const lat_label & image);
643 lat_label & operator = (const lat_label & rhs );
644 virtual void draw( void ); // Required method in base class
647 typedef lat_label * pLatlabel;
649 class lon_label : public instr_item {
653 const char *post_str;
657 char format_buffer[80];
664 FLTFNPTR data_source,
665 const char *label_format,
666 const char *pre_label_string,
667 const char *post_label_string,
670 fgLabelJust justification,
679 lon_label( const lon_label & image);
680 lon_label & operator = (const lon_label & rhs );
681 virtual void draw( void ); // Required method in base class
684 typedef lon_label * pLonlabel;
687 // fgRunway_instr This class is responsible for rendering the active runway
688 // in the hud (if visible).
689 class runway_instr : public instr_item
692 void boundPoint(const sgdVec3& v, sgdVec3& m);
693 bool boundOutsidePoints(sgdVec3& v, sgdVec3& m);
694 bool drawLine(const sgdVec3& a1, const sgdVec3& a2, const sgdVec3& p1, const sgdVec3& p2);
696 bool get_active_runway(FGRunway& rwy);
697 void get_rwy_points(sgdVec3 *points);
698 void setLineWidth(void);
700 sgdVec3 points3d[6],points2d[6];
701 double mm[16],pm[16], arrowScale, arrowRad, lnScale, scaleDist, default_pitch, default_heading;
704 FGViewer* cockpit_view;
705 unsigned short stippleOut,stippleCen;
706 bool drawIA,drawIAAlways;
716 bool working = true);
718 virtual void draw( void ); // Required method in base class
719 void setArrowRotationRadius(double radius);
720 void setArrowScale(double scale); // Scales the runway indication arrow
721 void setDrawArrow(bool draw); // Draws arrow when runway is not visible in HUD if draw=true
722 void setDrawArrowAlways(bool draw); //Always draws arrow if draw=true;
723 void setLineScale(double scale); //Sets the maximum line scale
724 void setScaleDist(double dist_nm); //Sets the distance where to start scaling the lines
725 void setStippleOutline(unsigned short stipple); //Sets the stipple pattern of the outline of the runway
726 void setStippleCenterline(unsigned short stipple); //Sets the stipple patter of the center line of the runway
731 // instr_scale This class is an abstract base class for both moving
732 // scale and moving needle (fixed scale) indicators. It
733 // does not draw itself, but is not instanciable.
736 class instr_scale : public instr_item {
738 float range_shown; // Width Units.
739 float Maximum_value; // ceiling.
740 float Minimum_value; // Representation floor.
741 float scale_factor; // factor => screen units/range values.
742 UINT Maj_div; // major division marker units
743 UINT Min_div; // minor division marker units
744 UINT Modulo; // Roll over point
745 int signif_digits; // digits to show to the right.
762 bool working = true);
764 virtual ~instr_scale();
765 instr_scale( const instr_scale & image);
766 instr_scale & operator = (const instr_scale & rhs);
768 virtual void draw ( void ) {}; // No-op here. Defined in derived classes.
769 UINT div_min ( void ) { return Min_div;}
770 UINT div_max ( void ) { return Maj_div;}
771 float min_val ( void ) { return Minimum_value;}
772 float max_val ( void ) { return Maximum_value;}
773 UINT modulo ( void ) { return Modulo; }
774 float factor ( void ) { return scale_factor;}
775 float range_to_show( void ) { return range_shown;}
778 // hud_card_ This class displays the indicated quantity on
779 // a scale that moves past the pointer. It may be
780 // horizontal or vertical, read above(left) or below(right) of the base
783 class hud_card : public instr_scale {
787 float half_width_units;
788 bool draw_tick_bottom;
790 bool draw_tick_right;
792 bool draw_cap_bottom;
802 float maxValue; //suma
803 float minValue; //suma
804 int divisions; //suma
826 bool draw_tick_bottom,
828 bool draw_tick_right,
830 bool draw_cap_bottom,
841 int divisions, //suma
847 hud_card( const hud_card & image);
848 hud_card & operator = (const hud_card & rhs );
849 // virtual void display_enable( bool setting );
850 virtual void draw( void ); // Required method in base class
851 void circles(float,float,float); // suma
852 void fixed(float,float,float,float,float,float); //suma
853 void zoomed_scale(int,int); //suma
856 typedef hud_card * pCardScale;
858 class gauge_instr : public instr_scale {
876 gauge_instr( const gauge_instr & image);
877 gauge_instr & operator = (const gauge_instr & rhs );
878 virtual void draw( void ); // Required method in base class
881 typedef gauge_instr * pGaugeInst;
883 // dual_instr_item This class was created to form the base class
884 // for both panel and HUD Turn Bank Indicators.
886 class dual_instr_item : public instr_item {
888 FLTFNPTR alt_data_source;
891 dual_instr_item ( int x,
895 FLTFNPTR chn1_source,
896 FLTFNPTR chn2_source,
900 virtual ~dual_instr_item() {};
901 dual_instr_item( const dual_instr_item & image);
902 dual_instr_item & operator = (const dual_instr_item & rhs );
904 float current_ch1( void ) { return (float)alt_data_source();}
905 float current_ch2( void ) { return (float)get_value();}
906 virtual void draw ( void ) { }
909 class fgTBI_instr : public dual_instr_item
923 FLTFNPTR chn1_source,
924 FLTFNPTR chn2_source,
932 fgTBI_instr( const fgTBI_instr & image);
933 fgTBI_instr & operator = (const fgTBI_instr & rhs );
937 UINT bank_limit( void ) { return BankLimit;}
938 UINT slew_limit( void ) { return SlewLimit;}
940 virtual void draw( void ); // Required method in base class
943 typedef fgTBI_instr * pTBI;
945 class HudLadder : public dual_instr_item {
955 string hudladder_type;
958 bool velocity_vector;
962 bool climb_dive_marker;
963 bool glide_slope_marker;
966 bool waypoint_marker;
972 // The Ladder has it's own temporary display lists
975 fgLineList StippleLineList;
978 HudLadder( const string& name,
984 FLTFNPTR ptch_source,
985 FLTFNPTR roll_source,
987 float division_units,
988 float minor_division,
993 bool velocity_vector,
997 bool climb_dive_marker,
998 bool glide_slope_marker,
1001 bool waypoint_marker,
1011 HudLadder( const HudLadder & image );
1012 HudLadder & operator = ( const HudLadder & rhs );
1013 virtual void draw( void );
1014 void drawZenith(float,float,float); //suma
1015 void drawNadir(float, float, float); //suma
1017 void Text( float x, float y, char *s)
1019 TextList.add( fgText( x, y, s) );
1022 void Line( float x1, float y1, float x2, float y2)
1024 LineList.add(fgLineSeg2D(x1,y1,x2,y2));
1027 void StippleLine( float x1, float y1, float x2, float y2)
1029 StippleLineList.add(fgLineSeg2D(x1,y1,x2,y2));
1034 //using namespace std;
1035 //deque <instr_item> * Hdeque_ptr;
1037 extern int fgHUDInit( fgAIRCRAFT * /* current_aircraft */ );
1038 extern int fgHUDInit2( fgAIRCRAFT * /* current_aircraft */ );
1039 extern void fgUpdateHUD( void );
1040 extern void fgUpdateHUD( GLfloat x_start, GLfloat y_start,
1041 GLfloat x_end, GLfloat y_end );
1044 bool AddHUDInstrument( instr_item *pBlackBox );
1045 void DrawHUD ( void );
1046 bool DamageInstrument( INSTR_HANDLE unit );
1047 bool RepairInstrument( INSTR_HANDLE unit );
1050 void fgUpdateHUD ( Hptr hud );
1051 void fgUpdateHUD2( Hptr hud ); // Future use?
1052 void fgHUDSetTimeMode( Hptr hud, int time_of_day );
1058 class HUD_Properties : public SGPropertyChangeListener {
1061 void valueChanged(SGPropertyNode *n);
1062 void setColor() const;
1063 bool isVisible() const { return _visible; }
1064 bool isAntialiased() const { return _antialiased; }
1067 float clamp(float f) { return f < 0.0f ? 0.0f : f > 1.0f ? 1.0f : f; }
1068 vector<SGPropertyNode_ptr> _colors;
1069 SGPropertyNode_ptr _which;
1070 SGPropertyNode_ptr _brightness;
1071 SGPropertyNode_ptr _alpha;
1072 SGPropertyNode_ptr _visibility;
1073 SGPropertyNode_ptr _antialiasing;
1074 bool _visible, _antialiased;
1075 float _r, _g, _b, _a;