]> git.mxchange.org Git - flightgear.git/blob - src/Cockpit/hud_tbi.cxx
Get rid of the double comma's for the file section of the generic protocol also.
[flightgear.git] / src / Cockpit / hud_tbi.cxx
1
2 #include "hud.hxx"
3 #include<math.h>
4
5
6 //============ Top of fgTBI_instr class member definitions ==============
7
8 fgTBI_instr ::
9 fgTBI_instr( int              x,
10              int              y,
11              UINT             width,
12              UINT             height,
13              FLTFNPTR  chn1_source,
14              FLTFNPTR  chn2_source,
15              float    maxBankAngle,
16              float    maxSlipAngle,
17              UINT      gap_width,
18              bool      working,
19                          bool      tsivalue, //suma
20                          float     radius) : //suma
21                dual_instr_item( x, y, width, height,
22                                 chn1_source,
23                                 chn2_source,
24                                 working,
25                                 HUDS_TOP),
26                BankLimit      ((int)(maxBankAngle)),
27                SlewLimit      ((int)(maxSlipAngle)),
28                scr_hole       (gap_width   )
29 {
30         tsi=tsivalue; //suma   
31         rad=radius; //suma
32 }
33
34 fgTBI_instr :: ~fgTBI_instr() {}
35
36 fgTBI_instr :: fgTBI_instr( const fgTBI_instr & image):
37                  dual_instr_item( (const dual_instr_item &) image),
38                  BankLimit( image.BankLimit),
39                  SlewLimit( image.SlewLimit),
40                  scr_hole ( image.scr_hole )
41 {
42 }
43
44 fgTBI_instr & fgTBI_instr ::
45 operator = (const fgTBI_instr & rhs )
46 {
47   if( !(this == &rhs)) {
48     dual_instr_item::operator = (rhs);
49     BankLimit = rhs.BankLimit;
50     SlewLimit = rhs.SlewLimit;
51     scr_hole  = rhs.scr_hole;
52     }
53    return *this;
54 }
55
56 //
57 //  Draws a Turn Bank Indicator on the screen
58 //
59
60  void fgTBI_instr :: draw( void )
61 {
62      float bank_angle, sideslip_angle;
63      float ss_const; // sideslip angle pixels per rad
64      float cen_x, cen_y, bank, fspan, tee, hole;
65
66      int span = get_span();
67      
68      float zero = 0.0;
69   
70      RECT My_box = get_location();
71      POINT centroid = get_centroid();
72      int tee_height = My_box.bottom;
73          
74      bank_angle     = current_ch2();  // Roll limit +/- 30 degrees
75      
76      if( bank_angle < -SGD_PI_2/3 ) 
77          {
78          bank_angle = -SGD_PI_2/3;
79      }
80          else if( bank_angle > SGD_PI_2/3 ) 
81          {
82              bank_angle = SGD_PI_2/3;
83      }
84      
85          
86          sideslip_angle = current_ch1(); // Sideslip limit +/- 20 degrees
87
88      if( sideslip_angle < -SGD_PI/9 ) 
89          {
90          sideslip_angle = -SGD_PI/9;
91      }
92          else if( sideslip_angle > SGD_PI/9 ) 
93          {
94              sideslip_angle = SGD_PI/9;
95      }
96
97      cen_x = centroid.x;
98      cen_y = centroid.y;
99      
100      bank  = bank_angle * SGD_RADIANS_TO_DEGREES;
101          tee   = -tee_height;
102      fspan = span;
103      hole  = scr_hole;
104      ss_const = 2 * sideslip_angle * fspan/(SGD_2PI/9);  // width represents 40 degrees
105      
106 //   printf("side_slip: %f   fspan: %f\n", sideslip_angle, fspan);
107 //   printf("ss_const: %f   hole: %f\n", ss_const, hole);
108      
109         
110      glPushMatrix();
111      glTranslatef(cen_x, cen_y, zero);
112      glRotatef(-bank, zero, zero, 1.0);
113     
114          if(!tsi)
115          {
116                  
117                 glBegin(GL_LINES);
118              
119                 if( !scr_hole )  
120                 {
121                         glVertex2f( -fspan, zero );
122                         glVertex2f(  fspan, zero );
123                 } 
124                 else
125                 {
126                         glVertex2f( -fspan, zero );
127                         glVertex2f( -hole,  zero );
128                         glVertex2f(  hole,  zero );
129                         glVertex2f(  fspan, zero );
130                 }
131                 // draw teemarks
132                 glVertex2f(  hole, zero );
133                 glVertex2f(  hole, tee );
134                 glVertex2f( -hole, zero );
135                 glVertex2f( -hole, tee );
136              
137                 glEnd();
138      
139                 glBegin(GL_LINE_LOOP);
140                         glVertex2f( ss_const,        -hole);
141                         glVertex2f( ss_const + hole,  zero);
142                         glVertex2f( ss_const,         hole);
143                         glVertex2f( ss_const - hole,  zero);
144                 glEnd();
145
146
147          }
148          
149
150          else //if tsi enabled
151          {
152                  // float factor = My_box.right / 6.0;
153
154                  drawOneLine(cen_x-1.0, My_box.top,      cen_x+1.0, My_box.top);
155                  drawOneLine(cen_x-1.0, My_box.top,      cen_x-1.0, My_box.top+10.0);
156                  drawOneLine(cen_x+1.0, My_box.top,      cen_x+1.0, My_box.top+10.0);
157                  drawOneLine(cen_x-1.0, My_box.top+10.0, cen_x+1.0, My_box.top+10.0);
158
159          float x1, y1, x2, y2, x3, y3, x4,y4, x5, y5;
160                  float xc, yc, r=rad, r1= rad-10.0, r2=rad-5.0;
161                  
162                  xc = My_box.left + My_box.right/ 2.0 ;
163                  yc = My_box.top + r;
164
165 //first n last lines
166                   x1= xc + r * cos (255.0 * SGD_DEGREES_TO_RADIANS);
167                   y1= yc + r * sin (255.0 * SGD_DEGREES_TO_RADIANS);
168
169                   x2= xc + r1 * cos (255.0 * SGD_DEGREES_TO_RADIANS);
170                   y2= yc + r1 * sin (255.0 * SGD_DEGREES_TO_RADIANS);
171                   
172                   drawOneLine(x1,y1,x2,y2);
173
174                   x1= xc + r * cos (285.0 * SGD_DEGREES_TO_RADIANS);
175                   y1= yc + r * sin (285.0 * SGD_DEGREES_TO_RADIANS);
176
177                   x2= xc + r1 * cos (285.0 * SGD_DEGREES_TO_RADIANS);
178                   y2= yc + r1 * sin (285.0 * SGD_DEGREES_TO_RADIANS);
179
180           drawOneLine(x1,y1,x2,y2);
181
182 //second n fifth  lines
183
184                   x1= xc + r * cos (260.0 * SGD_DEGREES_TO_RADIANS);
185                   y1= yc + r * sin (260.0 * SGD_DEGREES_TO_RADIANS);
186                   
187                   x2= xc + r2 * cos (260.0 * SGD_DEGREES_TO_RADIANS);
188                   y2= yc + r2 * sin (260.0 * SGD_DEGREES_TO_RADIANS);
189                   
190                   drawOneLine(x1,y1,x2,y2);
191
192                   x1= xc + r * cos (280.0 * SGD_DEGREES_TO_RADIANS);
193                   y1= yc + r * sin (280.0 * SGD_DEGREES_TO_RADIANS);
194
195                   
196                   x2= xc + r2 * cos (280.0 * SGD_DEGREES_TO_RADIANS);
197                   y2= yc + r2 * sin (280.0 * SGD_DEGREES_TO_RADIANS);
198
199           drawOneLine(x1,y1,x2,y2);
200
201 //third n fourth lines
202
203
204                   x1= xc + r * cos (265.0 * SGD_DEGREES_TO_RADIANS);
205                   y1= yc + r * sin (265.0 * SGD_DEGREES_TO_RADIANS);
206
207                   
208                   x2= xc + r2 * cos (265.0 * SGD_DEGREES_TO_RADIANS);
209                   y2= yc + r2 * sin (265.0 * SGD_DEGREES_TO_RADIANS);
210                   
211                   drawOneLine(x1,y1,x2,y2);
212
213                   x1= xc + r * cos (275.0 * SGD_DEGREES_TO_RADIANS);
214                   y1= yc + r * sin (275.0 * SGD_DEGREES_TO_RADIANS);
215                   
216                   x2= xc + r2 * cos (275.0 * SGD_DEGREES_TO_RADIANS);
217                   y2= yc + r2 * sin (275.0 * SGD_DEGREES_TO_RADIANS);
218
219           drawOneLine(x1,y1,x2,y2);
220
221                   //to draw marker
222                   
223                   
224                 
225                           float  valbank, valsideslip, sideslip;
226                          
227                           r = rad + 5.0;  //5 is added to get a gap 
228                          // upper polygon
229               bank_angle     = current_ch2();
230
231                           bank= bank_angle * SGD_RADIANS_TO_DEGREES;  // Roll limit +/- 30 degrees
232                           if(bank > BankLimit)
233                                         bank = BankLimit;
234                           if(bank < -1.0*BankLimit)
235                                         bank = -1.0*BankLimit;
236
237                           valbank = bank * 15.0 / BankLimit; // total span of TSI is 30 degrees
238                           
239                           sideslip_angle = current_ch1(); // Sideslip limit +/- 20 degrees
240                           sideslip= sideslip_angle * SGD_RADIANS_TO_DEGREES;  
241                           if(sideslip > SlewLimit)
242                                   sideslip = SlewLimit;
243                           if(sideslip < -1.0*SlewLimit)
244                                   sideslip = -1.0*SlewLimit;
245               valsideslip = sideslip * 15.0 / SlewLimit;
246                           
247                           //values 270, 225 and 315 are angles in degrees...
248
249                           x1= xc + r * cos ((valbank+270.0) * SGD_DEGREES_TO_RADIANS);
250                           y1= yc + r * sin ((valbank+270.0) * SGD_DEGREES_TO_RADIANS);
251
252                           x2= x1 + 6.0 * cos (225 * SGD_DEGREES_TO_RADIANS);
253                           y2= y1 + 6.0 * sin (225 * SGD_DEGREES_TO_RADIANS);
254                           
255                           x3= x1 + 6.0 * cos (315 * SGD_DEGREES_TO_RADIANS);
256                           y3= y1 + 6.0 * sin (315 * SGD_DEGREES_TO_RADIANS);
257
258                       drawOneLine(x1, y1, x2, y2);
259                           drawOneLine(x2, y2, x3, y3);
260                           drawOneLine(x3, y3, x1, y1);
261
262                           //lower polygon...
263                          
264                          
265                           
266                           x1= xc + r * cos ((valbank+270.0) * SGD_DEGREES_TO_RADIANS);
267                           y1= yc + r * sin ((valbank+270.0) * SGD_DEGREES_TO_RADIANS);
268
269                           x2= x1 + 6.0 * cos (225 * SGD_DEGREES_TO_RADIANS);
270                           y2= y1 + 6.0 * sin (225 * SGD_DEGREES_TO_RADIANS);
271                           
272                           x3= x1 + 6.0 * cos (315 * SGD_DEGREES_TO_RADIANS);
273                           y3= y1 + 6.0 * sin (315 * SGD_DEGREES_TO_RADIANS);
274
275                           x4= x1 + 10.0 * cos (225 * SGD_DEGREES_TO_RADIANS);
276                           y4= y1 + 10.0 * sin (225 * SGD_DEGREES_TO_RADIANS);
277                           
278                           x5= x1 + 10.0 * cos (315 * SGD_DEGREES_TO_RADIANS);
279                           y5= y1 + 10.0 * sin (315 * SGD_DEGREES_TO_RADIANS);
280
281                           x2 = x2 + cos (valsideslip * SGD_DEGREES_TO_RADIANS);
282                       y2 = y2 + sin (valsideslip * SGD_DEGREES_TO_RADIANS);
283                           x3 = x3 + cos (valsideslip * SGD_DEGREES_TO_RADIANS);
284                           y3 = y3 + sin (valsideslip * SGD_DEGREES_TO_RADIANS);
285                           x4 = x4 + cos (valsideslip * SGD_DEGREES_TO_RADIANS);
286                           y4 = y4 + sin (valsideslip * SGD_DEGREES_TO_RADIANS);
287                           x5 = x5 + cos (valsideslip * SGD_DEGREES_TO_RADIANS);
288                           y5 = y5 + sin (valsideslip * SGD_DEGREES_TO_RADIANS);
289
290                           drawOneLine(x2, y2, x3, y3); 
291                           drawOneLine(x3, y3, x5, y5);
292                           drawOneLine(x5, y5, x4, y4);
293                           drawOneLine(x4, y4, x2, y2);  
294                          
295  
296          }
297
298                 glPopMatrix();
299 }