7 //====================== Top of HudLadder Class =======================
8 HudLadder :: HudLadder( int x,
21 dual_instr_item( x, y, width, height,
26 width_units ( (int)(span_units) ),
27 div_units ( (int)(major_div < 0? -major_div: major_div) ),
28 minor_div ( (int)(minor_div) ),
29 label_pos ( lbl_pos ),
30 scr_hole ( screen_hole ),
31 vmax ( span_units/2 ),
37 // $$$ begin -added VS Renganthan 16 Oct 2k
39 factor = 480.0 / 33.75;
41 // $$$ begin -added VS Renganthan 16 Oct 2k
42 factor = (float)get_span() / (float) width_units;
47 HudLadder :: ~HudLadder()
52 HudLadder( const HudLadder & image ) :
53 dual_instr_item( (dual_instr_item &) image),
54 width_units ( image.width_units ),
55 div_units ( image.div_units ),
56 label_pos ( image.label_pos ),
57 scr_hole ( image.scr_hole ),
60 factor ( image.factor )
63 HudLadder & HudLadder :: operator = ( const HudLadder & rhs )
65 if( !(this == &rhs)) {
66 (dual_instr_item &)(*this) = (dual_instr_item &)rhs;
67 width_units = rhs.width_units;
68 div_units = rhs.div_units;
69 label_pos = rhs.label_pos;
70 scr_hole = rhs.scr_hole;
79 // Draws a climb ladder in the center of the HUD
81 // $$$ begin - added VS Renganathan, 13 Oct 2K
83 void HudLadder :: draw( void )
89 float cosine, sine,xvvr,yvvr,Vxx,Vyy,Vzz,up_vel,ground_vel,actslope;
90 float Axx,Ayy,Azz,total_vel,pot_slope,t1,t2,psi,alpha,pla;
91 float vel_x,vel_y,drift;
94 GLdouble eqn_top[4] = {0.0,-1.0,0.0,0.0};
95 GLdouble eqn_left[4] = {-1.0,0.0,0.0,100.0};
96 GLdouble eqn_right[4] = {1.0,0.0,0.0,100.0};
98 POINT centroid = get_centroid();
99 RECT box = get_location();
101 float half_span = box.right / 2.0;
102 float roll_value = current_ch2();
104 pla = get_throttleval();
106 int lgear,wown,wowm,iclaw,ihook;
113 float pitch_value = current_ch1() * RAD_TO_DEG;
114 vmin = pitch_value - (float)width_units;
115 vmax = pitch_value + (float)width_units; //$$$
118 glTranslatef( centroid.x, centroid.y, 0);
120 //*********************************************************
121 //waypoint marker computation
122 float fromwp_lat,towp_lat,fromwp_lon,towp_lon,dist,delx,dely,hyp,theta,brg;
124 fromwp_lon = get_longitude()*DEG_TO_RAD;
125 fromwp_lat = get_latitude()*DEG_TO_RAD;
126 towp_lon = get_aux5()*DEG_TO_RAD;
127 towp_lat = get_aux6()*DEG_TO_RAD;
129 dist = acos(sin(fromwp_lat)*sin(towp_lat)+cos(fromwp_lat)*cos(towp_lat)*cos(fabs(fromwp_lon-towp_lon)));
130 delx= towp_lat - fromwp_lat;
131 dely = towp_lon - fromwp_lon;
132 hyp = sqrt(pow(delx,2)+pow(dely,2));
134 theta = asin(dely/hyp);
138 brg = theta*RAD_TO_DEG;
139 if (brg > 360.0) brg = 0.0;
140 if (delx < 0) brg = 180 - brg;
142 // {Brg = asin(cos(towp_lat)*sin(fabs(fromwp_lon-towp_lon))/ sin(dist));
143 // Brg = Brg * RAD_TO_DEG; }
144 dist = dist*RAD_TO_DEG * 60.0*1852.0; //rad->deg->nm->m
145 //*********************************************************
146 // Draw the FRL spot and line
147 #define FRL_DIAMOND_SIZE 2.0
148 glBegin(GL_LINE_LOOP);
149 glVertex2f( -FRL_DIAMOND_SIZE, 0.0);
150 glVertex2f(0.0, FRL_DIAMOND_SIZE);
151 glVertex2f( FRL_DIAMOND_SIZE, 0.0);
152 glVertex2f(0.0, -FRL_DIAMOND_SIZE);
154 glBegin(GL_LINE_STRIP);
155 glVertex2f(0, FRL_DIAMOND_SIZE);
158 #undef FRL_DIAMOND_SIZE
160 //velocity vector reticle - computations
169 if (psi > 180.0) psi = psi - 360;
171 total_vel = sqrt(Vxx*Vxx + Vyy*Vyy + Vzz*Vzz);
172 ground_vel = sqrt(Vxx*Vxx + Vyy*Vyy);
175 if (ground_vel < 2.0) {
176 if (fabs(up_vel) < 2.0) {
179 actslope = (up_vel/fabs(up_vel))*90.0;
182 actslope = atan(up_vel/ground_vel)*RAD_TO_DEG;
185 xvvr = (((atan2(Vyy,Vxx)*RAD_TO_DEG)-psi)*(640.0/45.0));
186 drift = ((atan2(Vyy,Vxx)*RAD_TO_DEG)-psi);
187 yvvr = ((actslope - pitch_value)*factor);
188 vel_y = ((actslope -pitch_value) * cos(roll_value) + drift*sin(roll_value))*factor;
189 vel_x = (-(actslope -pitch_value)*sin(roll_value) + drift*cos(roll_value))*(640/45.0);
190 // printf("%f %f %f %f\n",vel_x,vel_y,drift,psi);
193 glBegin(GL_LINE_STRIP);
194 glVertex2f((xvvr*25/120)-6, -4);
195 glVertex2f(xvvr*25/120, 8);
196 glVertex2f((xvvr*25/120)+6, -4);
200 glClipPlane(GL_CLIP_PLANE0,eqn_top);
201 glEnable(GL_CLIP_PLANE0);
202 glClipPlane(GL_CLIP_PLANE1,eqn_left);
203 glEnable(GL_CLIP_PLANE1);
204 glClipPlane(GL_CLIP_PLANE2,eqn_right);
205 glEnable(GL_CLIP_PLANE2);
207 // alpha bracket - reqd only for landing (tied to hook)
209 glBegin(GL_LINE_STRIP);
210 glVertex2f(vel_x-20 , vel_y-(16-alpha)*factor);
211 glVertex2f(vel_x-17, vel_y-(16-alpha)*factor);
212 glVertex2f(vel_x-17, vel_y-(14-alpha)*factor);
213 glVertex2f(vel_x-20, vel_y-(14-alpha)*factor);
215 glBegin(GL_LINE_STRIP);
216 glVertex2f(vel_x+20 , vel_y-(16-alpha)*factor);
217 glVertex2f(vel_x+17, vel_y-(16-alpha)*factor);
218 glVertex2f(vel_x+17, vel_y-(14-alpha)*factor);
219 glVertex2f(vel_x+20, vel_y-(14-alpha)*factor);
223 //printf("xvr=%f,yvr=%f,Vx=%f,Vy=%f,Vz=%f\n",xvvr,yvvr,Vx,Vy,Vz);
224 //printf("Ax=%f,Ay=%f,Az=%f\n",Ax,Ay,Az);
226 //energy markers - compute potential slope
227 if (total_vel < 5.0) {
231 t1 = up_vel/total_vel;
232 t2 = asin((Vxx*Axx + Vyy*Ayy + Vzz*Azz)/(9.81*total_vel));
234 pot_slope = ((t2/3)*RAD_TO_DEG)*factor + vel_y;
237 glBegin(GL_LINE_STRIP);
238 glVertex2f(vel_x-20, pot_slope-5);
239 glVertex2f(vel_x-15, pot_slope);
240 glVertex2f(vel_x-20, pot_slope+5);
242 glBegin(GL_LINE_STRIP);
243 glVertex2f(vel_x+20, pot_slope-5);
244 glVertex2f(vel_x+15, pot_slope);
245 glVertex2f(vel_x+20, pot_slope+5);
247 if (pla > (105.0/131.0)) {
248 glBegin(GL_LINE_STRIP);
249 glVertex2f(vel_x-24, pot_slope-5);
250 glVertex2f(vel_x-19, pot_slope);
251 glVertex2f(vel_x-24, pot_slope+5);
253 glBegin(GL_LINE_STRIP);
254 glVertex2f(vel_x+24, pot_slope-5);
255 glVertex2f(vel_x+19, pot_slope);
256 glVertex2f(vel_x+24, pot_slope+5);
260 // ramp reticle - for ski jump takeoff only
262 glBegin(GL_LINE_STRIP);
263 glVertex2f(-15, -134);
264 glVertex2f(15, -134);
266 glBegin(GL_LINE_STRIP);
267 glVertex2f(-6, -134);
268 glVertex2f(-6, t2*RAD_TO_DEG*4.0 - 134);
269 glVertex2f(+6, t2*RAD_TO_DEG*4.0 - 134);
272 glBegin(GL_LINE_LOOP);
273 glVertex2f(-6, actslope*4.0 - 134);
274 glVertex2f(0, actslope*4.0 -134 +3);
275 glVertex2f(6, actslope*4.0 - 134);
276 glVertex2f(0, actslope*4.0 -134 -3);
280 // Draw the locked velocity vector.
281 glBegin(GL_LINE_LOOP);
282 glVertex2f( -3.0, 0.0+vel_y);
283 glVertex2f(0.0, 6.0+vel_y);
284 glVertex2f( 3.0, 0.0+vel_y);
285 glVertex2f(0.0, -6.0+vel_y);
288 // draw velocity vector
289 glBegin(GL_LINE_LOOP); // Use polygon to approximate a circle
290 for(count=0; count<50; count++) {
291 cosine = 6 * cos(count * 2 * M_PI/50.0);
292 sine = 6 * sin(count * 2 * M_PI/50.0);
293 glVertex2f(cosine+vel_x, sine+vel_y);
297 //velocity vector reticle orientation lines
298 glBegin(GL_LINE_STRIP);
299 glVertex2f(vel_x-12, vel_y);
300 glVertex2f(vel_x-6, vel_y);
302 glBegin(GL_LINE_STRIP);
303 glVertex2f(vel_x+12, vel_y);
304 glVertex2f(vel_x+6, vel_y);
306 glBegin(GL_LINE_STRIP);
307 glVertex2f(vel_x, vel_y+12);
308 glVertex2f(vel_x, vel_y+6);
312 // undercarriage status
313 glBegin(GL_LINE_STRIP);
314 glVertex2f(vel_x+8, vel_y);
315 glVertex2f(vel_x+8, vel_y-4);
317 glBegin(GL_LINE_STRIP);
318 glVertex2f(vel_x-8, vel_y);
319 glVertex2f(vel_x-8, vel_y-4);
321 glBegin(GL_LINE_STRIP);
322 glVertex2f(vel_x, vel_y-6);
323 glVertex2f(vel_x, vel_y-10);
328 // arrestor hook status
329 glBegin(GL_LINE_STRIP);
330 glVertex2f(vel_x-4, vel_y-8);
331 glVertex2f(vel_x, vel_y-10);
332 glVertex2f(vel_x+4, vel_y-8);
336 // FRL marker not rotated - this line shifted below
337 glTranslatef( vel_x, vel_y, 0);
338 glRotatef(roll_value * RAD_TO_DEG, 0.0, 0.0, 1.0);
349 float text_offset = 4.0f ;
350 float zero_offset = 50.0f ;
352 fntFont *font = HUDtext->getFont();
353 float pointsize = HUDtext->getPointSize();
354 float italic = HUDtext->getSlant();
356 TextList.setFont( HUDtext );
359 StippleLineList.erase();
361 int last = FloatToInt(vmax)+1;
362 int i = FloatToInt(vmin);
365 for( ; i<last ; i++ ) {
367 y = (((float)(i - pitch_value) * factor) + .5f);
368 if( !(i % div_units )) { // At integral multiple of div
370 sprintf( TextLadder, "%d", i );
371 font->getBBox ( TextLadder, pointsize, italic,
372 &left, &right, &bot, &top ) ;
373 label_length = right - left;
374 label_length += text_offset;
375 label_height = (top - bot)/2.0f;
381 // Make zero point wider on left
383 x_ini -= zero_offset;
384 // Zero or above draw solid lines
385 Line(x_ini, y, x_end, y);
387 // Below zero draw dashed lines.
388 StippleLine(x_ini, y, x_end, y);
391 // Calculate the position of the left text and write it.
392 Text( x_ini-label_length, y-label_height, TextLadder );
393 Text( x_end+text_offset, y-label_height, TextLadder );
397 else // if(scr_hole )
398 { // Draw ladder with space in the middle of the lines
399 float hole = (float)((scr_hole)/2.0f);
400 for( ; i<last ; i++ ) {
402 // y = (((float)(i - pitch_value) * factor) + .5);
403 y = (((float)(i - actslope) * factor) + .5);
405 if( !(i % div_units )) { // At integral multiple of div
407 sprintf( TextLadder, "%d", i );
408 font->getBBox ( TextLadder, pointsize, italic,
409 &left, &right, &bot, &top ) ;
410 label_length = right - left;
411 label_length += text_offset;
412 label_height = (top - bot)/2.0f;
413 // printf("l %f r %f b %f t %f\n",left, right, bot, top );
415 // Start by calculating the points and drawing the
418 x_end = -half_span + hole;
421 // Make zero point wider on left
423 x_ini -= zero_offset;
425 // Zero or above draw solid lines
426 Line(x_end, y-5.0, x_end, y);
429 Line(x_ini, y, x_end, y);
432 // Below zero draw dashed lines.
433 Line(x_end, y+5.0, x_end, y);
434 StippleLine(x_ini, y, x_end, y);
437 // Now calculate the location of the left side label using
438 Text( x_ini-label_length, y-label_height, TextLadder );
440 // Now calculate and draw the right side line location
441 x_ini = half_span - hole;
446 x_end += zero_offset;
448 Line(x_ini, y-5.0, x_ini, y);
450 // Zero or above draw solid lines
451 Line(x_ini, y, x_end, y);
453 // Below zero draw dashed lines.
454 Line(x_ini, y+5.0, x_ini, y);
455 StippleLine(x_ini, y, x_end, y);
458 // Calculate the location and draw the right side label
459 Text( x_end+text_offset, y-label_height, TextLadder );
463 // draw appraoch glide slope marker - for landing only (tied to hook)
465 Line(-half_span+15, (-4-actslope)*factor, -half_span + hole, (-4-actslope)*factor);
466 Line(half_span-15, (-4-actslope)*factor, half_span - hole, (-4-actslope)*factor);
477 glEnable(GL_LINE_STIPPLE);
478 glLineStipple( 1, 0x00FF );
479 StippleLineList.draw( );
480 glDisable(GL_LINE_STIPPLE);
482 glDisable(GL_CLIP_PLANE0);
483 glDisable(GL_CLIP_PLANE1);
484 glDisable(GL_CLIP_PLANE2);
485 // glDisable(GL_SCISSOR_TEST);
487 //*************************************************************
489 if (fabs(brg-psi) > 10.0) {
491 glTranslatef( centroid.x, centroid.y, 0);
492 glTranslatef( vel_x, vel_y, 0);
493 glRotatef(brg - psi,0.0,0.0,-1.0);
494 glBegin(GL_LINE_LOOP);
495 glVertex2f(-2.5,20.0);
496 glVertex2f(-2.5,30.0);
497 glVertex2f(-5.0,30.0);
498 glVertex2f(0.0,35.0);
499 glVertex2f(5.0,30.0);
500 glVertex2f(2.5,30.0);
501 glVertex2f(2.5,20.0);
505 // waypoint marker on heading scale
506 if (fabs(brg-psi) < 12.0) {
507 glBegin(GL_LINE_LOOP);
508 glVertex2f(((brg-psi)*60/25)+320,240.0);
509 glVertex2f(((brg-psi)*60/25)+326,240.0-4);
510 glVertex2f(((brg-psi)*60/25)+323,240.0-4);
511 glVertex2f(((brg-psi)*60/25)+323,240.0-8);
512 glVertex2f(((brg-psi)*60/25)+317,240.0-8);
513 glVertex2f(((brg-psi)*60/25)+317,240.0-4);
514 glVertex2f(((brg-psi)*60/25)+314,240.0-4);
517 //*************************************************************
521 // $$$ end - added VS Renganathan, 13 Oct 2K
524 void HudLadder :: draw( void )
526 POINT centroid = get_centroid();
528 float roll_value = current_ch2();
531 glTranslatef( centroid.x, centroid.y, 0);
532 // Alex's panel patch
533 // glScalef( globals->get_options()->get_fov()/55.0, 1.0, 1.0 );
534 glRotatef(roll_value * RAD_TO_DEG, 0.0, 0.0, 1.0);
536 // Draw the target spot.
537 #define CENTER_DIAMOND_SIZE 6.0f
539 glBegin(GL_LINE_LOOP);
540 glVertex2f( CENTER_DIAMOND_SIZE, 0.0);
541 glVertex2f( 0.0, CENTER_DIAMOND_SIZE);
542 glVertex2f( -CENTER_DIAMOND_SIZE, 0.0);
543 glVertex2f( 0.0, -CENTER_DIAMOND_SIZE);
546 if( minimal || ! div_units ) {
555 float pitch_value = current_ch1() * RAD_TO_DEG;
556 vmin = pitch_value - (float)width_units * 0.5f;
557 vmax = pitch_value + (float)width_units * 0.5f;
559 RECT box = get_location();
561 float half_span = box.right * 0.5f ;
570 float text_offset = 4.0f ;
571 float zero_offset = 10.0f ;
573 fntFont *font = HUDtext->getFont();
574 float pointsize = HUDtext->getPointSize();
575 float italic = HUDtext->getSlant();
577 TextList.setFont( HUDtext );
580 StippleLineList.erase();
582 int last = FloatToInt(vmax)+1;
583 int i = FloatToInt(vmin);
587 for( ; i<last ; i++ ) {
589 y = (((float)(i - pitch_value) * factor) + .5f);
590 if( !(i % div_units )) { // At integral multiple of div
592 sprintf( TextLadder, "%d", i );
593 font->getBBox ( TextLadder, pointsize, italic,
594 &left, &right, &bot, &top ) ;
596 label_length = right - left;
597 label_length += text_offset;
598 label_height = (top - bot) * 0.5f;
603 // Make zero point wider on left
605 x_ini -= zero_offset;
606 // Zero or above draw solid lines
607 Line(x_ini, y, x_end, y);
609 // Below zero draw dashed lines.
610 StippleLine(x_ini, y, x_end, y);
613 // Calculate the position of the left text and write it.
614 Text( x_ini-label_length, y-label_height, TextLadder );
615 Text( x_end+text_offset, y-label_height, TextLadder );
618 } else { // scr_hole != 0
619 // Draw ladder with space in the middle of the lines
622 float hole = (float)((scr_hole)*0.5f);
624 x_end = -half_span + hole;
625 x_ini2 = half_span - hole;
627 for( ; i<last ; i++ ) {
629 y = (((float)(i - pitch_value) * factor) + .5);
630 if( !(i % div_units )) { // At integral multiple of div
632 sprintf( TextLadder, "%d", i );
633 font->getBBox ( TextLadder, pointsize, italic,
634 &left, &right, &bot, &top ) ;
635 label_length = right - left;
636 label_length += text_offset;
637 label_height = (top - bot) * 0.5f;
639 // Start by calculating the points and drawing the
645 // Make zero point wider on left
647 x_ini -= zero_offset;
648 x_end2 += zero_offset;
650 // Zero or above draw solid lines
651 Line(x_ini, y, x_end, y);
652 Line(x_ini2, y, x_end2, y);
654 // Below zero draw dashed lines.
655 StippleLine(x_ini, y, x_end, y);
656 StippleLine(x_ini2, y, x_end2, y);
658 // Calculate the location of the left side label using
659 Text( x_ini-label_length, y-label_height, TextLadder );
660 // Calculate the location and draw the right side label
661 Text( x_end2+text_offset, y-label_height, TextLadder );
669 glEnable(GL_LINE_STIPPLE);
671 glLineStipple( 1, fgPanelVisible() ? 0x0F0F : 0x00FF );
673 glLineStipple( 1, 0x00FF );
676 StippleLineList.draw( );
677 glDisable(GL_LINE_STIPPLE);
679 // } // if(div_units)
683 #endif // DEFAULT_HUD