]> git.mxchange.org Git - flightgear.git/blob - src/Cockpit/hud_tbi.cxx
FG_ to SG_ namespace changes.
[flightgear.git] / src / Cockpit / hud_tbi.cxx
1
2 #include "hud.hxx"
3
4
5 //============ Top of fgTBI_instr class member definitions ==============
6
7 fgTBI_instr ::
8 fgTBI_instr( int              x,
9              int              y,
10              UINT             width,
11              UINT             height,
12              FLTFNPTR  chn1_source,
13              FLTFNPTR  chn2_source,
14              float    maxBankAngle,
15              float    maxSlipAngle,
16              UINT      gap_width,
17              bool      working ) :
18                dual_instr_item( x, y, width, height,
19                                 chn1_source,
20                                 chn2_source,
21                                 working,
22                                 HUDS_TOP),
23                BankLimit      ((int)(maxBankAngle)),
24                SlewLimit      ((int)(maxSlipAngle)),
25                scr_hole       (gap_width   )
26 {
27 }
28
29 fgTBI_instr :: ~fgTBI_instr() {}
30
31 fgTBI_instr :: fgTBI_instr( const fgTBI_instr & image):
32                  dual_instr_item( (const dual_instr_item &) image),
33                  BankLimit( image.BankLimit),
34                  SlewLimit( image.SlewLimit),
35                  scr_hole ( image.scr_hole )
36 {
37 }
38
39 fgTBI_instr & fgTBI_instr ::
40 operator = (const fgTBI_instr & rhs )
41 {
42   if( !(this == &rhs)) {
43     dual_instr_item::operator = (rhs);
44     BankLimit = rhs.BankLimit;
45     SlewLimit = rhs.SlewLimit;
46     scr_hole  = rhs.scr_hole;
47     }
48    return *this;
49 }
50
51 //
52 //  Draws a Turn Bank Indicator on the screen
53 //
54
55  void fgTBI_instr :: draw( void )
56 {
57      float bank_angle, sideslip_angle;
58      float ss_const; // sideslip angle pixels per rad
59      float cen_x, cen_y, bank, fspan, tee, hole;
60
61      int span = get_span();
62      
63      float zero = 0.0;
64   
65      RECT My_box = get_location();
66      POINT centroid = get_centroid();
67      int tee_height = My_box.bottom;
68
69      bank_angle     = current_ch2();  // Roll limit +/- 30 degrees
70      
71      if( bank_angle < -SGD_PI_2/3 ) {
72          bank_angle = -SGD_PI_2/3;
73      } else if( bank_angle > SGD_PI_2/3 ) {
74              bank_angle = SGD_PI_2/3;
75      }
76      
77      sideslip_angle = current_ch1(); // Sideslip limit +/- 20 degrees
78      
79      if( sideslip_angle < -SGD_PI/9 ) {
80          sideslip_angle = -SGD_PI/9;
81      } else if( sideslip_angle > SGD_PI/9 ) {
82              sideslip_angle = SGD_PI/9;
83      }
84
85      cen_x = centroid.x;
86      cen_y = centroid.y;
87      bank  = bank_angle * RAD_TO_DEG;
88      tee   = -tee_height;
89      fspan = span;
90      hole  = scr_hole;
91      ss_const = 2 * sideslip_angle * fspan/(SGD_2PI/9);  // width represents 40 degrees
92      
93 //   printf("side_slip: %f   fspan: %f\n", sideslip_angle, fspan);
94 //   printf("ss_const: %f   hole: %f\n", ss_const, hole);
95      
96      glPushMatrix();
97      glTranslatef(cen_x, cen_y, zero);
98      glRotatef(-bank, zero, zero, 1.0);
99     
100      glBegin(GL_LINES);
101      
102      if( !scr_hole )  
103      {
104          glVertex2f( -fspan, zero );
105          glVertex2f(  fspan, zero );
106      } else {
107          glVertex2f( -fspan, zero );
108          glVertex2f( -hole,  zero );
109          glVertex2f(  hole,  zero );
110          glVertex2f(  fspan, zero );
111      }
112      // draw teemarks
113      glVertex2f(  hole, zero );
114      glVertex2f(  hole, tee );
115      glVertex2f( -hole, zero );
116      glVertex2f( -hole, tee );
117      
118      glEnd();
119      
120      glBegin(GL_LINE_LOOP);
121          glVertex2f( ss_const,        -hole);
122          glVertex2f( ss_const + hole,  zero);
123          glVertex2f( ss_const,         hole);
124          glVertex2f( ss_const - hole,  zero);
125      glEnd();
126
127      glPopMatrix();
128 }