1 // cockpit.cxx -- routines to draw a cockpit (initial draft)
3 // Written by Michele America, started September 1997.
5 // Copyright (C) 1997 Michele F. America - nomimarketing@mail.telepac.pt
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.
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.
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
28 #include <simgear/compiler.h>
34 #include <simgear/constants.h>
35 #include <simgear/debug/logstream.hxx>
36 #include <simgear/props/props.hxx>
37 #include <simgear/timing/sg_time.hxx>
39 #include <Aircraft/aircraft.hxx>
40 #include <Include/general.hxx>
42 #include <FDM/SP/ADA.hxx>
44 #include <Main/globals.hxx>
45 #include <Main/fg_props.hxx>
46 #include <Main/viewmgr.hxx>
47 #include <Main/viewer.hxx>
48 #include <Scenery/scenery.hxx>
51 #include "cockpit.hxx"
55 // The following routines obtain information concerntin the aircraft's
56 // current state and return it to calling instrument display routines.
57 // They should eventually be member functions of the aircraft.
60 float get_latitude( void )
62 return current_aircraft.fdm_state->get_Latitude() * SGD_RADIANS_TO_DEGREES;
65 float get_lat_min( void )
69 a = current_aircraft.fdm_state->get_Latitude() * SGD_RADIANS_TO_DEGREES;
73 d = (double) ( (int) a);
74 float lat_min = (a - d) * 60.0;
80 float get_longitude( void )
82 return current_aircraft.fdm_state->get_Longitude() * SGD_RADIANS_TO_DEGREES;
87 get_formated_gmt_time( void )
90 const struct tm *p = globals->get_time_params()->getGmt();
91 sprintf( buf, "%d/%d/%4d %d:%02d:%02d",
92 p->tm_mon+1, p->tm_mday, 1900 + p->tm_year,
93 p->tm_hour, p->tm_min, p->tm_sec);
99 float get_long_min( void )
102 a = current_aircraft.fdm_state->get_Longitude() * SGD_RADIANS_TO_DEGREES;
106 d = (double) ( (int) a);
107 float lon_min = (a - d) * 60.0;
112 float get_throttleval( void )
114 // Hack limiting to one engine
115 return globals->get_controls()->get_throttle( 0 );
118 float get_aileronval( void )
120 return globals->get_controls()->get_aileron();
123 float get_elevatorval( void )
125 return globals->get_controls()->get_elevator();
128 float get_elev_trimval( void )
130 return globals->get_controls()->get_elevator_trim();
133 float get_rudderval( void )
135 return globals->get_controls()->get_rudder();
138 float get_speed( void )
140 static const SGPropertyNode * speedup_node = fgGetNode("/sim/speed-up");
142 float speed = current_aircraft.fdm_state->get_V_calibrated_kts()
143 * speedup_node->getIntValue();
150 return current_aircraft.fdm_state->get_Mach_number();
153 float get_aoa( void )
155 return current_aircraft.fdm_state->get_Alpha() * SGD_RADIANS_TO_DEGREES;
158 float get_roll( void )
160 return current_aircraft.fdm_state->get_Phi();
163 float get_pitch( void )
165 return current_aircraft.fdm_state->get_Theta();
168 float get_heading( void )
170 return current_aircraft.fdm_state->get_Psi() * SGD_RADIANS_TO_DEGREES;
173 float get_altitude( void )
175 static const SGPropertyNode *startup_units_node
176 = fgGetNode("/sim/startup/units");
180 if ( !strcmp(startup_units_node->getStringValue(), "feet") ) {
181 altitude = current_aircraft.fdm_state->get_Altitude();
183 altitude = (current_aircraft.fdm_state->get_Altitude()
190 float get_agl( void )
192 static const SGPropertyNode *startup_units_node
193 = fgGetNode("/sim/startup/units");
197 if ( !strcmp(startup_units_node->getStringValue(), "feet") ) {
198 agl = (current_aircraft.fdm_state->get_Altitude()
199 - current_aircraft.fdm_state->get_Runway_altitude());
201 agl = (current_aircraft.fdm_state->get_Altitude()
202 - current_aircraft.fdm_state->get_Runway_altitude()) * SG_FEET_TO_METER;
208 float get_sideslip( void )
210 return current_aircraft.fdm_state->get_Beta();
213 float get_frame_rate( void )
215 return general.get_frame_rate();
218 float get_fov( void )
220 return globals->get_current_view()->get_fov();
223 float get_vfc_ratio( void )
225 // float vfc = current_view.get_vfc_ratio();
230 float get_vfc_tris_drawn ( void )
232 // float rendered = current_view.get_tris_rendered();
233 // return (rendered);
237 float get_vfc_tris_culled ( void )
239 // float culled = current_view.get_tris_culled();
244 float get_climb_rate( void )
246 static const SGPropertyNode *startup_units_node
247 = fgGetNode("/sim/startup/units");
250 if ( !strcmp(startup_units_node->getStringValue(), "feet") ) {
251 climb_rate = current_aircraft.fdm_state->get_Climb_Rate() * 60.0;
253 climb_rate = current_aircraft.fdm_state->get_Climb_Rate() * SG_FEET_TO_METER * 60.0;
260 float get_view_direction( void )
262 double view_off = SGD_2PI - globals->get_current_view()->getHeadingOffset_deg() * SGD_DEGREES_TO_RADIANS;
263 double view = ( current_aircraft.fdm_state->get_Psi() + view_off)
264 * SGD_RADIANS_TO_DEGREES;
274 // Added by Markus Hof on 5. Jan 2004
275 float get_dme( void )
277 static const SGPropertyNode * dme_node =
278 fgGetNode("/instrumentation/dme/indicated-distance-nm");
280 return dme_node->getFloatValue();
283 // $$$ begin - added, VS Renganathan 13 Oct 2K
284 // #ifdef FIGHTER_HUD
285 float get_Vx ( void )
287 // Curt dont comment this and return zero. - Ranga
288 // Please remove comments from get_V_..() function in flight.hxx
289 float Vxx = current_aircraft.fdm_state->get_V_north_rel_ground();
293 float get_Vy ( void )
295 // Curt dont comment this and return zero. - Ranga
296 // Please remove comments from get_V_..() function in flight.hxx
297 float Vyy = current_aircraft.fdm_state->get_V_east_rel_ground();
301 float get_Vz ( void )
303 // Curt dont comment this and return zero. - Ranga
304 // Please remove comments from get_V_..() function in flight.hxx
305 float Vzz = current_aircraft.fdm_state->get_V_down_rel_ground();
309 float get_Ax ( void )
311 float Ax = current_aircraft.fdm_state->get_V_dot_north();
315 float get_Ay ( void )
317 float Ay = current_aircraft.fdm_state->get_V_dot_east();
321 float get_Az ( void )
323 float Az = current_aircraft.fdm_state->get_V_dot_down();
327 float get_anzg ( void )
329 float anzg = current_aircraft.fdm_state->get_N_Z_cg();
336 FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
337 return fdm->get_iaux(1);
342 FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
343 return fdm->get_iaux(2);
348 FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
349 return fdm->get_iaux(3);
354 FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
355 return fdm->get_iaux(4);
360 FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
361 return fdm->get_iaux(5);
366 FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
367 return fdm->get_iaux(6);
372 FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
373 return fdm->get_iaux(7);
378 FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
379 return fdm->get_iaux(8);
384 FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
385 return fdm->get_iaux(9);
388 int get_iaux10 (void)
390 FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
391 return fdm->get_iaux(10);
394 int get_iaux11 (void)
396 FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
397 return fdm->get_iaux(11);
400 int get_iaux12 (void)
402 FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
403 return fdm->get_iaux(12);
406 float get_aux1 (void)
408 FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
409 return fdm->get_daux(1);
412 float get_aux2 (void)
414 FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
415 return fdm->get_daux(2);
418 float get_aux3 (void)
420 FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
421 return fdm->get_daux(3);
424 float get_aux4 (void)
426 FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
427 return fdm->get_daux(4);
430 float get_aux5 (void)
432 FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
433 return fdm->get_daux(5);
436 float get_aux6 (void)
438 FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
439 return fdm->get_daux(6);
442 float get_aux7 (void)
444 FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
445 return fdm->get_daux(7);
448 float get_aux8 (void)
450 FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
451 return fdm->get_daux(8);
454 float get_aux9 (void)
456 FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
457 return fdm->get_faux(1);
460 float get_aux10 (void)
462 FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
463 return fdm->get_faux(2);
466 float get_aux11 (void)
468 FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
469 return fdm->get_faux(3);
472 float get_aux12 (void)
474 FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
475 return fdm->get_faux(4);
478 float get_aux13 (void)
480 FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
481 return fdm->get_faux(5);
484 float get_aux14 (void)
486 FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
487 return fdm->get_faux(6);
490 float get_aux15 (void)
492 FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
493 return fdm->get_faux(7);
496 float get_aux16 (void)
498 FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
499 return fdm->get_faux(8);
502 float get_aux17 (void)
504 FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
505 return fdm->get_faux(9);
508 float get_aux18 (void)
510 FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
511 return fdm->get_faux(10);
516 bool fgCockpitInit( fgAIRCRAFT *cur_aircraft )
518 SG_LOG( SG_COCKPIT, SG_INFO, "Initializing cockpit subsystem" );
520 // cockpit->code = 1; /* It will be aircraft dependent */
521 // cockpit->status = 0;
523 // If aircraft has HUD specified we will get the specs from its def
524 // file. For now we will depend upon hard coding in hud?
526 // We must insure that the existing instrument link is purged.
527 // This is done by deleting the links in the list.
529 // HI_Head is now a null pointer so we can generate a new list from the
532 fgHUDInit( cur_aircraft );
537 void fgCockpitUpdate( osg::State* state ) {
539 static const SGPropertyNode * xsize_node = fgGetNode("/sim/startup/xsize");
540 static const SGPropertyNode * ysize_node = fgGetNode("/sim/startup/ysize");
541 static const SGPropertyNode * hud_visibility_node
542 = fgGetNode("/sim/hud/visibility");
544 int iwidth = xsize_node->getIntValue();
545 int iheight = ysize_node->getIntValue();
547 // FIXME: inefficient
548 if ( hud_visibility_node->getBoolValue() ) {
549 // This will check the global hud linked list pointer.
550 // If there is anything to draw it will.
551 fgUpdateHUD( state );
554 glViewport( 0, 0, iwidth, iheight );
566 { "aileronval", get_aileronval },
567 { "altitude", get_altitude },
568 { "anzg", get_anzg },
571 { "climb", get_climb_rate },
572 { "elevatortrimval", get_elev_trimval },
573 { "elevatorval", get_elevatorval },
575 { "framerate", get_frame_rate },
576 { "heading", get_heading },
577 { "latitude", get_latitude },
578 { "longitude", get_longitude },
579 { "mach", get_mach },
580 { "rudderval", get_rudderval },
581 { "speed", get_speed },
582 { "throttleval", get_throttleval },
583 { "view_direction", get_view_direction },
584 { "vfc_tris_culled", get_vfc_tris_culled },
585 { "vfc_tris_drawn", get_vfc_tris_drawn },
587 { "aux1", get_aux1 },
588 { "aux2", get_aux2 },
589 { "aux3", get_aux3 },
590 { "aux4", get_aux4 },
591 { "aux5", get_aux5 },
592 { "aux6", get_aux6 },
593 { "aux7", get_aux7 },
594 { "aux8", get_aux8 },
595 { "aux9", get_aux9 },
596 { "aux10", get_aux10 },
597 { "aux11", get_aux11 },
598 { "aux12", get_aux12 },
599 { "aux13", get_aux13 },
600 { "aux14", get_aux14 },
601 { "aux15", get_aux15 },
602 { "aux16", get_aux16 },
603 { "aux17", get_aux17 },
604 { "aux18", get_aux18 },
610 FLTFNPTR get_func(const char *name)
612 for (int i = 0; fn_table[i].name; i++)
613 if (!strcmp(fn_table[i].name, name))
614 return fn_table[i].func;