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.
32 #include <simgear/compiler.h>
40 #include <simgear/constants.h>
41 #include <simgear/debug/logstream.hxx>
42 #include <simgear/math/polar3d.hxx>
43 #include <simgear/props/props.hxx>
44 #include <simgear/timing/sg_time.hxx>
46 #include <Aircraft/aircraft.hxx>
47 #include <Include/general.hxx>
49 #include <FDM/SP/ADA.hxx>
51 #include <Main/globals.hxx>
52 #include <Main/fg_props.hxx>
53 #include <Main/viewmgr.hxx>
54 #include <Scenery/scenery.hxx>
55 #include <Time/fg_timer.hxx>
58 #include "cockpit.hxx"
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 float get_latitude( void )
69 return current_aircraft.fdm_state->get_Latitude() * SGD_RADIANS_TO_DEGREES;
72 float get_lat_min( void )
76 a = current_aircraft.fdm_state->get_Latitude() * SGD_RADIANS_TO_DEGREES;
80 d = (double) ( (int) a);
81 float lat_min = (a - d) * 60.0;
87 float get_longitude( void )
89 return current_aircraft.fdm_state->get_Longitude() * SGD_RADIANS_TO_DEGREES;
94 get_formated_gmt_time( void )
97 const struct tm *p = globals->get_time_params()->getGmt();
98 sprintf( buf, "%d/%d/%4d %d:%02d:%02d",
99 p->tm_mon+1, p->tm_mday, 1900 + p->tm_year,
100 p->tm_hour, p->tm_min, p->tm_sec);
106 float get_long_min( void )
109 a = current_aircraft.fdm_state->get_Longitude() * SGD_RADIANS_TO_DEGREES;
113 d = (double) ( (int) a);
114 float lon_min = (a - d) * 60.0;
119 float get_throttleval( void )
121 // Hack limiting to one engine
122 return globals->get_controls()->get_throttle( 0 );
125 float get_aileronval( void )
127 return globals->get_controls()->get_aileron();
130 float get_elevatorval( void )
132 return globals->get_controls()->get_elevator();
135 float get_elev_trimval( void )
137 return globals->get_controls()->get_elevator_trim();
140 float get_rudderval( void )
142 return globals->get_controls()->get_rudder();
145 float get_speed( void )
147 static const SGPropertyNode * speedup_node = fgGetNode("/sim/speed-up");
149 float speed = current_aircraft.fdm_state->get_V_calibrated_kts()
150 * speedup_node->getIntValue();
157 return current_aircraft.fdm_state->get_Mach_number();
160 float get_aoa( void )
162 return current_aircraft.fdm_state->get_Alpha() * SGD_RADIANS_TO_DEGREES;
165 float get_roll( void )
167 return current_aircraft.fdm_state->get_Phi();
170 float get_pitch( void )
172 return current_aircraft.fdm_state->get_Theta();
175 float get_heading( void )
177 return current_aircraft.fdm_state->get_Psi() * SGD_RADIANS_TO_DEGREES;
180 float get_altitude( void )
182 static const SGPropertyNode *startup_units_node
183 = fgGetNode("/sim/startup/units");
187 if ( !strcmp(startup_units_node->getStringValue(), "feet") ) {
188 altitude = current_aircraft.fdm_state->get_Altitude();
190 altitude = (current_aircraft.fdm_state->get_Altitude()
197 float get_agl( void )
199 static const SGPropertyNode *startup_units_node
200 = fgGetNode("/sim/startup/units");
204 if ( !strcmp(startup_units_node->getStringValue(), "feet") ) {
205 agl = (current_aircraft.fdm_state->get_Altitude()
206 - current_aircraft.fdm_state->get_Runway_altitude());
208 agl = (current_aircraft.fdm_state->get_Altitude()
209 - current_aircraft.fdm_state->get_Runway_altitude()) * SG_FEET_TO_METER;
215 float get_sideslip( void )
217 return current_aircraft.fdm_state->get_Beta();
220 float get_frame_rate( void )
222 return general.get_frame_rate();
225 float get_fov( void )
227 return globals->get_current_view()->get_fov();
230 float get_vfc_ratio( void )
232 // float vfc = current_view.get_vfc_ratio();
237 float get_vfc_tris_drawn ( void )
239 // float rendered = current_view.get_tris_rendered();
240 // return (rendered);
244 float get_vfc_tris_culled ( void )
246 // float culled = current_view.get_tris_culled();
251 float get_climb_rate( void )
253 static const SGPropertyNode *startup_units_node
254 = fgGetNode("/sim/startup/units");
257 if ( !strcmp(startup_units_node->getStringValue(), "feet") ) {
258 climb_rate = current_aircraft.fdm_state->get_Climb_Rate() * 60.0;
260 climb_rate = current_aircraft.fdm_state->get_Climb_Rate() * SG_FEET_TO_METER * 60.0;
267 float get_view_direction( void )
269 double view_off = SGD_2PI - globals->get_current_view()->getHeadingOffset_deg() * SGD_DEGREES_TO_RADIANS;
270 double view = ( current_aircraft.fdm_state->get_Psi() + view_off)
271 * SGD_RADIANS_TO_DEGREES;
281 // Added by Markus Hof on 5. Jan 2004
282 float get_dme( void )
284 static const SGPropertyNode * dme_node =
285 fgGetNode("/instrumentation/dme/indicated-distance-nm");
287 return dme_node->getFloatValue();
290 // $$$ begin - added, VS Renganathan 13 Oct 2K
291 // #ifdef FIGHTER_HUD
292 float get_Vx ( void )
294 // Curt dont comment this and return zero. - Ranga
295 // Please remove comments from get_V_..() function in flight.hxx
296 float Vxx = current_aircraft.fdm_state->get_V_north_rel_ground();
300 float get_Vy ( void )
302 // Curt dont comment this and return zero. - Ranga
303 // Please remove comments from get_V_..() function in flight.hxx
304 float Vyy = current_aircraft.fdm_state->get_V_east_rel_ground();
308 float get_Vz ( void )
310 // Curt dont comment this and return zero. - Ranga
311 // Please remove comments from get_V_..() function in flight.hxx
312 float Vzz = current_aircraft.fdm_state->get_V_down_rel_ground();
316 float get_Ax ( void )
318 float Ax = current_aircraft.fdm_state->get_V_dot_north();
322 float get_Ay ( void )
324 float Ay = current_aircraft.fdm_state->get_V_dot_east();
328 float get_Az ( void )
330 float Az = current_aircraft.fdm_state->get_V_dot_down();
334 float get_anzg ( void )
336 float anzg = current_aircraft.fdm_state->get_N_Z_cg();
343 FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
344 return fdm->get_iaux(1);
349 FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
350 return fdm->get_iaux(2);
355 FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
356 return fdm->get_iaux(3);
361 FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
362 return fdm->get_iaux(4);
367 FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
368 return fdm->get_iaux(5);
373 FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
374 return fdm->get_iaux(6);
379 FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
380 return fdm->get_iaux(7);
385 FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
386 return fdm->get_iaux(8);
391 FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
392 return fdm->get_iaux(9);
395 int get_iaux10 (void)
397 FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
398 return fdm->get_iaux(10);
401 int get_iaux11 (void)
403 FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
404 return fdm->get_iaux(11);
407 int get_iaux12 (void)
409 FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
410 return fdm->get_iaux(12);
413 float get_aux1 (void)
415 FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
416 return fdm->get_daux(1);
419 float get_aux2 (void)
421 FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
422 return fdm->get_daux(2);
425 float get_aux3 (void)
427 FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
428 return fdm->get_daux(3);
431 float get_aux4 (void)
433 FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
434 return fdm->get_daux(4);
437 float get_aux5 (void)
439 FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
440 return fdm->get_daux(5);
443 float get_aux6 (void)
445 FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
446 return fdm->get_daux(6);
449 float get_aux7 (void)
451 FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
452 return fdm->get_daux(7);
455 float get_aux8 (void)
457 FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
458 return fdm->get_daux(8);
461 float get_aux9 (void)
463 FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
464 return fdm->get_faux(1);
467 float get_aux10 (void)
469 FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
470 return fdm->get_faux(2);
473 float get_aux11 (void)
475 FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
476 return fdm->get_faux(3);
479 float get_aux12 (void)
481 FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
482 return fdm->get_faux(4);
485 float get_aux13 (void)
487 FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
488 return fdm->get_faux(5);
491 float get_aux14 (void)
493 FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
494 return fdm->get_faux(6);
497 float get_aux15 (void)
499 FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
500 return fdm->get_faux(7);
503 float get_aux16 (void)
505 FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
506 return fdm->get_faux(8);
509 float get_aux17 (void)
511 FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
512 return fdm->get_faux(9);
515 float get_aux18 (void)
517 FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
518 return fdm->get_faux(10);
523 bool fgCockpitInit( fgAIRCRAFT *cur_aircraft )
525 SG_LOG( SG_COCKPIT, SG_INFO, "Initializing cockpit subsystem" );
527 // cockpit->code = 1; /* It will be aircraft dependent */
528 // cockpit->status = 0;
530 // If aircraft has HUD specified we will get the specs from its def
531 // file. For now we will depend upon hard coding in hud?
533 // We must insure that the existing instrument link is purged.
534 // This is done by deleting the links in the list.
536 // HI_Head is now a null pointer so we can generate a new list from the
539 fgHUDInit( cur_aircraft );
544 void fgCockpitUpdate( osg::State* state ) {
546 static const SGPropertyNode * xsize_node = fgGetNode("/sim/startup/xsize");
547 static const SGPropertyNode * ysize_node = fgGetNode("/sim/startup/ysize");
548 static const SGPropertyNode * hud_visibility_node
549 = fgGetNode("/sim/hud/visibility");
551 int iwidth = xsize_node->getIntValue();
552 int iheight = ysize_node->getIntValue();
554 // FIXME: inefficient
555 if ( hud_visibility_node->getBoolValue() ) {
556 // This will check the global hud linked list pointer.
557 // If there is anything to draw it will.
558 fgUpdateHUD( state );
561 glViewport( 0, 0, iwidth, iheight );
573 { "aileronval", get_aileronval },
574 { "altitude", get_altitude },
575 { "anzg", get_anzg },
578 { "climb", get_climb_rate },
579 { "elevatortrimval", get_elev_trimval },
580 { "elevatorval", get_elevatorval },
582 { "framerate", get_frame_rate },
583 { "heading", get_heading },
584 { "latitude", get_latitude },
585 { "longitude", get_longitude },
586 { "mach", get_mach },
587 { "rudderval", get_rudderval },
588 { "speed", get_speed },
589 { "throttleval", get_throttleval },
590 { "view_direction", get_view_direction },
591 { "vfc_tris_culled", get_vfc_tris_culled },
592 { "vfc_tris_drawn", get_vfc_tris_drawn },
594 { "aux1", get_aux1 },
595 { "aux2", get_aux2 },
596 { "aux3", get_aux3 },
597 { "aux4", get_aux4 },
598 { "aux5", get_aux5 },
599 { "aux6", get_aux6 },
600 { "aux7", get_aux7 },
601 { "aux8", get_aux8 },
602 { "aux9", get_aux9 },
603 { "aux10", get_aux10 },
604 { "aux11", get_aux11 },
605 { "aux12", get_aux12 },
606 { "aux13", get_aux13 },
607 { "aux14", get_aux14 },
608 { "aux15", get_aux15 },
609 { "aux16", get_aux16 },
610 { "aux17", get_aux17 },
611 { "aux18", get_aux18 },
617 FLTFNPTR get_func(const char *name)
619 for (int i = 0; fn_table[i].name; i++)
620 if (!strcmp(fn_table[i].name, name))
621 return fn_table[i].func;