]> git.mxchange.org Git - flightgear.git/blob - Cockpit/cockpit.cxx
Modifications to incorporate Jon S. Berndts flight model code.
[flightgear.git] / Cockpit / cockpit.cxx
1 //*************************************************************************
2 // cockpit.cxx -- routines to draw a cockpit (initial draft)
3 //
4 // Written by Michele America, started September 1997.
5 //
6 // Copyright (C) 1997  Michele F. America  - nomimarketing@mail.telepac.pt
7 //
8 // This program is free software; you can redistribute it and/or
9 // modify it under the terms of the GNU General Public License as
10 // published by the Free Software Foundation; either version 2 of the
11 // License, or (at your option) any later version.
12 //
13 // This program is distributed in the hope that it will be useful, but
14 // WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16 // General Public License for more details.
17 //
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the Free Software
20 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 //
22 // $Id$
23 // (Log is kept at end of this file)
24 //*************************************************************************/
25
26
27 #ifdef HAVE_CONFIG_H
28 #  include <config.h>
29 #endif
30
31 #ifdef HAVE_WINDOWS_H          
32 #  include <windows.h>
33 #endif
34
35 #include <GL/glut.h>
36 #include <XGL/xgl.h>
37
38 #include <stdlib.h>
39 #include <stdio.h>
40 #include <string.h>
41
42 #include <Aircraft/aircraft.hxx>
43 #include <Debug/logstream.hxx>
44 #include <Include/fg_constants.h>
45 #include <Include/general.hxx>
46 #include <Main/options.hxx>
47 #include <Main/views.hxx>
48 #include <Math/fg_random.h>
49 #include <Math/mat3.h>
50 #include <Math/polar3d.hxx>
51 #include <Scenery/scenery.hxx>
52 #include <Time/fg_timer.hxx>
53
54 #include "cockpit.hxx"
55
56
57 // This is a structure that contains all data related to
58 // cockpit/panel/hud system
59
60 static pCockpit ac_cockpit;
61
62 // The following routines obtain information concerntin the aircraft's
63 // current state and return it to calling instrument display routines.
64 // They should eventually be member functions of the aircraft.
65 //
66
67 double get_latitude( void )
68 {
69     return((double)((int)( current_aircraft.fdm_state->get_Latitude() 
70                            * RAD_TO_DEG)) );
71 }
72
73 double get_lat_min( void )
74 {
75     double a, d;
76
77     a = current_aircraft.fdm_state->get_Latitude() * RAD_TO_DEG;        
78     if (a < 0.0) {
79         a = -a;
80     }
81     d = (double) ( (int) a);
82     return( (a - d) * 60.0);
83 }
84
85 double get_longitude( void )
86 {
87     return( (double)((int) (current_aircraft.fdm_state->get_Longitude()
88                             * RAD_TO_DEG)) );
89 }
90
91 double get_long_min( void )
92 {
93     double  a, d;
94     
95     a = current_aircraft.fdm_state->get_Longitude() * RAD_TO_DEG;       
96     if (a < 0.0) {
97         a = -a;
98     }
99     d = (double) ( (int) a);
100     return( (a - d) * 60.0);
101 }
102
103 double get_throttleval( void )
104 {
105     return controls.get_throttle( 0 );     // Hack limiting to one engine
106 }
107
108 double get_aileronval( void )
109 {
110     return controls.get_aileron();
111 }
112
113 double get_elevatorval( void )
114 {
115     return controls.get_elevator();
116 }
117
118 double get_elev_trimval( void )
119 {
120     return controls.get_elevator_trim();
121 }
122
123 double get_rudderval( void )
124 {
125     return controls.get_rudder();
126 }
127
128 double get_speed( void )
129 {
130     return( current_aircraft.fdm_state->get_V_equiv_kts() );
131 }
132
133 double get_aoa( void )
134 {
135     return( current_aircraft.fdm_state->get_Alpha() * RAD_TO_DEG );
136 }
137
138 double get_roll( void )
139 {
140     return( current_aircraft.fdm_state->get_Phi() );
141 }
142
143 double get_pitch( void )
144 {
145     return( current_aircraft.fdm_state->get_Theta() );
146 }
147
148 double get_heading( void )
149 {
150     return( current_aircraft.fdm_state->get_Psi() * RAD_TO_DEG );
151 }
152
153 double get_altitude( void )
154 {
155     if ( current_options.get_units() == fgOPTIONS::FG_UNITS_FEET ) {
156         return current_aircraft.fdm_state->get_Altitude();
157     } else {
158         return current_aircraft.fdm_state->get_Altitude() * FEET_TO_METER;
159     }
160 }
161
162 double get_agl( void )
163 {
164     if ( current_options.get_units() == fgOPTIONS::FG_UNITS_FEET ) {
165         return current_aircraft.fdm_state->get_Altitude()
166             - scenery.cur_elev * METER_TO_FEET;
167     } else {
168         return current_aircraft.fdm_state->get_Altitude() * FEET_TO_METER
169             - scenery.cur_elev;
170     }
171 }
172
173 double get_sideslip( void )
174 {
175     return( current_aircraft.fdm_state->get_Beta() );
176 }
177
178 double get_frame_rate( void )
179 {
180     return (double) general.get_frame_rate();
181 }
182
183 double get_fov( void )
184 {
185     return (current_options.get_fov()); 
186 }
187
188 double get_vfc_ratio( void )
189 {
190     return current_view.get_vfc_ratio();
191 }
192
193 double get_vfc_tris_drawn   ( void )
194 {
195     return current_view.get_tris_rendered();
196 }
197
198 double get_climb_rate( void )
199 {
200     if ( current_options.get_units() == fgOPTIONS::FG_UNITS_FEET ) {
201         return current_aircraft.fdm_state->get_Climb_Rate() * 60.0;
202     } else {
203         return current_aircraft.fdm_state->get_Climb_Rate()
204             * FEET_TO_METER * 60.0;
205     }
206 }
207
208
209 bool fgCockpitInit( fgAIRCRAFT *cur_aircraft )
210 {
211     FG_LOG( FG_COCKPIT, FG_INFO, "Initializing cockpit subsystem" );
212
213     //  cockpit->code = 1;      /* It will be aircraft dependent */
214     //  cockpit->status = 0;
215
216     // If aircraft has HUD specified we will get the specs from its def
217     // file. For now we will depend upon hard coding in hud?
218     
219     // We must insure that the existing instrument link is purged.
220     // This is done by deleting the links in the list.
221     
222     // HI_Head is now a null pointer so we can generate a new list from the
223     // current aircraft.
224
225     fgHUDInit( cur_aircraft );
226     ac_cockpit = new fg_Cockpit();
227     
228     if ( current_options.get_panel_status() ) {
229         fgPanelInit();
230     }
231
232     FG_LOG( FG_COCKPIT, FG_INFO,
233             "  Code " << ac_cockpit->code() << " Status " 
234             << ac_cockpit->status() );
235     
236     return true;
237 }
238
239
240 void fgCockpitUpdate( void ) {
241     FG_LOG( FG_COCKPIT, FG_DEBUG,
242             "Cockpit: code " << ac_cockpit->code() << " status " 
243             << ac_cockpit->status() );
244
245     if ( current_options.get_hud_status() ) {
246         // This will check the global hud linked list pointer.
247         // If these is anything to draw it will.
248         fgUpdateHUD();
249     }
250
251     if ( current_options.get_panel_status() && 
252          (fabs( current_view.get_view_offset() ) < 0.2) )
253     {
254         xglViewport( 0, 0, 
255                      current_view.get_winWidth(), 
256                      current_view.get_winHeight() );
257         fgPanelUpdate();
258     }
259 }
260
261
262 // $Log$
263 // Revision 1.30  1999/02/05 21:28:57  curt
264 // Modifications to incorporate Jon S. Berndts flight model code.
265 //
266 // Revision 1.29  1999/01/08 19:27:34  curt
267 // Fixed AOA reading on HUD.
268 // Continued work on time jitter compensation.
269 //
270 // Revision 1.28  1999/01/07 20:24:17  curt
271 // Update fgGENERAL to FGGeneral.
272 //
273 // Revision 1.27  1998/12/18 23:35:09  curt
274 // Converted to a simpler frame rate counting method.
275 //
276 // Revision 1.26  1998/12/09 18:50:19  curt
277 // Converted "class fgVIEW" to "class FGView" and updated to make data
278 // members private and make required accessor functions.
279 //
280 // Revision 1.25  1998/12/05 15:54:07  curt
281 // Renamed class fgFLIGHT to class FGState as per request by JSB.
282 //
283 // Revision 1.24  1998/12/03 01:16:00  curt
284 // Converted fgFLIGHT to a class.
285 //
286 // Revision 1.23  1998/11/09 23:38:50  curt
287 // Panel updates from Friedemann.
288 //
289 // Revision 1.22  1998/11/06 21:17:45  curt
290 // Converted to new logstream debugging facility.  This allows release
291 // builds with no messages at all (and no performance impact) by using
292 // the -DFG_NDEBUG flag.
293 //
294 // Revision 1.21  1998/11/02 23:04:02  curt
295 // HUD units now display in feet by default with meters being a command line
296 // option.
297 //
298 // Revision 1.20  1998/10/25 14:08:40  curt
299 // Turned "struct fgCONTROLS" into a class, with inlined accessor functions.
300 //
301 // Revision 1.19  1998/10/17 01:33:56  curt
302 // C++ ifying ...
303 //
304 // Revision 1.18  1998/10/16 23:27:23  curt
305 // C++-ifying.
306 //
307 // Revision 1.17  1998/09/29 14:56:30  curt
308 // c++-ified comments.
309 //
310 // Revision 1.16  1998/09/29 02:01:06  curt
311 // Added a "rate of climb" indicator.
312 //
313 // Revision 1.15  1998/08/28 18:14:39  curt
314 // Added new cockpit code from Friedemann Reinhard
315 // <mpt218@faupt212.physik.uni-erlangen.de>
316 //
317 // Revision 1.14  1998/08/24 20:05:15  curt
318 // Added a second minimalistic HUD.
319 // Added code to display the number of triangles rendered.
320 //
321 // Revision 1.13  1998/08/22 01:19:27  curt
322 // Omit panel code because it's texture loading overruns array bounds.
323 //
324 // Revision 1.12  1998/07/13 21:28:00  curt
325 // Converted the aoa scale to a radio altimeter.
326 //
327 // Revision 1.11  1998/07/13 21:00:45  curt
328 // Integrated Charlies latest HUD updates.
329 // Wrote access functions for current fgOPTIONS.
330 //
331 // Revision 1.10  1998/07/08 14:41:08  curt
332 // Renamed polar3d.h to polar3d.hxx
333 //
334 // Revision 1.9  1998/06/27 16:47:53  curt
335 // Incorporated Friedemann Reinhard's <mpt218@faupt212.physik.uni-erlangen.de>
336 // first pass at an isntrument panel.
337 //
338 // Revision 1.8  1998/05/17 16:58:12  curt
339 // Added a View Frustum Culling ratio display to the hud.
340 //
341 // Revision 1.7  1998/05/16 13:04:13  curt
342 // New updates from Charlie Hotchkiss.
343 //
344 // Revision 1.6  1998/05/13 18:27:53  curt
345 // Added an fov to hud display.
346 //
347 // Revision 1.5  1998/05/11 18:13:10  curt
348 // Complete C++ rewrite of all cockpit code by Charlie Hotchkiss.
349 //
350 // Revision 1.4  1998/05/03 00:46:45  curt
351 // polar.h -> polar3d.h
352 //
353 // Revision 1.3  1998/04/30 12:36:02  curt
354 // C++-ifying a couple source files.
355 //
356 // Revision 1.2  1998/04/25 22:06:26  curt
357 // Edited cvs log messages in source files ... bad bad bad!
358 //
359 // Revision 1.1  1998/04/24 00:45:54  curt
360 // C++-ifing the code a bit.
361 //
362 // Revision 1.13  1998/04/18 04:14:01  curt
363 // Moved fg_debug.c to it's own library.
364 //
365 // Revision 1.12  1998/04/14 02:23:09  curt
366 // Code reorganizations.  Added a Lib/ directory for more general libraries.
367 //
368 // Revision 1.11  1998/03/14 00:32:13  curt
369 // Changed a printf() to a fgPrintf().
370 //
371 // Revision 1.10  1998/02/07 15:29:33  curt
372 // Incorporated HUD changes and struct/typedef changes from Charlie Hotchkiss
373 // <chotchkiss@namg.us.anritsu.com>
374 //
375 // Revision 1.9  1998/02/03 23:20:14  curt
376 // Lots of little tweaks to fix various consistency problems discovered by
377 // Solaris' CC.  Fixed a bug in fg_debug.c with how the fgPrintf() wrapper
378 // passed arguments along to the real printf().  Also incorporated HUD changes
379 // by Michele America.
380 //
381 // Revision 1.8  1998/01/31 00:43:03  curt
382 // Added MetroWorks patches from Carmen Volpe.
383 //
384 // Revision 1.7  1998/01/27 00:47:51  curt
385 // Incorporated Paul Bleisch's <bleisch@chromatic.com> new debug message
386 // system and commandline/config file processing code.
387 //
388 // Revision 1.6  1998/01/19 19:27:01  curt
389 // Merged in make system changes from Bob Kuehne <rpk@sgi.com>
390 // This should simplify things tremendously.
391 //
392 // Revision 1.5  1998/01/19 18:40:19  curt
393 // Tons of little changes to clean up the code and to remove fatal errors
394 // when building with the c++ compiler.
395 //
396 // Revision 1.4  1997/12/30 20:47:34  curt
397 // Integrated new event manager with subsystem initializations.
398 //
399 // Revision 1.3  1997/12/15 23:54:33  curt
400 // Add xgl wrappers for debugging.
401 // Generate terrain normals on the fly.
402 //
403 // Revision 1.2  1997/12/10 22:37:38  curt
404 // Prepended "fg" on the name of all global structures that didn't have it yet.
405 // i.e. "struct WEATHER {}" became "struct fgWEATHER {}"
406 //
407 // Revision 1.1  1997/08/29 18:03:20  curt
408 // Initial revision.
409 //
410