12 #include <simgear/constants.h>
13 #include <simgear/math/fg_random.h>
14 #include <simgear/math/polar3d.hxx>
16 #include <Aircraft/aircraft.hxx>
17 #include <Scenery/scenery.hxx>
18 #include <Time/fg_timer.hxx>
24 //====================== Top of HudLadder Class =======================
25 HudLadder :: HudLadder( int x,
38 dual_instr_item( x, y, width, height,
43 width_units ( (int)(span_units) ),
44 div_units ( (int)(major_div < 0? -major_div: major_div) ),
45 minor_div ( (int)(minor_div) ),
46 label_pos ( lbl_pos ),
47 scr_hole ( screen_hole ),
48 vmax ( span_units/2 ),
54 factor = (float)get_span() / (float) width_units;
58 HudLadder :: ~HudLadder()
63 HudLadder( const HudLadder & image ) :
64 dual_instr_item( (dual_instr_item &) image),
65 width_units ( image.width_units ),
66 div_units ( image.div_units ),
67 label_pos ( image.label_pos ),
68 scr_hole ( image.scr_hole ),
71 factor ( image.factor )
74 HudLadder & HudLadder :: operator = ( const HudLadder & rhs )
76 if( !(this == &rhs)) {
77 (dual_instr_item &)(*this) = (dual_instr_item &)rhs;
78 width_units = rhs.width_units;
79 div_units = rhs.div_units;
80 label_pos = rhs.label_pos;
81 scr_hole = rhs.scr_hole;
90 // Draws a climb ladder in the center of the HUD
93 void HudLadder :: draw( void )
99 POINT centroid = get_centroid();
100 RECT box = get_location();
102 float half_span = box.right / 2.0;
103 float roll_value = current_ch2();
105 float pitch_value = current_ch1() * RAD_TO_DEG;
106 vmin = pitch_value - (float)width_units/2.0;
107 vmax = pitch_value + (float)width_units/2.0;
110 glTranslatef( centroid.x, centroid.y, 0);
111 glRotatef(roll_value * RAD_TO_DEG, 0.0, 0.0, 1.0);
113 // Draw the target spot.
114 #define CENTER_DIAMOND_SIZE 6.0
115 glBegin(GL_LINE_LOOP);
116 glVertex2f( -CENTER_DIAMOND_SIZE, 0.0);
117 glVertex2f(0.0, CENTER_DIAMOND_SIZE);
118 glVertex2f( CENTER_DIAMOND_SIZE, 0.0);
119 glVertex2f(0.0, -CENTER_DIAMOND_SIZE);
121 #undef CENTER_DIAMOND_SIZE
136 float text_offset = 4.0f ;
137 float zero_offset = 10.0f ;
139 fntFont *font = HUDtext->getFont();
140 float pointsize = HUDtext->getPointSize();
141 float italic = HUDtext->getSlant();
143 TextList.setFont( HUDtext );
146 StippleLineList.erase();
148 int last = FloatToInt(vmax)+1;
149 int i = FloatToInt(vmin);
152 for( ; i<last ; i++ ) {
154 y = (((float)(i - pitch_value) * factor) + .5f);
155 if( !(i % div_units )) { // At integral multiple of div
157 sprintf( TextLadder, "%d", i );
158 font->getBBox ( TextLadder, pointsize, italic,
159 &left, &right, &bot, &top ) ;
160 label_length = right - left;
161 label_length += text_offset;
162 label_height = (top - bot)/2.0f;
168 // Make zero point wider on left
170 x_ini -= zero_offset;
171 // Zero or above draw solid lines
172 Line(x_ini, y, x_end, y);
174 // Below zero draw dashed lines.
175 StippleLine(x_ini, y, x_end, y);
178 // Calculate the position of the left text and write it.
179 Text( x_ini-label_length, y-label_height, TextLadder );
180 Text( x_end+text_offset, y-label_height, TextLadder );
184 else // if(scr_hole )
185 { // Draw ladder with space in the middle of the lines
186 float hole = (float)((scr_hole)/2.0f);
187 for( ; i<last ; i++ ) {
189 y = (((float)(i - pitch_value) * factor) + .5);
190 if( !(i % div_units )) { // At integral multiple of div
192 sprintf( TextLadder, "%d", i );
193 font->getBBox ( TextLadder, pointsize, italic,
194 &left, &right, &bot, &top ) ;
195 label_length = right - left;
196 label_length += text_offset;
197 label_height = (top - bot)/2.0f;
198 // printf("l %f r %f b %f t %f\n",left, right, bot, top );
200 // Start by calculating the points and drawing the
203 x_end = -half_span + hole;
206 // Make zero point wider on left
208 x_ini -= zero_offset;
209 // Zero or above draw solid lines
210 Line(x_ini, y, x_end, y);
212 // Below zero draw dashed lines.
213 StippleLine(x_ini, y, x_end, y);
216 // Now calculate the location of the left side label using
217 Text( x_ini-label_length, y-label_height, TextLadder );
219 // Now calculate and draw the right side line location
220 x_ini = half_span - hole;
225 x_end += zero_offset;
226 // Zero or above draw solid lines
227 Line(x_ini, y, x_end, y);
229 // Below zero draw dashed lines.
230 StippleLine(x_ini, y, x_end, y);
233 // Calculate the location and draw the right side label
234 Text( x_end+text_offset, y-label_height, TextLadder );
244 glEnable(GL_LINE_STIPPLE);
245 glLineStipple( 1, 0x00FF );
246 StippleLineList.draw( );
247 glDisable(GL_LINE_STIPPLE);