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