1 //*************************************************************************
2 // cockpit.cxx -- routines to draw a cockpit (initial draft)
4 // Written by Michele America, started September 1997.
6 // Copyright (C) 1997 Michele F. America - nomimarketing@mail.telepac.pt
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.
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.
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.
23 // (Log is kept at end of this file)
24 //*************************************************************************/
42 #include <Aircraft/aircraft.hxx>
43 #include <Debug/fg_debug.h>
44 #include <Include/fg_constants.h>
45 #include <Include/general.h>
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>
54 #include "cockpit.hxx"
57 // This is a structure that contains all data related to
58 // cockpit/panel/hud system
60 static pCockpit ac_cockpit;
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.
67 double get_latitude( void )
70 f = current_aircraft.flight;
72 // return( toDM(FG_Latitude * RAD_TO_DEG) );
73 return((double)((int)( FG_Latitude * RAD_TO_DEG)) );
75 double get_lat_min( void )
80 f = current_aircraft.flight;
82 a = FG_Latitude * RAD_TO_DEG;
86 d = (double) ( (int) a);
87 return( (a - d) * 60.0);
91 double get_longitude( void )
94 f = current_aircraft.flight;
96 // return( toDM(FG_Longitude * RAD_TO_DEG) );
97 return((double)((int) (FG_Longitude * RAD_TO_DEG)) );
99 double get_long_min( void )
104 f = current_aircraft.flight;
106 a = FG_Longitude * RAD_TO_DEG;
110 d = (double) ( (int) a);
111 return( (a - d) * 60.0);
114 double get_throttleval( void )
116 fgCONTROLS *pcontrols;
118 pcontrols = current_aircraft.controls;
119 return pcontrols->throttle[0]; // Hack limiting to one engine
122 double get_aileronval( void )
124 fgCONTROLS *pcontrols;
126 pcontrols = current_aircraft.controls;
127 return pcontrols->aileron;
130 double get_elevatorval( void )
132 fgCONTROLS *pcontrols;
134 pcontrols = current_aircraft.controls;
135 return pcontrols->elevator;
138 double get_elev_trimval( void )
140 fgCONTROLS *pcontrols;
142 pcontrols = current_aircraft.controls;
143 return pcontrols->elevator_trim;
146 double get_rudderval( void )
148 fgCONTROLS *pcontrols;
150 pcontrols = current_aircraft.controls;
151 return pcontrols->rudder;
154 double get_speed( void )
158 f = current_aircraft.flight;
159 return( FG_V_equiv_kts ); // Make an explicit function call.
162 double get_aoa( void )
166 f = current_aircraft.flight;
167 return( FG_Gamma_vert_rad * RAD_TO_DEG );
170 double get_roll( void )
174 f = current_aircraft.flight;
178 double get_pitch( void )
182 f = current_aircraft.flight;
186 double get_heading( void )
190 f = current_aircraft.flight;
191 return( FG_Psi * RAD_TO_DEG );
194 double get_altitude( void )
197 // double rough_elev;
199 f = current_aircraft.flight;
200 // rough_elev = mesh_altitude(FG_Longitude * RAD_TO_ARCSEC,
201 // FG_Latitude * RAD_TO_ARCSEC);
203 return( FG_Altitude * FEET_TO_METER /* -rough_elev */ );
206 double get_agl( void )
211 f = current_aircraft.flight;
212 agl = FG_Altitude * FEET_TO_METER - scenery.cur_elev;
217 double get_sideslip( void )
221 f = current_aircraft.flight;
226 double get_frame_rate( void )
232 return pgeneral->frame_rate;
235 double get_fov( void )
237 return (current_options.get_fov());
240 double get_vfc_ratio( void )
244 pview = ¤t_view;
246 return pview->vfc_ratio;
249 double get_vfc_tris_drawn ( void )
251 return current_view.tris_rendered;
254 double get_climb_rate( void )
258 f = current_aircraft.flight;
260 return( FG_Climb_Rate * FEET_TO_METER * 60.0 );
264 bool fgCockpitInit( fgAIRCRAFT *cur_aircraft )
266 fgPrintf( FG_COCKPIT, FG_INFO, "Initializing cockpit subsystem\n");
268 // cockpit->code = 1; /* It will be aircraft dependent */
269 // cockpit->status = 0;
271 // If aircraft has HUD specified we will get the specs from its def
272 // file. For now we will depend upon hard coding in hud?
274 // We must insure that the existing instrument link is purged.
275 // This is done by deleting the links in the list.
277 // HI_Head is now a null pointer so we can generate a new list from the
280 fgHUDInit( cur_aircraft );
281 ac_cockpit = new fg_Cockpit();
283 if ( current_options.get_panel_status() ) {
287 fgPrintf( FG_COCKPIT, FG_INFO,
288 " Code %d Status %d\n",
289 ac_cockpit->code(), ac_cockpit->status() );
295 void fgCockpitUpdate( void ) {
298 pview = ¤t_view;
300 fgPrintf( FG_COCKPIT, FG_DEBUG,
301 "Cockpit: code %d status %d\n",
302 ac_cockpit->code(), ac_cockpit->status() );
304 if ( current_options.get_hud_status() ) {
305 // This will check the global hud linked list pointer.
306 // If these is anything to draw it will.
310 if ( current_options.get_panel_status() &&
311 (fabs(pview->view_offset) < 0.2) ) {
318 // Revision 1.19 1998/10/17 01:33:56 curt
321 // Revision 1.18 1998/10/16 23:27:23 curt
324 // Revision 1.17 1998/09/29 14:56:30 curt
325 // c++-ified comments.
327 // Revision 1.16 1998/09/29 02:01:06 curt
328 // Added a "rate of climb" indicator.
330 // Revision 1.15 1998/08/28 18:14:39 curt
331 // Added new cockpit code from Friedemann Reinhard
332 // <mpt218@faupt212.physik.uni-erlangen.de>
334 // Revision 1.14 1998/08/24 20:05:15 curt
335 // Added a second minimalistic HUD.
336 // Added code to display the number of triangles rendered.
338 // Revision 1.13 1998/08/22 01:19:27 curt
339 // Omit panel code because it's texture loading overruns array bounds.
341 // Revision 1.12 1998/07/13 21:28:00 curt
342 // Converted the aoa scale to a radio altimeter.
344 // Revision 1.11 1998/07/13 21:00:45 curt
345 // Integrated Charlies latest HUD updates.
346 // Wrote access functions for current fgOPTIONS.
348 // Revision 1.10 1998/07/08 14:41:08 curt
349 // Renamed polar3d.h to polar3d.hxx
351 // Revision 1.9 1998/06/27 16:47:53 curt
352 // Incorporated Friedemann Reinhard's <mpt218@faupt212.physik.uni-erlangen.de>
353 // first pass at an isntrument panel.
355 // Revision 1.8 1998/05/17 16:58:12 curt
356 // Added a View Frustum Culling ratio display to the hud.
358 // Revision 1.7 1998/05/16 13:04:13 curt
359 // New updates from Charlie Hotchkiss.
361 // Revision 1.6 1998/05/13 18:27:53 curt
362 // Added an fov to hud display.
364 // Revision 1.5 1998/05/11 18:13:10 curt
365 // Complete C++ rewrite of all cockpit code by Charlie Hotchkiss.
367 // Revision 1.4 1998/05/03 00:46:45 curt
368 // polar.h -> polar3d.h
370 // Revision 1.3 1998/04/30 12:36:02 curt
371 // C++-ifying a couple source files.
373 // Revision 1.2 1998/04/25 22:06:26 curt
374 // Edited cvs log messages in source files ... bad bad bad!
376 // Revision 1.1 1998/04/24 00:45:54 curt
377 // C++-ifing the code a bit.
379 // Revision 1.13 1998/04/18 04:14:01 curt
380 // Moved fg_debug.c to it's own library.
382 // Revision 1.12 1998/04/14 02:23:09 curt
383 // Code reorganizations. Added a Lib/ directory for more general libraries.
385 // Revision 1.11 1998/03/14 00:32:13 curt
386 // Changed a printf() to a fgPrintf().
388 // Revision 1.10 1998/02/07 15:29:33 curt
389 // Incorporated HUD changes and struct/typedef changes from Charlie Hotchkiss
390 // <chotchkiss@namg.us.anritsu.com>
392 // Revision 1.9 1998/02/03 23:20:14 curt
393 // Lots of little tweaks to fix various consistency problems discovered by
394 // Solaris' CC. Fixed a bug in fg_debug.c with how the fgPrintf() wrapper
395 // passed arguments along to the real printf(). Also incorporated HUD changes
396 // by Michele America.
398 // Revision 1.8 1998/01/31 00:43:03 curt
399 // Added MetroWorks patches from Carmen Volpe.
401 // Revision 1.7 1998/01/27 00:47:51 curt
402 // Incorporated Paul Bleisch's <bleisch@chromatic.com> new debug message
403 // system and commandline/config file processing code.
405 // Revision 1.6 1998/01/19 19:27:01 curt
406 // Merged in make system changes from Bob Kuehne <rpk@sgi.com>
407 // This should simplify things tremendously.
409 // Revision 1.5 1998/01/19 18:40:19 curt
410 // Tons of little changes to clean up the code and to remove fatal errors
411 // when building with the c++ compiler.
413 // Revision 1.4 1997/12/30 20:47:34 curt
414 // Integrated new event manager with subsystem initializations.
416 // Revision 1.3 1997/12/15 23:54:33 curt
417 // Add xgl wrappers for debugging.
418 // Generate terrain normals on the fly.
420 // Revision 1.2 1997/12/10 22:37:38 curt
421 // Prepended "fg" on the name of all global structures that didn't have it yet.
422 // i.e. "struct WEATHER {}" became "struct fgWEATHER {}"
424 // Revision 1.1 1997/08/29 18:03:20 curt