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/logstream.hxx>
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.fdm_state;
72 // return( toDM(FG_Latitude * RAD_TO_DEG) );
73 return((double)((int)( f->get_Latitude() * RAD_TO_DEG)) );
76 double get_lat_min( void )
81 f = current_aircraft.fdm_state;
83 a = f->get_Latitude() * RAD_TO_DEG;
87 d = (double) ( (int) a);
88 return( (a - d) * 60.0);
92 double get_longitude( void )
95 f = current_aircraft.fdm_state;
97 // return( toDM(FG_Longitude * RAD_TO_DEG) );
98 return((double)((int) (f->get_Longitude() * RAD_TO_DEG)) );
100 double get_long_min( void )
105 f = current_aircraft.fdm_state;
107 a = f->get_Longitude() * RAD_TO_DEG;
111 d = (double) ( (int) a);
112 return( (a - d) * 60.0);
115 double get_throttleval( void )
117 return controls.get_throttle( 0 ); // Hack limiting to one engine
120 double get_aileronval( void )
122 return controls.get_aileron();
125 double get_elevatorval( void )
127 return controls.get_elevator();
130 double get_elev_trimval( void )
132 return controls.get_elevator_trim();
135 double get_rudderval( void )
137 return controls.get_rudder();
140 double get_speed( void )
144 f = current_aircraft.fdm_state;
145 return( f->get_V_equiv_kts() ); // Make an explicit function call.
148 double get_aoa( void )
152 f = current_aircraft.fdm_state;
153 return( f->get_Gamma_vert_rad() * RAD_TO_DEG );
156 double get_roll( void )
160 f = current_aircraft.fdm_state;
161 return( f->get_Phi() );
164 double get_pitch( void )
168 f = current_aircraft.fdm_state;
169 return( f->get_Theta() );
172 double get_heading( void )
176 f = current_aircraft.fdm_state;
177 return( f->get_Psi() * RAD_TO_DEG );
180 double get_altitude( void )
183 // double rough_elev;
185 f = current_aircraft.fdm_state;
186 // rough_elev = mesh_altitude(f->get_Longitude() * RAD_TO_ARCSEC,
187 // f->get_Latitude() * RAD_TO_ARCSEC);
189 if ( current_options.get_units() == fgOPTIONS::FG_UNITS_FEET ) {
190 return f->get_Altitude();
192 return f->get_Altitude() * FEET_TO_METER;
196 double get_agl( void )
200 f = current_aircraft.fdm_state;
202 if ( current_options.get_units() == fgOPTIONS::FG_UNITS_FEET ) {
203 return f->get_Altitude() - scenery.cur_elev * METER_TO_FEET;
205 return f->get_Altitude() * FEET_TO_METER - scenery.cur_elev;
209 double get_sideslip( void )
213 f = current_aircraft.fdm_state;
215 return( f->get_Beta() );
218 double get_frame_rate( void )
224 return pgeneral->frame_rate;
227 double get_fov( void )
229 return (current_options.get_fov());
232 double get_vfc_ratio( void )
236 pview = ¤t_view;
238 return pview->vfc_ratio;
241 double get_vfc_tris_drawn ( void )
243 return current_view.tris_rendered;
246 double get_climb_rate( void )
250 f = current_aircraft.fdm_state;
252 if ( current_options.get_units() == fgOPTIONS::FG_UNITS_FEET ) {
253 return f->get_Climb_Rate() * 60.0;
255 return f->get_Climb_Rate() * FEET_TO_METER * 60.0;
260 bool fgCockpitInit( fgAIRCRAFT *cur_aircraft )
262 FG_LOG( FG_COCKPIT, FG_INFO, "Initializing cockpit subsystem" );
264 // cockpit->code = 1; /* It will be aircraft dependent */
265 // cockpit->status = 0;
267 // If aircraft has HUD specified we will get the specs from its def
268 // file. For now we will depend upon hard coding in hud?
270 // We must insure that the existing instrument link is purged.
271 // This is done by deleting the links in the list.
273 // HI_Head is now a null pointer so we can generate a new list from the
276 fgHUDInit( cur_aircraft );
277 ac_cockpit = new fg_Cockpit();
279 if ( current_options.get_panel_status() ) {
283 FG_LOG( FG_COCKPIT, FG_INFO,
284 " Code " << ac_cockpit->code() << " Status "
285 << ac_cockpit->status() );
291 void fgCockpitUpdate( void ) {
294 pview = ¤t_view;
296 FG_LOG( FG_COCKPIT, FG_DEBUG,
297 "Cockpit: code " << ac_cockpit->code() << " status "
298 << ac_cockpit->status() );
300 if ( current_options.get_hud_status() ) {
301 // This will check the global hud linked list pointer.
302 // If these is anything to draw it will.
306 if ( current_options.get_panel_status() &&
307 (fabs(pview->view_offset) < 0.2) ) {
308 xglViewport(0, 0, pview->winWidth, pview->winHeight);
315 // Revision 1.25 1998/12/05 15:54:07 curt
316 // Renamed class fgFLIGHT to class FGState as per request by JSB.
318 // Revision 1.24 1998/12/03 01:16:00 curt
319 // Converted fgFLIGHT to a class.
321 // Revision 1.23 1998/11/09 23:38:50 curt
322 // Panel updates from Friedemann.
324 // Revision 1.22 1998/11/06 21:17:45 curt
325 // Converted to new logstream debugging facility. This allows release
326 // builds with no messages at all (and no performance impact) by using
327 // the -DFG_NDEBUG flag.
329 // Revision 1.21 1998/11/02 23:04:02 curt
330 // HUD units now display in feet by default with meters being a command line
333 // Revision 1.20 1998/10/25 14:08:40 curt
334 // Turned "struct fgCONTROLS" into a class, with inlined accessor functions.
336 // Revision 1.19 1998/10/17 01:33:56 curt
339 // Revision 1.18 1998/10/16 23:27:23 curt
342 // Revision 1.17 1998/09/29 14:56:30 curt
343 // c++-ified comments.
345 // Revision 1.16 1998/09/29 02:01:06 curt
346 // Added a "rate of climb" indicator.
348 // Revision 1.15 1998/08/28 18:14:39 curt
349 // Added new cockpit code from Friedemann Reinhard
350 // <mpt218@faupt212.physik.uni-erlangen.de>
352 // Revision 1.14 1998/08/24 20:05:15 curt
353 // Added a second minimalistic HUD.
354 // Added code to display the number of triangles rendered.
356 // Revision 1.13 1998/08/22 01:19:27 curt
357 // Omit panel code because it's texture loading overruns array bounds.
359 // Revision 1.12 1998/07/13 21:28:00 curt
360 // Converted the aoa scale to a radio altimeter.
362 // Revision 1.11 1998/07/13 21:00:45 curt
363 // Integrated Charlies latest HUD updates.
364 // Wrote access functions for current fgOPTIONS.
366 // Revision 1.10 1998/07/08 14:41:08 curt
367 // Renamed polar3d.h to polar3d.hxx
369 // Revision 1.9 1998/06/27 16:47:53 curt
370 // Incorporated Friedemann Reinhard's <mpt218@faupt212.physik.uni-erlangen.de>
371 // first pass at an isntrument panel.
373 // Revision 1.8 1998/05/17 16:58:12 curt
374 // Added a View Frustum Culling ratio display to the hud.
376 // Revision 1.7 1998/05/16 13:04:13 curt
377 // New updates from Charlie Hotchkiss.
379 // Revision 1.6 1998/05/13 18:27:53 curt
380 // Added an fov to hud display.
382 // Revision 1.5 1998/05/11 18:13:10 curt
383 // Complete C++ rewrite of all cockpit code by Charlie Hotchkiss.
385 // Revision 1.4 1998/05/03 00:46:45 curt
386 // polar.h -> polar3d.h
388 // Revision 1.3 1998/04/30 12:36:02 curt
389 // C++-ifying a couple source files.
391 // Revision 1.2 1998/04/25 22:06:26 curt
392 // Edited cvs log messages in source files ... bad bad bad!
394 // Revision 1.1 1998/04/24 00:45:54 curt
395 // C++-ifing the code a bit.
397 // Revision 1.13 1998/04/18 04:14:01 curt
398 // Moved fg_debug.c to it's own library.
400 // Revision 1.12 1998/04/14 02:23:09 curt
401 // Code reorganizations. Added a Lib/ directory for more general libraries.
403 // Revision 1.11 1998/03/14 00:32:13 curt
404 // Changed a printf() to a fgPrintf().
406 // Revision 1.10 1998/02/07 15:29:33 curt
407 // Incorporated HUD changes and struct/typedef changes from Charlie Hotchkiss
408 // <chotchkiss@namg.us.anritsu.com>
410 // Revision 1.9 1998/02/03 23:20:14 curt
411 // Lots of little tweaks to fix various consistency problems discovered by
412 // Solaris' CC. Fixed a bug in fg_debug.c with how the fgPrintf() wrapper
413 // passed arguments along to the real printf(). Also incorporated HUD changes
414 // by Michele America.
416 // Revision 1.8 1998/01/31 00:43:03 curt
417 // Added MetroWorks patches from Carmen Volpe.
419 // Revision 1.7 1998/01/27 00:47:51 curt
420 // Incorporated Paul Bleisch's <bleisch@chromatic.com> new debug message
421 // system and commandline/config file processing code.
423 // Revision 1.6 1998/01/19 19:27:01 curt
424 // Merged in make system changes from Bob Kuehne <rpk@sgi.com>
425 // This should simplify things tremendously.
427 // Revision 1.5 1998/01/19 18:40:19 curt
428 // Tons of little changes to clean up the code and to remove fatal errors
429 // when building with the c++ compiler.
431 // Revision 1.4 1997/12/30 20:47:34 curt
432 // Integrated new event manager with subsystem initializations.
434 // Revision 1.3 1997/12/15 23:54:33 curt
435 // Add xgl wrappers for debugging.
436 // Generate terrain normals on the fly.
438 // Revision 1.2 1997/12/10 22:37:38 curt
439 // Prepended "fg" on the name of all global structures that didn't have it yet.
440 // i.e. "struct WEATHER {}" became "struct fgWEATHER {}"
442 // Revision 1.1 1997/08/29 18:03:20 curt