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 glScalef( current_options.get_fov()/55.0, 1.0, 1.0 );
112 glRotatef(roll_value * RAD_TO_DEG, 0.0, 0.0, 1.0);
114 // Draw the target spot.
115 #define CENTER_DIAMOND_SIZE 6.0
116 glBegin(GL_LINE_LOOP);
117 glVertex2f( -CENTER_DIAMOND_SIZE, 0.0);
118 glVertex2f(0.0, CENTER_DIAMOND_SIZE);
119 glVertex2f( CENTER_DIAMOND_SIZE, 0.0);
120 glVertex2f(0.0, -CENTER_DIAMOND_SIZE);
122 #undef CENTER_DIAMOND_SIZE
137 float text_offset = 4.0f ;
138 float zero_offset = 10.0f ;
140 fntFont *font = HUDtext->getFont();
141 float pointsize = HUDtext->getPointSize();
142 float italic = HUDtext->getSlant();
144 TextList.setFont( HUDtext );
147 StippleLineList.erase();
149 int last = FloatToInt(vmax)+1;
150 int i = FloatToInt(vmin);
153 for( ; i<last ; i++ ) {
155 y = (((float)(i - pitch_value) * factor) + .5f);
156 if( !(i % div_units )) { // At integral multiple of div
158 sprintf( TextLadder, "%d", i );
159 font->getBBox ( TextLadder, pointsize, italic,
160 &left, &right, &bot, &top ) ;
161 label_length = right - left;
162 label_length += text_offset;
163 label_height = (top - bot)/2.0f;
169 // Make zero point wider on left
171 x_ini -= zero_offset;
172 // Zero or above draw solid lines
173 Line(x_ini, y, x_end, y);
175 // Below zero draw dashed lines.
176 StippleLine(x_ini, y, x_end, y);
179 // Calculate the position of the left text and write it.
180 Text( x_ini-label_length, y-label_height, TextLadder );
181 Text( x_end+text_offset, y-label_height, TextLadder );
185 else // if(scr_hole )
186 { // Draw ladder with space in the middle of the lines
187 float hole = (float)((scr_hole)/2.0f);
188 for( ; i<last ; i++ ) {
190 y = (((float)(i - pitch_value) * factor) + .5);
191 if( !(i % div_units )) { // At integral multiple of div
193 sprintf( TextLadder, "%d", i );
194 font->getBBox ( TextLadder, pointsize, italic,
195 &left, &right, &bot, &top ) ;
196 label_length = right - left;
197 label_length += text_offset;
198 label_height = (top - bot)/2.0f;
199 // printf("l %f r %f b %f t %f\n",left, right, bot, top );
201 // Start by calculating the points and drawing the
204 x_end = -half_span + hole;
207 // Make zero point wider on left
209 x_ini -= zero_offset;
210 // Zero or above draw solid lines
211 Line(x_ini, y, x_end, y);
213 // Below zero draw dashed lines.
214 StippleLine(x_ini, y, x_end, y);
217 // Now calculate the location of the left side label using
218 Text( x_ini-label_length, y-label_height, TextLadder );
220 // Now calculate and draw the right side line location
221 x_ini = half_span - hole;
226 x_end += zero_offset;
227 // Zero or above draw solid lines
228 Line(x_ini, y, x_end, y);
230 // Below zero draw dashed lines.
231 StippleLine(x_ini, y, x_end, y);
234 // Calculate the location and draw the right side label
235 Text( x_end+text_offset, y-label_height, TextLadder );
245 glEnable(GL_LINE_STIPPLE);
246 glLineStipple( 1, 0x00FF );
247 StippleLineList.draw( );
248 glDisable(GL_LINE_STIPPLE);