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