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 =======================
34 dual_instr_item( x, y, width, height,
39 width_units ( span_units ),
40 div_units ( major_div < 0? -major_div: major_div ),
41 minor_div ( minor_div ),
42 label_pos ( lbl_pos ),
43 scr_hole ( screen_hole ),
44 vmax ( span_units/2 ),
50 factor = (double)get_span() / (double) width_units;
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 ::
71 operator = ( const HudLadder & rhs )
73 if( !(this == &rhs)) {
74 (dual_instr_item &)(*this) = (dual_instr_item &)rhs;
75 width_units = rhs.width_units;
76 div_units = rhs.div_units;
77 label_pos = rhs.label_pos;
78 scr_hole = rhs.scr_hole;
87 // Draws a climb ladder in the center of the HUD
90 void HudLadder :: draw( void )
104 POINT centroid = get_centroid();
105 RECT box = get_location();
106 int scr_min = box.top;
107 int half_span = box.right >> 1;
111 roll_value = current_ch2();
112 GLfloat sinRoll = sin( roll_value );
113 GLfloat cosRoll = cos( roll_value );
115 pitch_value = current_ch1() * RAD_TO_DEG;
116 vmin = pitch_value - (double)width_units/2.0;
117 vmax = pitch_value + (double)width_units/2.0;
120 drawOneLine( centroid.x - 5, centroid.y, centroid.x, centroid.y + 5);
121 drawOneLine( centroid.x, centroid.y + 5, centroid.x + 5, centroid.y);
122 drawOneLine( centroid.x + 5, centroid.y, centroid.x, centroid.y - 5);
123 drawOneLine( centroid.x, centroid.y - 5, centroid.x - 5, centroid.y);
125 for( i=(int)vmin; i<=(int)vmax; i++ ) { // Through integer pitch values...
128 marker_y = centroid.y + (int)(((double)(i - pitch_value) * factor) + .5);
130 if( !(i % div_units )) { // At integral multiple of div
131 sprintf( TextLadder, "%d", i );
132 label_length = strlen( TextLadder );
133 if( scr_hole == 0 ) {
135 x_ini = centroid.x - half_span;
137 else { // Make zero point wider on left
138 x_ini = centroid.x - half_span - 10;
141 x_end = centroid.x + half_span;
143 new_x_ini = centroid.x + (int)(
144 (x_ini - centroid.x) * cosRoll -
145 (y_ini - centroid.y) * sinRoll);
146 new_y_ini = centroid.y + (int)( \
147 (x_ini - centroid.x) * sinRoll + \
148 (y_ini - centroid.y) * cosRoll);
149 new_x_end = centroid.x + (int)( \
150 (x_end - centroid.x) * cosRoll - \
151 (y_end - centroid.y) * sinRoll);
152 new_y_end = centroid.y + (int)( \
153 (x_end - centroid.x) * sinRoll + \
154 (y_end - centroid.y) * cosRoll);
156 if( i >= 0 ) { // Above zero draw solid lines
157 drawOneLine( new_x_ini, new_y_ini, new_x_end, new_y_end );
159 else { // Below zero draw dashed lines.
160 glEnable(GL_LINE_STIPPLE);
161 glLineStipple( 1, 0x00FF );
162 drawOneLine( new_x_ini, new_y_ini, new_x_end, new_y_end );
163 glDisable(GL_LINE_STIPPLE);
165 // Calculate the position of the left text and write it.
166 new_x_ini = centroid.x + (int)(
167 (x_ini - 8 * label_length- 4 - centroid.x) * cosRoll -
168 (y_ini - 4 ) * sinRoll);
169 new_y_ini = centroid.y + (int)(
170 (x_ini - 8 * label_length- 4 - centroid.x) * sinRoll +
171 (y_ini - 4 - centroid.y) * cosRoll);
172 strokeString( new_x_ini , new_y_ini ,
173 TextLadder, GLUT_STROKE_ROMAN,
176 // Calculate the position of the right text and write it.
177 new_x_end = centroid.x + (int)( \
178 (x_end + 24 - 8 * label_length - centroid.x) * cosRoll - \
179 (y_end - 4 - centroid.y) * sinRoll);
180 new_y_end = centroid.y + (int)( \
181 (x_end + 24 - 8 * label_length - centroid.x) * sinRoll + \
182 (y_end - 4 - centroid.y) * cosRoll);
183 strokeString( new_x_end, new_y_end,
184 TextLadder, GLUT_STROKE_ROMAN,
187 else { // Draw ladder with space in the middle of the lines
188 // Start by calculating the points and drawing the
191 x_ini = centroid.x - half_span;
194 x_ini = centroid.x - half_span - 10;
197 x_end = centroid.x - half_span + scr_hole/2;
200 new_x_end = centroid.x+ (int)( \
201 (x_end - centroid.x) * cosRoll -\
202 (y_end - centroid.y) * sinRoll);
203 new_y_end = centroid.y+ (int)( \
204 (x_end - centroid.x) * sinRoll +\
205 (y_end - centroid.y) * cosRoll);
206 new_x_ini = centroid.x + (int)( \
207 (x_ini - centroid.x) * cosRoll -\
208 (y_ini - centroid.y) * sinRoll);
209 new_y_ini = centroid.y + (int)( \
210 (x_ini - centroid.x) * sinRoll +\
211 (y_ini - centroid.y) * cosRoll);
215 drawOneLine( new_x_ini, new_y_ini, new_x_end, new_y_end );
218 glEnable(GL_LINE_STIPPLE);
219 glLineStipple( 1, 0x00FF );
220 drawOneLine( new_x_ini, new_y_ini, new_x_end, new_y_end );
221 glDisable(GL_LINE_STIPPLE);
223 // Now calculate the location of the left side label using
224 // the previously calculated start of the left side line.
226 x_ini = x_ini - (label_length + 32 + centroid.x);
235 y_ini = y_ini - ( 4 + centroid.y);
237 new_x_ini = centroid.x + (int)(x_ini * cosRoll - y_ini * sinRoll);
238 new_y_ini = centroid.y + (int)(x_ini * sinRoll + y_ini * cosRoll);
239 strokeString( new_x_ini , new_y_ini ,
240 TextLadder, GLUT_STROKE_MONO_ROMAN,
243 // Now calculate and draw the right side line location
244 x_ini = centroid.x + half_span - scr_hole/2;
247 x_end = centroid.x + half_span;
250 x_end = centroid.x + half_span + 10;
254 new_x_ini = centroid.x + (int)( \
255 (x_ini-centroid.x)*cosRoll -\
256 (y_ini-centroid.y)*sinRoll);
257 new_y_ini = centroid.y + (int)( \
258 (x_ini-centroid.x)*sinRoll +\
259 (y_ini-centroid.y)*cosRoll);
260 new_x_end = centroid.x + (int)( \
261 (x_end-centroid.x)*cosRoll -\
262 (y_end-centroid.y)*sinRoll);
263 new_y_end = centroid.y + (int)( \
264 (x_end-centroid.x)*sinRoll +\
265 (y_end-centroid.y)*cosRoll);
269 drawOneLine( new_x_ini, new_y_ini, new_x_end, new_y_end );
273 glEnable(GL_LINE_STIPPLE);
274 glLineStipple( 1, 0x00FF );
275 drawOneLine( new_x_ini, new_y_ini, new_x_end, new_y_end );
276 glDisable(GL_LINE_STIPPLE);
279 // Calculate the location and draw the right side label
280 // using the end of the line as previously calculated.
281 x_end -= centroid.x + label_length - 24;
285 y_end = marker_y - ( 4 + centroid.y);
286 new_x_end = centroid.x + (int)( (GLfloat)x_end * cosRoll -
287 (GLfloat)y_end * sinRoll);
288 new_y_end = centroid.y + (int)( (GLfloat)x_end * sinRoll +
289 (GLfloat)y_end * cosRoll);
290 strokeString( new_x_end, new_y_end,
291 TextLadder, GLUT_STROKE_MONO_ROMAN,