]> git.mxchange.org Git - flightgear.git/blob - Simulator/Cockpit/cockpit.cxx
Initial revision.
[flightgear.git] / Simulator / Cockpit / cockpit.cxx
1 // cockpit.cxx -- routines to draw a cockpit (initial draft)
2 //
3 // Written by Michele America, started September 1997.
4 //
5 // Copyright (C) 1997  Michele F. America  - nomimarketing@mail.telepac.pt
6 //
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License as
9 // published by the Free Software Foundation; either version 2 of the
10 // License, or (at your option) any later version.
11 //
12 // This program is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 // General Public License for more details.
16 //
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 //
21 // $Id$
22
23
24 #ifdef HAVE_CONFIG_H
25 #  include <config.h>
26 #endif
27
28 #ifdef HAVE_WINDOWS_H          
29 #  include <windows.h>
30 #endif
31
32 #include <GL/glut.h>
33 #include <XGL/xgl.h>
34
35 #include <stdlib.h>
36 #include <stdio.h>
37 #include <string.h>
38
39 #include <Aircraft/aircraft.hxx>
40 #include <Debug/logstream.hxx>
41 #include <Include/fg_constants.h>
42 #include <Include/general.hxx>
43 #include <Main/options.hxx>
44 #include <Main/views.hxx>
45 #include <Math/fg_random.h>
46 #include <Math/mat3.h>
47 #include <Math/polar3d.hxx>
48 #include <Scenery/scenery.hxx>
49 #include <Time/fg_timer.hxx>
50
51 #include "cockpit.hxx"
52 #include "panel.hxx"
53
54
55 // This is a structure that contains all data related to
56 // cockpit/panel/hud system
57
58 static pCockpit ac_cockpit;
59
60 // The following routines obtain information concerntin the aircraft's
61 // current state and return it to calling instrument display routines.
62 // They should eventually be member functions of the aircraft.
63
64 double get_latitude( void )
65 {
66     return((double)((int)( current_aircraft.fdm_state->get_Latitude() 
67                            * RAD_TO_DEG)) );
68 }
69
70 double get_lat_min( void )
71 {
72     double a, d;
73
74     a = current_aircraft.fdm_state->get_Latitude() * RAD_TO_DEG;        
75     if (a < 0.0) {
76         a = -a;
77     }
78     d = (double) ( (int) a);
79     return( (a - d) * 60.0);
80 }
81
82 double get_longitude( void )
83 {
84     return( (double)((int) (current_aircraft.fdm_state->get_Longitude()
85                             * RAD_TO_DEG)) );
86 }
87
88 double get_long_min( void )
89 {
90     double  a, d;
91     
92     a = current_aircraft.fdm_state->get_Longitude() * RAD_TO_DEG;       
93     if (a < 0.0) {
94         a = -a;
95     }
96     d = (double) ( (int) a);
97     return( (a - d) * 60.0);
98 }
99
100 double get_throttleval( void )
101 {
102     return controls.get_throttle( 0 );     // Hack limiting to one engine
103 }
104
105 double get_aileronval( void )
106 {
107     return controls.get_aileron();
108 }
109
110 double get_elevatorval( void )
111 {
112     return controls.get_elevator();
113 }
114
115 double get_elev_trimval( void )
116 {
117     return controls.get_elevator_trim();
118 }
119
120 double get_rudderval( void )
121 {
122     return controls.get_rudder();
123 }
124
125 double get_speed( void )
126 {
127     return( current_aircraft.fdm_state->get_V_equiv_kts() );
128 }
129
130 double get_aoa( void )
131 {
132     return( current_aircraft.fdm_state->get_Alpha() * RAD_TO_DEG );
133 }
134
135 double get_roll( void )
136 {
137     return( current_aircraft.fdm_state->get_Phi() );
138 }
139
140 double get_pitch( void )
141 {
142     return( current_aircraft.fdm_state->get_Theta() );
143 }
144
145 double get_heading( void )
146 {
147     return( current_aircraft.fdm_state->get_Psi() * RAD_TO_DEG );
148 }
149
150 double get_altitude( void )
151 {
152     if ( current_options.get_units() == fgOPTIONS::FG_UNITS_FEET ) {
153         return current_aircraft.fdm_state->get_Altitude();
154     } else {
155         return current_aircraft.fdm_state->get_Altitude() * FEET_TO_METER;
156     }
157 }
158
159 double get_agl( void )
160 {
161     if ( current_options.get_units() == fgOPTIONS::FG_UNITS_FEET ) {
162         return current_aircraft.fdm_state->get_Altitude()
163             - scenery.cur_elev * METER_TO_FEET;
164     } else {
165         return current_aircraft.fdm_state->get_Altitude() * FEET_TO_METER
166             - scenery.cur_elev;
167     }
168 }
169
170 double get_sideslip( void )
171 {
172     return( current_aircraft.fdm_state->get_Beta() );
173 }
174
175 double get_frame_rate( void )
176 {
177     return (double) general.get_frame_rate();
178 }
179
180 double get_fov( void )
181 {
182     return (current_options.get_fov()); 
183 }
184
185 double get_vfc_ratio( void )
186 {
187     return current_view.get_vfc_ratio();
188 }
189
190 double get_vfc_tris_drawn   ( void )
191 {
192     return current_view.get_tris_rendered();
193 }
194
195 double get_climb_rate( void )
196 {
197     if ( current_options.get_units() == fgOPTIONS::FG_UNITS_FEET ) {
198         return current_aircraft.fdm_state->get_Climb_Rate() * 60.0;
199     } else {
200         return current_aircraft.fdm_state->get_Climb_Rate()
201             * FEET_TO_METER * 60.0;
202     }
203 }
204
205
206 bool fgCockpitInit( fgAIRCRAFT *cur_aircraft )
207 {
208     FG_LOG( FG_COCKPIT, FG_INFO, "Initializing cockpit subsystem" );
209
210     //  cockpit->code = 1;      /* It will be aircraft dependent */
211     //  cockpit->status = 0;
212
213     // If aircraft has HUD specified we will get the specs from its def
214     // file. For now we will depend upon hard coding in hud?
215     
216     // We must insure that the existing instrument link is purged.
217     // This is done by deleting the links in the list.
218     
219     // HI_Head is now a null pointer so we can generate a new list from the
220     // current aircraft.
221
222     fgHUDInit( cur_aircraft );
223     ac_cockpit = new fg_Cockpit();
224     
225     if ( current_options.get_panel_status() ) {
226         new FGPanel;
227     }
228
229     FG_LOG( FG_COCKPIT, FG_INFO,
230             "  Code " << ac_cockpit->code() << " Status " 
231             << ac_cockpit->status() );
232     
233     return true;
234 }
235
236
237 void fgCockpitUpdate( void ) {
238     FG_LOG( FG_COCKPIT, FG_DEBUG,
239             "Cockpit: code " << ac_cockpit->code() << " status " 
240             << ac_cockpit->status() );
241
242     if ( current_options.get_hud_status() ) {
243         // This will check the global hud linked list pointer.
244         // If these is anything to draw it will.
245         fgUpdateHUD();
246     }
247
248     if ( current_options.get_panel_status() && 
249          (fabs( current_view.get_view_offset() ) < 0.2) )
250     {
251         xglViewport( 0, 0, 
252                      current_view.get_winWidth(), 
253                      current_view.get_winHeight() );
254         FGPanel::OurPanel->Update();
255     }
256 }
257
258