10 #include <Aircraft/aircraft.h>
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>
18 #include <Weather/weather.h>
22 //====================== Top of HudLadder Class =======================
36 dual_instr_item( x, y, width, height,
41 width_units ( span_units ),
42 div_units ( major_div < 0? -major_div: major_div ),
43 minor_div ( minor_div ),
44 label_pos ( lbl_pos ),
45 scr_hole ( screen_hole ),
46 vmax ( span_units/2 ),
52 factor = (double)get_span() / (double) width_units;
61 HudLadder( const HudLadder & image ) :
62 dual_instr_item( (dual_instr_item &) image),
63 width_units ( image.width_units ),
64 div_units ( image.div_units ),
65 label_pos ( image.label_pos ),
66 scr_hole ( image.scr_hole ),
69 factor ( image.factor )
72 HudLadder & HudLadder ::
73 operator = ( const HudLadder & rhs )
75 if( !(this == &rhs)) {
76 (dual_instr_item &)(*this) = (dual_instr_item &)rhs;
77 width_units = rhs.width_units;
78 div_units = rhs.div_units;
79 label_pos = rhs.label_pos;
80 scr_hole = rhs.scr_hole;
89 // Draws a climb ladder in the center of the HUD
92 void HudLadder :: draw( void )
106 POINT centroid = get_centroid();
107 RECT box = get_location();
108 int scr_min = box.top;
109 int half_span = box.right >> 1;
113 roll_value = current_ch2();
114 GLfloat sinRoll = sin( roll_value );
115 GLfloat cosRoll = cos( roll_value );
117 pitch_value = current_ch1() * RAD_TO_DEG;
118 vmin = pitch_value - (double)width_units/2.0;
119 vmax = pitch_value + (double)width_units/2.0;
122 drawOneLine( centroid.x - 5, centroid.y, centroid.x, centroid.y + 5);
123 drawOneLine( centroid.x, centroid.y + 5, centroid.x + 5, centroid.y);
124 drawOneLine( centroid.x + 5, centroid.y, centroid.x, centroid.y - 5);
125 drawOneLine( centroid.x, centroid.y - 5, centroid.x - 5, centroid.y);
127 for( i=(int)vmin; i<=(int)vmax; i++ ) { // Through integer pitch values...
130 marker_y = centroid.y + (int)(((double)(i - pitch_value) * factor) + .5);
132 if( !(i % div_units )) { // At integral multiple of div
133 sprintf( TextLadder, "%d", i );
134 label_length = strlen( TextLadder );
135 if( scr_hole == 0 ) {
137 x_ini = centroid.x - half_span;
139 else { // Make zero point wider on left
140 x_ini = centroid.x - half_span - 10;
143 x_end = centroid.x + half_span;
145 new_x_ini = centroid.x + (int)(
146 (x_ini - centroid.x) * cosRoll -
147 (y_ini - centroid.y) * sinRoll);
148 new_y_ini = centroid.y + (int)( \
149 (x_ini - centroid.x) * sinRoll + \
150 (y_ini - centroid.y) * cosRoll);
151 new_x_end = centroid.x + (int)( \
152 (x_end - centroid.x) * cosRoll - \
153 (y_end - centroid.y) * sinRoll);
154 new_y_end = centroid.y + (int)( \
155 (x_end - centroid.x) * sinRoll + \
156 (y_end - centroid.y) * cosRoll);
158 if( i >= 0 ) { // Above zero draw solid lines
159 drawOneLine( new_x_ini, new_y_ini, new_x_end, new_y_end );
161 else { // Below zero draw dashed lines.
162 glEnable(GL_LINE_STIPPLE);
163 glLineStipple( 1, 0x00FF );
164 drawOneLine( new_x_ini, new_y_ini, new_x_end, new_y_end );
165 glDisable(GL_LINE_STIPPLE);
167 // Calculate the position of the left text and write it.
168 new_x_ini = centroid.x + (int)(
169 (x_ini - 8 * label_length- 4 - centroid.x) * cosRoll -
170 (y_ini - 4 ) * sinRoll);
171 new_y_ini = centroid.y + (int)(
172 (x_ini - 8 * label_length- 4 - centroid.x) * sinRoll +
173 (y_ini - 4 - centroid.y) * cosRoll);
174 strokeString( new_x_ini , new_y_ini ,
175 TextLadder, GLUT_STROKE_ROMAN,
178 // Calculate the position of the right text and write it.
179 new_x_end = centroid.x + (int)( \
180 (x_end + 24 - 8 * label_length - centroid.x) * cosRoll - \
181 (y_end - 4 - centroid.y) * sinRoll);
182 new_y_end = centroid.y + (int)( \
183 (x_end + 24 - 8 * label_length - centroid.x) * sinRoll + \
184 (y_end - 4 - centroid.y) * cosRoll);
185 strokeString( new_x_end, new_y_end,
186 TextLadder, GLUT_STROKE_ROMAN,
189 else { // Draw ladder with space in the middle of the lines
190 // Start by calculating the points and drawing the
193 x_ini = centroid.x - half_span;
196 x_ini = centroid.x - half_span - 10;
199 x_end = centroid.x - half_span + scr_hole/2;
202 new_x_end = centroid.x+ (int)( \
203 (x_end - centroid.x) * cosRoll -\
204 (y_end - centroid.y) * sinRoll);
205 new_y_end = centroid.y+ (int)( \
206 (x_end - centroid.x) * sinRoll +\
207 (y_end - centroid.y) * cosRoll);
208 new_x_ini = centroid.x + (int)( \
209 (x_ini - centroid.x) * cosRoll -\
210 (y_ini - centroid.y) * sinRoll);
211 new_y_ini = centroid.y + (int)( \
212 (x_ini - centroid.x) * sinRoll +\
213 (y_ini - centroid.y) * cosRoll);
217 drawOneLine( new_x_ini, new_y_ini, new_x_end, new_y_end );
220 glEnable(GL_LINE_STIPPLE);
221 glLineStipple( 1, 0x00FF );
222 drawOneLine( new_x_ini, new_y_ini, new_x_end, new_y_end );
223 glDisable(GL_LINE_STIPPLE);
225 // Now calculate the location of the left side label using
226 // the previously calculated start of the left side line.
228 x_ini = x_ini - (label_length + 32 + centroid.x);
237 y_ini = y_ini - ( 4 + centroid.y);
239 new_x_ini = centroid.x + (int)(x_ini * cosRoll - y_ini * sinRoll);
240 new_y_ini = centroid.y + (int)(x_ini * sinRoll + y_ini * cosRoll);
241 strokeString( new_x_ini , new_y_ini ,
242 TextLadder, GLUT_STROKE_MONO_ROMAN,
245 // Now calculate and draw the right side line location
246 x_ini = centroid.x + half_span - scr_hole/2;
249 x_end = centroid.x + half_span;
252 x_end = centroid.x + half_span + 10;
256 new_x_ini = centroid.x + (int)( \
257 (x_ini-centroid.x)*cosRoll -\
258 (y_ini-centroid.y)*sinRoll);
259 new_y_ini = centroid.y + (int)( \
260 (x_ini-centroid.x)*sinRoll +\
261 (y_ini-centroid.y)*cosRoll);
262 new_x_end = centroid.x + (int)( \
263 (x_end-centroid.x)*cosRoll -\
264 (y_end-centroid.y)*sinRoll);
265 new_y_end = centroid.y + (int)( \
266 (x_end-centroid.x)*sinRoll +\
267 (y_end-centroid.y)*cosRoll);
271 drawOneLine( new_x_ini, new_y_ini, new_x_end, new_y_end );
275 glEnable(GL_LINE_STIPPLE);
276 glLineStipple( 1, 0x00FF );
277 drawOneLine( new_x_ini, new_y_ini, new_x_end, new_y_end );
278 glDisable(GL_LINE_STIPPLE);
281 // Calculate the location and draw the right side label
282 // using the end of the line as previously calculated.
283 x_end -= centroid.x + label_length - 24;
287 y_end = marker_y - ( 4 + centroid.y);
288 new_x_end = centroid.x + (int)( (GLfloat)x_end * cosRoll -
289 (GLfloat)y_end * sinRoll);
290 new_y_end = centroid.y + (int)( (GLfloat)x_end * sinRoll +
291 (GLfloat)y_end * cosRoll);
292 strokeString( new_x_end, new_y_end,
293 TextLadder, GLUT_STROKE_MONO_ROMAN,