]> git.mxchange.org Git - flightgear.git/blob - Simulator/Cockpit/hud_tbi.cxx
Initial revision.
[flightgear.git] / Simulator / Cockpit / hud_tbi.cxx
1 #ifdef HAVE_CONFIG_H
2 #  include <config.h>
3 #endif
4
5 #ifdef HAVE_WINDOWS_H
6 #  include <windows.h>
7 #endif
8 #include <stdlib.h>
9 #include <string.h>
10 #include <Aircraft/aircraft.hxx>
11 #include <Include/fg_constants.h>
12 #include <Math/fg_random.h>
13 #include <Math/mat3.h>
14 #include <Math/polar3d.hxx>
15 #include <Scenery/scenery.hxx>
16 #include <Time/fg_timer.hxx>
17
18
19 #include "hud.hxx"
20 //============ Top of fgTBI_instr class member definitions ==============
21
22 fgTBI_instr ::
23 fgTBI_instr( int              x,
24              int              y,
25              UINT             width,
26              UINT             height,
27              DBLFNPTR  chn1_source,
28              DBLFNPTR  chn2_source,
29              double    maxBankAngle,
30              double    maxSlipAngle,
31              UINT      gap_width,
32              bool      working ) :
33                dual_instr_item( x, y, width, height,
34                                 chn1_source,
35                                 chn2_source,
36                                 working,
37                                 HUDS_TOP),
38                BankLimit      (maxBankAngle),
39                SlewLimit      (maxSlipAngle),
40                scr_hole       (gap_width   )
41 {
42 }
43
44 fgTBI_instr :: ~fgTBI_instr() {}
45
46 fgTBI_instr :: fgTBI_instr( const fgTBI_instr & image):
47                  dual_instr_item( (const dual_instr_item &) image),
48                  BankLimit( image.BankLimit),
49                  SlewLimit( image.SlewLimit),
50                  scr_hole ( image.scr_hole )
51 {
52 }
53
54 fgTBI_instr & fgTBI_instr ::
55 operator = (const fgTBI_instr & rhs )
56 {
57   if( !(this == &rhs)) {
58     dual_instr_item::operator = (rhs);
59     BankLimit = rhs.BankLimit;
60     SlewLimit = rhs.SlewLimit;
61     scr_hole  = rhs.scr_hole;
62     }
63    return *this;
64 }
65
66 //
67 //      Draws a Turn Bank Indicator on the screen
68 //
69
70  void fgTBI_instr :: draw( void )
71 {
72   int x_inc1, y_inc1;
73   int x_inc2, y_inc2;
74   int x_t_inc1, y_t_inc1;
75
76   int d_bottom_x, d_bottom_y;
77   int d_right_x, d_right_y;
78   int d_top_x, d_top_y;
79   int d_left_x, d_left_y;
80
81   int inc_b_x, inc_b_y;
82   int inc_r_x, inc_r_y;
83   int inc_t_x, inc_t_y;
84   int inc_l_x, inc_l_y;
85   RECT My_box = get_location();
86   POINT centroid = get_centroid();
87   int tee_height = My_box.bottom;
88
89 //      struct fgFLIGHT *f = &current_aircraft.flight;
90   double sin_bank, cos_bank;
91   double bank_angle, sideslip_angle;
92   double ss_const; // sideslip angle pixels per rad
93
94   bank_angle     = current_ch2();  // Roll limit +/- 30 degrees
95   if( bank_angle < -FG_PI_2/3 ) {
96     bank_angle = -FG_PI_2/3;
97     }
98   else
99     if( bank_angle > FG_PI_2/3 ) {
100       bank_angle = FG_PI_2/3;
101       }
102   sideslip_angle = current_ch1(); // Sideslip limit +/- 20 degrees
103   if( sideslip_angle < -FG_PI/9 ) {
104     sideslip_angle = -FG_PI/9;
105     }
106   else
107     if( sideslip_angle > FG_PI/9 ) {
108       sideslip_angle = FG_PI/9;
109       }
110
111         // sin_bank = sin( FG_2PI-FG_Phi );
112         // cos_bank = cos( FG_2PI-FG_Phi );
113   sin_bank = sin(FG_2PI-bank_angle);
114   cos_bank = cos(FG_2PI-bank_angle);
115
116   x_inc1 = (int)(get_span() * cos_bank);
117   y_inc1 = (int)(get_span() * sin_bank);
118   x_inc2 = (int)(scr_hole  * cos_bank);
119   y_inc2 = (int)(scr_hole  * sin_bank);
120
121   x_t_inc1 = (int)(tee_height * sin_bank);
122   y_t_inc1 = (int)(tee_height * cos_bank);
123
124   d_bottom_x = 0;
125   d_bottom_y = (int)(-scr_hole);
126   d_right_x  = (int)(scr_hole);
127   d_right_y  = 0;
128   d_top_x    = 0;
129   d_top_y    = (int)(scr_hole);
130   d_left_x   = (int)(-scr_hole);
131   d_left_y   = 0;
132
133   ss_const = (get_span()*2)/(FG_2PI/9);  // width represents 40 degrees
134
135   d_bottom_x += (int)(sideslip_angle*ss_const);
136   d_right_x  += (int)(sideslip_angle*ss_const);
137   d_left_x   += (int)(sideslip_angle*ss_const);
138   d_top_x    += (int)(sideslip_angle*ss_const);
139
140   inc_b_x = (int)(d_bottom_x*cos_bank-d_bottom_y*sin_bank);
141   inc_b_y = (int)(d_bottom_x*sin_bank+d_bottom_y*cos_bank);
142   inc_r_x = (int)(d_right_x*cos_bank-d_right_y*sin_bank);
143   inc_r_y = (int)(d_right_x*sin_bank+d_right_y*cos_bank);
144   inc_t_x = (int)(d_top_x*cos_bank-d_top_y*sin_bank);
145   inc_t_y = (int)(d_top_x*sin_bank+d_top_y*cos_bank);
146   inc_l_x = (int)(d_left_x*cos_bank-d_left_y*sin_bank);
147   inc_l_y = (int)(d_left_x*sin_bank+d_left_y*cos_bank);
148
149   if( scr_hole == 0 )
150     {
151     drawOneLine( centroid.x - x_inc1, centroid.y - y_inc1, \
152                  centroid.x + x_inc1, centroid.y + y_inc1 );
153     }
154   else
155     {
156     drawOneLine( centroid.x - x_inc1, centroid.y - y_inc1, \
157                  centroid.x - x_inc2, centroid.y - y_inc2 );
158     drawOneLine( centroid.x + x_inc2, centroid.y + y_inc2, \
159                  centroid.x + x_inc1, centroid.y + y_inc1 );
160     }
161
162   // draw teemarks
163   drawOneLine( centroid.x + x_inc2,            \
164                  centroid.y + y_inc2,          \
165                centroid.x + x_inc2 + x_t_inc1, \
166                  centroid.y + y_inc2 - y_t_inc1 );
167   drawOneLine( centroid.x - x_inc2,            \
168                  centroid.y - y_inc2,          \
169                centroid.x - x_inc2 + x_t_inc1, \
170                  centroid.y - y_inc2 - y_t_inc1 );
171
172   // draw sideslip diamond (it is not yet positioned correctly )
173   drawOneLine( centroid.x + inc_b_x, \
174                centroid.y + inc_b_y, \
175                centroid.x + inc_r_x, \
176                centroid.y + inc_r_y );
177   drawOneLine( centroid.x + inc_r_x, \
178                centroid.y + inc_r_y, \
179                centroid.x + inc_t_x, \
180                centroid.y + inc_t_y );
181   drawOneLine( centroid.x + inc_t_x, \
182                centroid.y + inc_t_y, \
183                centroid.x + inc_l_x, \
184                centroid.y + inc_l_y );
185   drawOneLine( centroid.x + inc_l_x, \
186                centroid.y + inc_l_y, \
187                centroid.x + inc_b_x, \
188                centroid.y + inc_b_y );
189
190 }