]> git.mxchange.org Git - flightgear.git/blob - src/Cockpit/hud_tbi.cxx
MSVC9 fix
[flightgear.git] / src / Cockpit / hud_tbi.cxx
1 //
2 //  Turn Bank Indicator
3 //
4
5 #include <math.h>
6 #include "hud.hxx"
7
8 // FIXME
9 extern float get_roll(void);
10 extern float get_sideslip(void);
11
12 // x, y, width, height, get_roll, get_sideslip, maxBankAngle, maxSlipAngle, gap_width, working, tsi, rad
13
14 // int x, int y, UINT width, UINT height, FLTFNPTR chn1_source, FLTFNPTR chn2_source, float maxBankAngle,
15 // float maxSlipAngle, UINT gap_width, bool working, bool tsivalue, float radius) :
16
17
18 fgTBI_instr::fgTBI_instr(const SGPropertyNode *node) :
19     dual_instr_item(
20             node->getIntValue("x"),
21             node->getIntValue("y"),
22             node->getIntValue("width"),
23             node->getIntValue("height"),
24             get_roll,                                   // FIXME
25             get_sideslip,
26             node->getBoolValue("working", true),
27             HUDS_TOP),
28     BankLimit(int(node->getFloatValue("maxBankAngle"))),
29     SlewLimit(int(node->getFloatValue("maxSlipAngle"))),
30     scr_hole(node->getIntValue("gap_width")),
31     tsi(node->getBoolValue("tsi")),
32     rad(node->getFloatValue("rad"))
33
34 {
35     SG_LOG(SG_INPUT, SG_INFO, "Done reading TBI instrument"
36             << node->getStringValue("name", "[unnamed]"));
37 }
38
39
40 void fgTBI_instr::draw(void)
41 {
42     float bank_angle, sideslip_angle;
43     float ss_const; // sideslip angle pixels per rad
44     float cen_x, cen_y, bank, fspan, tee, hole;
45
46     int span = get_span();
47     float zero = 0.0;
48
49     RECT My_box = get_location();
50     POINT centroid = get_centroid();
51     int tee_height = My_box.bottom;
52
53     bank_angle = current_ch2();  // Roll limit +/- 30 degrees
54
55     if (bank_angle < -SGD_PI_2 / 3)
56         bank_angle = -SGD_PI_2 / 3;
57     else if (bank_angle > SGD_PI_2 / 3)
58         bank_angle = SGD_PI_2 / 3;
59
60
61     sideslip_angle = current_ch1(); // Sideslip limit +/- 20 degrees
62
63     if (sideslip_angle < -SGD_PI / 9)
64         sideslip_angle = -SGD_PI / 9;
65     else if ( sideslip_angle > SGD_PI / 9 )
66         sideslip_angle = SGD_PI / 9;
67
68     cen_x = centroid.x;
69     cen_y = centroid.y;
70
71     bank = bank_angle * SGD_RADIANS_TO_DEGREES;
72     tee = -tee_height;
73     fspan = span;
74     hole = scr_hole;
75     ss_const = 2 * sideslip_angle * fspan / (SGD_2PI / 9);  // width represents 40 degrees
76
77 //  printf("side_slip: %f   fspan: %f\n", sideslip_angle, fspan);
78 //  printf("ss_const: %f   hole: %f\n", ss_const, hole);
79
80     glPushMatrix();
81     glTranslatef(cen_x, cen_y, zero);
82     glRotatef(-bank, zero, zero, 1.0);
83
84     if (!tsi) {
85        glBegin(GL_LINES);
86
87        if (!scr_hole) {
88            glVertex2f(-fspan, zero);
89            glVertex2f(fspan, zero);
90
91        } else {
92            glVertex2f(-fspan, zero);
93            glVertex2f(-hole, zero);
94            glVertex2f(hole, zero);
95            glVertex2f(fspan, zero);
96        }
97
98        // draw teemarks
99        glVertex2f(hole, zero);
100        glVertex2f(hole, tee);
101        glVertex2f(-hole, zero);
102        glVertex2f(-hole, tee);
103        glEnd();
104
105        glBegin(GL_LINE_LOOP);
106        glVertex2f(ss_const, -hole);
107        glVertex2f(ss_const + hole, zero);
108        glVertex2f(ss_const, hole);
109        glVertex2f(ss_const - hole, zero);
110        glEnd();
111
112     } else { //if tsi enabled
113         drawOneLine(cen_x-1.0, My_box.top, cen_x + 1.0, My_box.top);
114         drawOneLine(cen_x-1.0, My_box.top, cen_x - 1.0, My_box.top + 10.0);
115         drawOneLine(cen_x+1.0, My_box.top, cen_x + 1.0, My_box.top + 10.0);
116         drawOneLine(cen_x-1.0, My_box.top + 10.0, cen_x + 1.0, My_box.top + 10.0);
117
118         float x1, y1, x2, y2, x3, y3, x4, y4, x5, y5;
119         float xc, yc, r = rad, r1 = rad - 10.0, r2 = rad - 5.0;
120
121         xc = My_box.left + My_box.right / 2.0 ;
122         yc = My_box.top + r;
123
124         // first n last lines
125         x1 = xc + r * cos(255.0 * SGD_DEGREES_TO_RADIANS);
126         y1 = yc + r * sin(255.0 * SGD_DEGREES_TO_RADIANS);
127
128         x2 = xc + r1 * cos(255.0 * SGD_DEGREES_TO_RADIANS);
129         y2 = yc + r1 * sin(255.0 * SGD_DEGREES_TO_RADIANS);
130         drawOneLine(x1,y1,x2,y2);
131
132         x1 = xc + r * cos(285.0 * SGD_DEGREES_TO_RADIANS);
133         y1 = yc + r * sin(285.0 * SGD_DEGREES_TO_RADIANS);
134
135         x2 = xc + r1 * cos(285.0 * SGD_DEGREES_TO_RADIANS);
136         y2 = yc + r1 * sin(285.0 * SGD_DEGREES_TO_RADIANS);
137         drawOneLine(x1, y1, x2, y2);
138
139         // second n fifth  lines
140         x1 = xc + r * cos(260.0 * SGD_DEGREES_TO_RADIANS);
141         y1 = yc + r * sin(260.0 * SGD_DEGREES_TO_RADIANS);
142
143         x2 = xc + r2 * cos(260.0 * SGD_DEGREES_TO_RADIANS);
144         y2 = yc + r2 * sin(260.0 * SGD_DEGREES_TO_RADIANS);
145         drawOneLine(x1, y1, x2, y2);
146
147         x1 = xc + r * cos(280.0 * SGD_DEGREES_TO_RADIANS);
148         y1 = yc + r * sin(280.0 * SGD_DEGREES_TO_RADIANS);
149
150         x2 = xc + r2 * cos(280.0 * SGD_DEGREES_TO_RADIANS);
151         y2 = yc + r2 * sin(280.0 * SGD_DEGREES_TO_RADIANS);
152         drawOneLine(x1, y1, x2, y2);
153
154         // third n fourth lines
155         x1 = xc + r * cos(265.0 * SGD_DEGREES_TO_RADIANS);
156         y1 = yc + r * sin(265.0 * SGD_DEGREES_TO_RADIANS);
157
158
159         x2 = xc + r2 * cos(265.0 * SGD_DEGREES_TO_RADIANS);
160         y2 = yc + r2 * sin(265.0 * SGD_DEGREES_TO_RADIANS);
161         drawOneLine(x1, y1, x2, y2);
162
163         x1 = xc + r * cos(275.0 * SGD_DEGREES_TO_RADIANS);
164         y1 = yc + r * sin(275.0 * SGD_DEGREES_TO_RADIANS);
165
166         x2 = xc + r2 * cos(275.0 * SGD_DEGREES_TO_RADIANS);
167         y2 = yc + r2 * sin(275.0 * SGD_DEGREES_TO_RADIANS);
168         drawOneLine(x1,y1,x2,y2);
169
170         // draw marker
171         float  valbank, valsideslip, sideslip;
172
173         r = rad + 5.0;  // add gap
174
175         // upper polygon
176         bank_angle = current_ch2();
177
178         bank = bank_angle * SGD_RADIANS_TO_DEGREES;  // Roll limit +/- 30 degrees
179         if (bank > BankLimit)
180             bank = BankLimit;
181         if (bank < -1.0*BankLimit)
182             bank = -1.0*BankLimit;
183
184         valbank = bank * 15.0 / BankLimit; // total span of TSI is 30 degrees
185
186         sideslip_angle = current_ch1(); // Sideslip limit +/- 20 degrees
187         sideslip = sideslip_angle * SGD_RADIANS_TO_DEGREES;
188         if (sideslip > SlewLimit)
189             sideslip = SlewLimit;
190         if (sideslip < -1.0 * SlewLimit)
191             sideslip = -1.0 * SlewLimit;
192         valsideslip = sideslip * 15.0 / SlewLimit;
193
194         // values 270, 225 and 315 are angles in degrees...
195         x1 = xc + r * cos((valbank + 270.0) * SGD_DEGREES_TO_RADIANS);
196         y1 = yc + r * sin((valbank + 270.0) * SGD_DEGREES_TO_RADIANS);
197
198         x2 = x1 + 6.0 * cos(225 * SGD_DEGREES_TO_RADIANS);
199         y2 = y1 + 6.0 * sin(225 * SGD_DEGREES_TO_RADIANS);
200
201         x3 = x1 + 6.0 * cos(315 * SGD_DEGREES_TO_RADIANS);
202         y3 = y1 + 6.0 * sin(315 * SGD_DEGREES_TO_RADIANS);
203
204         drawOneLine(x1, y1, x2, y2);
205         drawOneLine(x2, y2, x3, y3);
206         drawOneLine(x3, y3, x1, y1);
207
208         // lower polygon
209         x1 = xc + r * cos((valbank + 270.0) * SGD_DEGREES_TO_RADIANS);
210         y1 = yc + r * sin((valbank + 270.0) * SGD_DEGREES_TO_RADIANS);
211
212         x2 = x1 + 6.0 * cos(225 * SGD_DEGREES_TO_RADIANS);
213         y2 = y1 + 6.0 * sin(225 * SGD_DEGREES_TO_RADIANS);
214
215         x3 = x1 + 6.0 * cos(315 * SGD_DEGREES_TO_RADIANS);
216         y3 = y1 + 6.0 * sin(315 * SGD_DEGREES_TO_RADIANS);
217
218         x4 = x1 + 10.0 * cos(225 * SGD_DEGREES_TO_RADIANS);
219         y4 = y1 + 10.0 * sin(225 * SGD_DEGREES_TO_RADIANS);
220
221         x5 = x1 + 10.0 * cos(315 * SGD_DEGREES_TO_RADIANS);
222         y5 = y1 + 10.0 * sin(315 * SGD_DEGREES_TO_RADIANS);
223
224         x2 = x2 + cos(valsideslip * SGD_DEGREES_TO_RADIANS);
225         y2 = y2 + sin(valsideslip * SGD_DEGREES_TO_RADIANS);
226         x3 = x3 + cos(valsideslip * SGD_DEGREES_TO_RADIANS);
227         y3 = y3 + sin(valsideslip * SGD_DEGREES_TO_RADIANS);
228         x4 = x4 + cos(valsideslip * SGD_DEGREES_TO_RADIANS);
229         y4 = y4 + sin(valsideslip * SGD_DEGREES_TO_RADIANS);
230         x5 = x5 + cos(valsideslip * SGD_DEGREES_TO_RADIANS);
231         y5 = y5 + sin(valsideslip * SGD_DEGREES_TO_RADIANS);
232
233         drawOneLine(x2, y2, x3, y3);
234         drawOneLine(x3, y3, x5, y5);
235         drawOneLine(x5, y5, x4, y4);
236         drawOneLine(x4, y4, x2, y2);
237     }
238     glPopMatrix();
239 }
240
241