10 #include <Aircraft/aircraft.hxx>
11 #include <Debug/fg_debug.h>
12 #include <Include/fg_constants.h>
13 #include <Math/fg_random.h>
14 #include <Math/mat3.h>
15 #include <Math/polar3d.hxx>
16 #include <Scenery/scenery.hxx>
17 #include <Time/fg_timer.hxx>
21 //====================== Top of HudLadder Class =======================
35 dual_instr_item( x, y, width, height,
40 width_units ( span_units ),
41 div_units ( major_div < 0? -major_div: major_div ),
42 minor_div ( minor_div ),
43 label_pos ( lbl_pos ),
44 scr_hole ( screen_hole ),
45 vmax ( span_units/2 ),
51 factor = (double)get_span() / (double) width_units;
60 HudLadder( const HudLadder & image ) :
61 dual_instr_item( (dual_instr_item &) image),
62 width_units ( image.width_units ),
63 div_units ( image.div_units ),
64 label_pos ( image.label_pos ),
65 scr_hole ( image.scr_hole ),
68 factor ( image.factor )
71 HudLadder & HudLadder ::
72 operator = ( const HudLadder & rhs )
74 if( !(this == &rhs)) {
75 (dual_instr_item &)(*this) = (dual_instr_item &)rhs;
76 width_units = rhs.width_units;
77 div_units = rhs.div_units;
78 label_pos = rhs.label_pos;
79 scr_hole = rhs.scr_hole;
88 // Draws a climb ladder in the center of the HUD
91 void HudLadder :: draw( void )
105 POINT centroid = get_centroid();
106 RECT box = get_location();
107 int scr_min = box.top;
108 int half_span = box.right >> 1;
112 roll_value = current_ch2();
113 GLfloat sinRoll = sin( roll_value );
114 GLfloat cosRoll = cos( roll_value );
116 pitch_value = current_ch1() * RAD_TO_DEG;
117 vmin = pitch_value - (double)width_units/2.0;
118 vmax = pitch_value + (double)width_units/2.0;
121 drawOneLine( centroid.x - 5, centroid.y, centroid.x, centroid.y + 5);
122 drawOneLine( centroid.x, centroid.y + 5, centroid.x + 5, centroid.y);
123 drawOneLine( centroid.x + 5, centroid.y, centroid.x, centroid.y - 5);
124 drawOneLine( centroid.x, centroid.y - 5, centroid.x - 5, centroid.y);
126 for( i=(int)vmin; i<=(int)vmax; i++ ) { // Through integer pitch values...
129 marker_y = centroid.y + (int)(((double)(i - pitch_value) * factor) + .5);
131 if( !(i % div_units )) { // At integral multiple of div
132 sprintf( TextLadder, "%d", i );
133 label_length = strlen( TextLadder );
134 if( scr_hole == 0 ) {
136 x_ini = centroid.x - half_span;
138 else { // Make zero point wider on left
139 x_ini = centroid.x - half_span - 10;
142 x_end = centroid.x + half_span;
144 new_x_ini = centroid.x + (int)(
145 (x_ini - centroid.x) * cosRoll -
146 (y_ini - centroid.y) * sinRoll);
147 new_y_ini = centroid.y + (int)( \
148 (x_ini - centroid.x) * sinRoll + \
149 (y_ini - centroid.y) * cosRoll);
150 new_x_end = centroid.x + (int)( \
151 (x_end - centroid.x) * cosRoll - \
152 (y_end - centroid.y) * sinRoll);
153 new_y_end = centroid.y + (int)( \
154 (x_end - centroid.x) * sinRoll + \
155 (y_end - centroid.y) * cosRoll);
157 if( i >= 0 ) { // Above zero draw solid lines
158 drawOneLine( new_x_ini, new_y_ini, new_x_end, new_y_end );
160 else { // Below zero draw dashed lines.
161 glEnable(GL_LINE_STIPPLE);
162 glLineStipple( 1, 0x00FF );
163 drawOneLine( new_x_ini, new_y_ini, new_x_end, new_y_end );
164 glDisable(GL_LINE_STIPPLE);
166 // Calculate the position of the left text and write it.
167 new_x_ini = centroid.x + (int)(
168 (x_ini - 8 * label_length- 4 - centroid.x) * cosRoll -
169 (y_ini - 4 ) * sinRoll);
170 new_y_ini = centroid.y + (int)(
171 (x_ini - 8 * label_length- 4 - centroid.x) * sinRoll +
172 (y_ini - 4 - centroid.y) * cosRoll);
173 strokeString( new_x_ini , new_y_ini ,
174 TextLadder, GLUT_STROKE_ROMAN,
177 // Calculate the position of the right text and write it.
178 new_x_end = centroid.x + (int)( \
179 (x_end + 24 - 8 * label_length - centroid.x) * cosRoll - \
180 (y_end - 4 - centroid.y) * sinRoll);
181 new_y_end = centroid.y + (int)( \
182 (x_end + 24 - 8 * label_length - centroid.x) * sinRoll + \
183 (y_end - 4 - centroid.y) * cosRoll);
184 strokeString( new_x_end, new_y_end,
185 TextLadder, GLUT_STROKE_ROMAN,
188 else { // Draw ladder with space in the middle of the lines
189 // Start by calculating the points and drawing the
192 x_ini = centroid.x - half_span;
195 x_ini = centroid.x - half_span - 10;
198 x_end = centroid.x - half_span + scr_hole/2;
201 new_x_end = centroid.x+ (int)( \
202 (x_end - centroid.x) * cosRoll -\
203 (y_end - centroid.y) * sinRoll);
204 new_y_end = centroid.y+ (int)( \
205 (x_end - centroid.x) * sinRoll +\
206 (y_end - centroid.y) * cosRoll);
207 new_x_ini = centroid.x + (int)( \
208 (x_ini - centroid.x) * cosRoll -\
209 (y_ini - centroid.y) * sinRoll);
210 new_y_ini = centroid.y + (int)( \
211 (x_ini - centroid.x) * sinRoll +\
212 (y_ini - centroid.y) * cosRoll);
216 drawOneLine( new_x_ini, new_y_ini, new_x_end, new_y_end );
219 glEnable(GL_LINE_STIPPLE);
220 glLineStipple( 1, 0x00FF );
221 drawOneLine( new_x_ini, new_y_ini, new_x_end, new_y_end );
222 glDisable(GL_LINE_STIPPLE);
224 // Now calculate the location of the left side label using
225 // the previously calculated start of the left side line.
227 x_ini = x_ini - (label_length + 32 + centroid.x);
236 y_ini = y_ini - ( 4 + centroid.y);
238 new_x_ini = centroid.x + (int)(x_ini * cosRoll - y_ini * sinRoll);
239 new_y_ini = centroid.y + (int)(x_ini * sinRoll + y_ini * cosRoll);
240 strokeString( new_x_ini , new_y_ini ,
241 TextLadder, GLUT_STROKE_MONO_ROMAN,
244 // Now calculate and draw the right side line location
245 x_ini = centroid.x + half_span - scr_hole/2;
248 x_end = centroid.x + half_span;
251 x_end = centroid.x + half_span + 10;
255 new_x_ini = centroid.x + (int)( \
256 (x_ini-centroid.x)*cosRoll -\
257 (y_ini-centroid.y)*sinRoll);
258 new_y_ini = centroid.y + (int)( \
259 (x_ini-centroid.x)*sinRoll +\
260 (y_ini-centroid.y)*cosRoll);
261 new_x_end = centroid.x + (int)( \
262 (x_end-centroid.x)*cosRoll -\
263 (y_end-centroid.y)*sinRoll);
264 new_y_end = centroid.y + (int)( \
265 (x_end-centroid.x)*sinRoll +\
266 (y_end-centroid.y)*cosRoll);
270 drawOneLine( new_x_ini, new_y_ini, new_x_end, new_y_end );
274 glEnable(GL_LINE_STIPPLE);
275 glLineStipple( 1, 0x00FF );
276 drawOneLine( new_x_ini, new_y_ini, new_x_end, new_y_end );
277 glDisable(GL_LINE_STIPPLE);
280 // Calculate the location and draw the right side label
281 // using the end of the line as previously calculated.
282 x_end -= centroid.x + label_length - 24;
286 y_end = marker_y - ( 4 + centroid.y);
287 new_x_end = centroid.x + (int)( (GLfloat)x_end * cosRoll -
288 (GLfloat)y_end * sinRoll);
289 new_y_end = centroid.y + (int)( (GLfloat)x_end * sinRoll +
290 (GLfloat)y_end * cosRoll);
291 strokeString( new_x_end, new_y_end,
292 TextLadder, GLUT_STROKE_MONO_ROMAN,