]> git.mxchange.org Git - flightgear.git/blob - src/Cockpit/hud_tbi.cxx
Added first stab at a socket class.
[flightgear.git] / src / 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              FLTFNPTR  chn1_source,
28              FLTFNPTR  chn2_source,
29              float    maxBankAngle,
30              float    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      ((int)(maxBankAngle)),
39                SlewLimit      ((int)(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      float bank_angle, sideslip_angle;
73      float ss_const; // sideslip angle pixels per rad
74      float cen_x, cen_y, bank, fspan, tee, hole;
75
76      int span = get_span();
77      
78      float zero = 0.0;
79   
80      RECT My_box = get_location();
81      POINT centroid = get_centroid();
82      int tee_height = My_box.bottom;
83
84      bank_angle     = current_ch2();  // Roll limit +/- 30 degrees
85      
86      if( bank_angle < -FG_PI_2/3 ) {
87          bank_angle = -FG_PI_2/3;
88      } else if( bank_angle > FG_PI_2/3 ) {
89              bank_angle = FG_PI_2/3;
90      }
91      
92      sideslip_angle = current_ch1(); // Sideslip limit +/- 20 degrees
93      
94      if( sideslip_angle < -FG_PI/9 ) {
95          sideslip_angle = -FG_PI/9;
96      } else if( sideslip_angle > FG_PI/9 ) {
97              sideslip_angle = FG_PI/9;
98      }
99
100      cen_x = centroid.x;
101      cen_y = centroid.y;
102      bank  = bank_angle * RAD_TO_DEG;
103      tee   = -tee_height;
104      fspan = span;
105      hole  = scr_hole;
106      ss_const = 2 * sideslip_angle * fspan/(FG_2PI/9);  // width represents 40 degrees
107      
108 //   printf("side_slip: %f   fspan: %f\n", sideslip_angle, fspan);
109 //   printf("ss_const: %f   hole: %f\n", ss_const, hole);
110      
111      glPushMatrix();
112      glTranslatef(cen_x, cen_y, zero);
113      glRotatef(-bank, zero, zero, 1.0);
114     
115      glBegin(GL_LINES);
116      
117      if( !scr_hole )  
118      {
119          glVertex2f( -fspan, zero );
120          glVertex2f(  fspan, zero );
121      } else {
122          glVertex2f( -fspan, zero );
123          glVertex2f( -hole,  zero );
124          glVertex2f(  hole,  zero );
125          glVertex2f(  fspan, zero );
126      }
127      // draw teemarks
128      glVertex2f(  hole, zero );
129      glVertex2f(  hole, tee );
130      glVertex2f( -hole, zero );
131      glVertex2f( -hole, tee );
132      
133      glEnd();
134      
135      glBegin(GL_LINE_LOOP);
136          glVertex2f( ss_const,        -hole);
137          glVertex2f( ss_const + hole,  zero);
138          glVertex2f( ss_const,         hole);
139          glVertex2f( ss_const - hole,  zero);
140      glEnd();
141
142      glPopMatrix();
143 }