10 #include <Aircraft/aircraft.hxx>
11 #include <Include/fg_constants.h>
12 #include <Math/fg_random.h>
13 #include <Math/mat3.h>
14 #include <Math/polar3d.hxx>
15 #include <Scenery/scenery.hxx>
16 #include <Time/fg_timer.hxx>
20 //====================== Top of HudLadder Class =======================
21 HudLadder :: HudLadder( int x,
34 dual_instr_item( x, y, width, height,
39 width_units ( (int)(span_units) ),
40 div_units ( (int)(major_div < 0? -major_div: major_div) ),
41 minor_div ( (int)(minor_div) ),
42 label_pos ( lbl_pos ),
43 scr_hole ( screen_hole ),
44 vmax ( span_units/2 ),
50 factor = (float)get_span() / (float) width_units;
54 HudLadder :: ~HudLadder()
59 HudLadder( const HudLadder & image ) :
60 dual_instr_item( (dual_instr_item &) image),
61 width_units ( image.width_units ),
62 div_units ( image.div_units ),
63 label_pos ( image.label_pos ),
64 scr_hole ( image.scr_hole ),
67 factor ( image.factor )
70 HudLadder & HudLadder :: operator = ( const HudLadder & rhs )
72 if( !(this == &rhs)) {
73 (dual_instr_item &)(*this) = (dual_instr_item &)rhs;
74 width_units = rhs.width_units;
75 div_units = rhs.div_units;
76 label_pos = rhs.label_pos;
77 scr_hole = rhs.scr_hole;
86 // Draws a climb ladder in the center of the HUD
89 void HudLadder :: draw( void )
95 POINT centroid = get_centroid();
96 RECT box = get_location();
98 float half_span = box.right / 2.0;
99 float roll_value = current_ch2();
101 float pitch_value = current_ch1() * RAD_TO_DEG;
102 vmin = pitch_value - (float)width_units/2.0;
103 vmax = pitch_value + (float)width_units/2.0;
106 glTranslatef( centroid.x, centroid.y, 0);
107 glRotatef(roll_value * RAD_TO_DEG, 0.0, 0.0, 1.0);
109 // Draw the target spot.
110 #define CENTER_DIAMOND_SIZE 6.0
111 glBegin(GL_LINE_LOOP);
112 glVertex2f( -CENTER_DIAMOND_SIZE, 0.0);
113 glVertex2f(0.0, CENTER_DIAMOND_SIZE);
114 glVertex2f( CENTER_DIAMOND_SIZE, 0.0);
115 glVertex2f(0.0, -CENTER_DIAMOND_SIZE);
117 #undef CENTER_DIAMOND_SIZE
132 float text_offset = 4.0f ;
133 float zero_offset = 10.0f ;
135 fntFont *font = HUDtext->getFont();
136 float pointsize = HUDtext->getPointSize();
137 float italic = HUDtext->getSlant();
139 TextList.setFont( HUDtext );
142 StippleLineList.erase();
144 int last = FloatToInt(vmax)+1;
145 int i = FloatToInt(vmin);
148 for( ; i<last ; i++ ) {
150 y = (((float)(i - pitch_value) * factor) + .5f);
151 if( !(i % div_units )) { // At integral multiple of div
153 sprintf( TextLadder, "%d", i );
154 font->getBBox ( TextLadder, pointsize, italic,
155 &left, &right, &bot, &top ) ;
156 label_length = right - left;
157 label_length += text_offset;
158 label_height = (top - bot)/2.0f;
164 // Make zero point wider on left
166 x_ini -= zero_offset;
167 // Zero or above draw solid lines
168 Line(x_ini, y, x_end, y);
170 // Below zero draw dashed lines.
171 StippleLine(x_ini, y, x_end, y);
174 // Calculate the position of the left text and write it.
175 Text( x_ini-label_length, y-label_height, TextLadder );
176 Text( x_end+text_offset, y-label_height, TextLadder );
180 else // if(scr_hole )
181 { // Draw ladder with space in the middle of the lines
182 float hole = (float)((scr_hole)/2.0f);
183 for( ; i<last ; i++ ) {
185 y = (((float)(i - pitch_value) * factor) + .5);
186 if( !(i % div_units )) { // At integral multiple of div
188 sprintf( TextLadder, "%d", i );
189 font->getBBox ( TextLadder, pointsize, italic,
190 &left, &right, &bot, &top ) ;
191 label_length = right - left;
192 label_length += text_offset;
193 label_height = (top - bot)/2.0f;
194 // printf("l %f r %f b %f t %f\n",left, right, bot, top );
196 // Start by calculating the points and drawing the
199 x_end = -half_span + hole;
202 // Make zero point wider on left
204 x_ini -= zero_offset;
205 // Zero or above draw solid lines
206 Line(x_ini, y, x_end, y);
208 // Below zero draw dashed lines.
209 StippleLine(x_ini, y, x_end, y);
212 // Now calculate the location of the left side label using
213 Text( x_ini-label_length, y-label_height, TextLadder );
215 // Now calculate and draw the right side line location
216 x_ini = half_span - hole;
221 x_end += zero_offset;
222 // Zero or above draw solid lines
223 Line(x_ini, y, x_end, y);
225 // Below zero draw dashed lines.
226 StippleLine(x_ini, y, x_end, y);
229 // Calculate the location and draw the right side label
230 Text( x_end+text_offset, y-label_height, TextLadder );
240 glEnable(GL_LINE_STIPPLE);
241 glLineStipple( 1, 0x00FF );
242 StippleLineList.draw( );
243 glDisable(GL_LINE_STIPPLE);