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,
33 dual_instr_item( x, y, width, height,
38 width_units ( (int)(span_units) ),
39 div_units ( (int)(major_div < 0? -major_div: major_div) ),
40 minor_div ( (int)(minor_div) ),
41 label_pos ( lbl_pos ),
42 scr_hole ( screen_hole ),
43 vmax ( span_units/2 ),
49 factor = (float)get_span() / (float) width_units;
52 HudLadder :: ~HudLadder()
57 HudLadder( const HudLadder & image ) :
58 dual_instr_item( (dual_instr_item &) image),
59 width_units ( image.width_units ),
60 div_units ( image.div_units ),
61 label_pos ( image.label_pos ),
62 scr_hole ( image.scr_hole ),
65 factor ( image.factor )
68 HudLadder & HudLadder :: operator = ( const HudLadder & rhs )
70 if( !(this == &rhs)) {
71 (dual_instr_item &)(*this) = (dual_instr_item &)rhs;
72 width_units = rhs.width_units;
73 div_units = rhs.div_units;
74 label_pos = rhs.label_pos;
75 scr_hole = rhs.scr_hole;
84 // Draws a climb ladder in the center of the HUD
87 void HudLadder :: draw( void )
93 POINT centroid = get_centroid();
94 RECT box = get_location();
96 float half_span = box.right / 2.0;
97 float roll_value = current_ch2();
99 float pitch_value = current_ch1() * RAD_TO_DEG;
100 vmin = pitch_value - (float)width_units/2.0;
101 vmax = pitch_value + (float)width_units/2.0;
104 glTranslatef( centroid.x, centroid.y, 0);
105 glRotatef(roll_value * RAD_TO_DEG, 0.0, 0.0, 1.0);
107 // Draw the target spot.
108 #define CENTER_DIAMOND_SIZE 6.0
109 glBegin(GL_LINE_LOOP);
110 glVertex2f( -CENTER_DIAMOND_SIZE, 0.0);
111 glVertex2f(0.0, CENTER_DIAMOND_SIZE);
112 glVertex2f( CENTER_DIAMOND_SIZE, 0.0);
113 glVertex2f(0.0, -CENTER_DIAMOND_SIZE);
115 #undef CENTER_DIAMOND_SIZE
125 float text_offset = 4.0f ;
126 float zero_offset = 10.0f ;
128 fntFont *font = HUDtext->getFont();
129 float pointsize = HUDtext->getPointSize();
130 float italic = HUDtext->getSlant();
132 TextList.setFont( HUDtext );
135 StippleLineList.erase();
137 int last = FloatToInt(vmax)+1;
138 int i = FloatToInt(vmin);
141 for( ; i<last ; i++ ) {
143 y = (((float)(i - pitch_value) * factor) + .5f);
144 if( !(i % div_units )) { // At integral multiple of div
146 sprintf( TextLadder, "%d", i );
147 font->getBBox ( TextLadder, pointsize, italic,
148 &left, &right, &bot, &top ) ;
149 label_length = right - left;
150 label_length += text_offset;
151 label_height = (top - bot)/2.0f;
157 // Make zero point wider on left
159 x_ini -= zero_offset;
160 // Zero or above draw solid lines
161 Line(x_ini, y, x_end, y);
163 // Below zero draw dashed lines.
164 StippleLine(x_ini, y, x_end, y);
167 // Calculate the position of the left text and write it.
168 Text( x_ini-label_length, y-label_height, TextLadder );
169 Text( x_end+text_offset, y-label_height, TextLadder );
173 else // if(scr_hole )
174 { // Draw ladder with space in the middle of the lines
175 float hole = (float)((scr_hole)/2.0f);
176 for( ; i<last ; i++ ) {
178 y = (((float)(i - pitch_value) * factor) + .5);
179 if( !(i % div_units )) { // At integral multiple of div
181 sprintf( TextLadder, "%d", i );
182 font->getBBox ( TextLadder, pointsize, italic,
183 &left, &right, &bot, &top ) ;
184 label_length = right - left;
185 label_length += text_offset;
186 label_height = (top - bot)/2.0f;
187 // printf("l %f r %f b %f t %f\n",left, right, bot, top );
189 // Start by calculating the points and drawing the
192 x_end = -half_span + hole;
195 // Make zero point wider on left
197 x_ini -= zero_offset;
198 // Zero or above draw solid lines
199 Line(x_ini, y, x_end, y);
201 // Below zero draw dashed lines.
202 StippleLine(x_ini, y, x_end, y);
205 // Now calculate the location of the left side label using
206 Text( x_ini-label_length, y-label_height, TextLadder );
208 // Now calculate and draw the right side line location
209 x_ini = half_span - hole;
214 x_end += zero_offset;
215 // Zero or above draw solid lines
216 Line(x_ini, y, x_end, y);
218 // Below zero draw dashed lines.
219 StippleLine(x_ini, y, x_end, y);
222 // Calculate the location and draw the right side label
223 Text( x_end+text_offset, y-label_height, TextLadder );
233 glEnable(GL_LINE_STIPPLE);
234 glLineStipple( 1, 0x00FF );
235 StippleLineList.draw( );
236 glDisable(GL_LINE_STIPPLE);