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/math/polar3d.hxx>
37 #include <simgear/props/props.hxx>
38 #include <simgear/timing/sg_time.hxx>
40 #include <Aircraft/aircraft.hxx>
41 #include <Include/general.hxx>
43 #include <FDM/SP/ADA.hxx>
45 #include <Main/globals.hxx>
46 #include <Main/fg_props.hxx>
47 #include <Main/viewmgr.hxx>
48 #include <Scenery/scenery.hxx>
49 #include <Time/fg_timer.hxx>
52 #include "cockpit.hxx"
56 // The following routines obtain information concerntin the aircraft's
57 // current state and return it to calling instrument display routines.
58 // They should eventually be member functions of the aircraft.
61 float get_latitude( void )
63 return current_aircraft.fdm_state->get_Latitude() * SGD_RADIANS_TO_DEGREES;
66 float get_lat_min( void )
70 a = current_aircraft.fdm_state->get_Latitude() * SGD_RADIANS_TO_DEGREES;
74 d = (double) ( (int) a);
75 float lat_min = (a - d) * 60.0;
81 float get_longitude( void )
83 return current_aircraft.fdm_state->get_Longitude() * SGD_RADIANS_TO_DEGREES;
88 get_formated_gmt_time( void )
91 const struct tm *p = globals->get_time_params()->getGmt();
92 sprintf( buf, "%d/%d/%4d %d:%02d:%02d",
93 p->tm_mon+1, p->tm_mday, 1900 + p->tm_year,
94 p->tm_hour, p->tm_min, p->tm_sec);
100 float get_long_min( void )
103 a = current_aircraft.fdm_state->get_Longitude() * SGD_RADIANS_TO_DEGREES;
107 d = (double) ( (int) a);
108 float lon_min = (a - d) * 60.0;
113 float get_throttleval( void )
115 // Hack limiting to one engine
116 return globals->get_controls()->get_throttle( 0 );
119 float get_aileronval( void )
121 return globals->get_controls()->get_aileron();
124 float get_elevatorval( void )
126 return globals->get_controls()->get_elevator();
129 float get_elev_trimval( void )
131 return globals->get_controls()->get_elevator_trim();
134 float get_rudderval( void )
136 return globals->get_controls()->get_rudder();
139 float get_speed( void )
141 static const SGPropertyNode * speedup_node = fgGetNode("/sim/speed-up");
143 float speed = current_aircraft.fdm_state->get_V_calibrated_kts()
144 * speedup_node->getIntValue();
151 return current_aircraft.fdm_state->get_Mach_number();
154 float get_aoa( void )
156 return current_aircraft.fdm_state->get_Alpha() * SGD_RADIANS_TO_DEGREES;
159 float get_roll( void )
161 return current_aircraft.fdm_state->get_Phi();
164 float get_pitch( void )
166 return current_aircraft.fdm_state->get_Theta();
169 float get_heading( void )
171 return current_aircraft.fdm_state->get_Psi() * SGD_RADIANS_TO_DEGREES;
174 float get_altitude( void )
176 static const SGPropertyNode *startup_units_node
177 = fgGetNode("/sim/startup/units");
181 if ( !strcmp(startup_units_node->getStringValue(), "feet") ) {
182 altitude = current_aircraft.fdm_state->get_Altitude();
184 altitude = (current_aircraft.fdm_state->get_Altitude()
191 float get_agl( void )
193 static const SGPropertyNode *startup_units_node
194 = fgGetNode("/sim/startup/units");
198 if ( !strcmp(startup_units_node->getStringValue(), "feet") ) {
199 agl = (current_aircraft.fdm_state->get_Altitude()
200 - current_aircraft.fdm_state->get_Runway_altitude());
202 agl = (current_aircraft.fdm_state->get_Altitude()
203 - current_aircraft.fdm_state->get_Runway_altitude()) * SG_FEET_TO_METER;
209 float get_sideslip( void )
211 return current_aircraft.fdm_state->get_Beta();
214 float get_frame_rate( void )
216 return general.get_frame_rate();
219 float get_fov( void )
221 return globals->get_current_view()->get_fov();
224 float get_vfc_ratio( void )
226 // float vfc = current_view.get_vfc_ratio();
231 float get_vfc_tris_drawn ( void )
233 // float rendered = current_view.get_tris_rendered();
234 // return (rendered);
238 float get_vfc_tris_culled ( void )
240 // float culled = current_view.get_tris_culled();
245 float get_climb_rate( void )
247 static const SGPropertyNode *startup_units_node
248 = fgGetNode("/sim/startup/units");
251 if ( !strcmp(startup_units_node->getStringValue(), "feet") ) {
252 climb_rate = current_aircraft.fdm_state->get_Climb_Rate() * 60.0;
254 climb_rate = current_aircraft.fdm_state->get_Climb_Rate() * SG_FEET_TO_METER * 60.0;
261 float get_view_direction( void )
263 double view_off = SGD_2PI - globals->get_current_view()->getHeadingOffset_deg() * SGD_DEGREES_TO_RADIANS;
264 double view = ( current_aircraft.fdm_state->get_Psi() + view_off)
265 * SGD_RADIANS_TO_DEGREES;
275 // Added by Markus Hof on 5. Jan 2004
276 float get_dme( void )
278 static const SGPropertyNode * dme_node =
279 fgGetNode("/instrumentation/dme/indicated-distance-nm");
281 return dme_node->getFloatValue();
284 // $$$ begin - added, VS Renganathan 13 Oct 2K
285 // #ifdef FIGHTER_HUD
286 float get_Vx ( void )
288 // Curt dont comment this and return zero. - Ranga
289 // Please remove comments from get_V_..() function in flight.hxx
290 float Vxx = current_aircraft.fdm_state->get_V_north_rel_ground();
294 float get_Vy ( void )
296 // Curt dont comment this and return zero. - Ranga
297 // Please remove comments from get_V_..() function in flight.hxx
298 float Vyy = current_aircraft.fdm_state->get_V_east_rel_ground();
302 float get_Vz ( void )
304 // Curt dont comment this and return zero. - Ranga
305 // Please remove comments from get_V_..() function in flight.hxx
306 float Vzz = current_aircraft.fdm_state->get_V_down_rel_ground();
310 float get_Ax ( void )
312 float Ax = current_aircraft.fdm_state->get_V_dot_north();
316 float get_Ay ( void )
318 float Ay = current_aircraft.fdm_state->get_V_dot_east();
322 float get_Az ( void )
324 float Az = current_aircraft.fdm_state->get_V_dot_down();
328 float get_anzg ( void )
330 float anzg = current_aircraft.fdm_state->get_N_Z_cg();
337 FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
338 return fdm->get_iaux(1);
343 FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
344 return fdm->get_iaux(2);
349 FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
350 return fdm->get_iaux(3);
355 FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
356 return fdm->get_iaux(4);
361 FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
362 return fdm->get_iaux(5);
367 FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
368 return fdm->get_iaux(6);
373 FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
374 return fdm->get_iaux(7);
379 FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
380 return fdm->get_iaux(8);
385 FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
386 return fdm->get_iaux(9);
389 int get_iaux10 (void)
391 FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
392 return fdm->get_iaux(10);
395 int get_iaux11 (void)
397 FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
398 return fdm->get_iaux(11);
401 int get_iaux12 (void)
403 FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
404 return fdm->get_iaux(12);
407 float get_aux1 (void)
409 FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
410 return fdm->get_daux(1);
413 float get_aux2 (void)
415 FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
416 return fdm->get_daux(2);
419 float get_aux3 (void)
421 FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
422 return fdm->get_daux(3);
425 float get_aux4 (void)
427 FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
428 return fdm->get_daux(4);
431 float get_aux5 (void)
433 FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
434 return fdm->get_daux(5);
437 float get_aux6 (void)
439 FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
440 return fdm->get_daux(6);
443 float get_aux7 (void)
445 FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
446 return fdm->get_daux(7);
449 float get_aux8 (void)
451 FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
452 return fdm->get_daux(8);
455 float get_aux9 (void)
457 FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
458 return fdm->get_faux(1);
461 float get_aux10 (void)
463 FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
464 return fdm->get_faux(2);
467 float get_aux11 (void)
469 FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
470 return fdm->get_faux(3);
473 float get_aux12 (void)
475 FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
476 return fdm->get_faux(4);
479 float get_aux13 (void)
481 FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
482 return fdm->get_faux(5);
485 float get_aux14 (void)
487 FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
488 return fdm->get_faux(6);
491 float get_aux15 (void)
493 FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
494 return fdm->get_faux(7);
497 float get_aux16 (void)
499 FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
500 return fdm->get_faux(8);
503 float get_aux17 (void)
505 FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
506 return fdm->get_faux(9);
509 float get_aux18 (void)
511 FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
512 return fdm->get_faux(10);
517 bool fgCockpitInit( fgAIRCRAFT *cur_aircraft )
519 SG_LOG( SG_COCKPIT, SG_INFO, "Initializing cockpit subsystem" );
521 // cockpit->code = 1; /* It will be aircraft dependent */
522 // cockpit->status = 0;
524 // If aircraft has HUD specified we will get the specs from its def
525 // file. For now we will depend upon hard coding in hud?
527 // We must insure that the existing instrument link is purged.
528 // This is done by deleting the links in the list.
530 // HI_Head is now a null pointer so we can generate a new list from the
533 fgHUDInit( cur_aircraft );
538 void fgCockpitUpdate( osg::State* state ) {
540 static const SGPropertyNode * xsize_node = fgGetNode("/sim/startup/xsize");
541 static const SGPropertyNode * ysize_node = fgGetNode("/sim/startup/ysize");
542 static const SGPropertyNode * hud_visibility_node
543 = fgGetNode("/sim/hud/visibility");
545 int iwidth = xsize_node->getIntValue();
546 int iheight = ysize_node->getIntValue();
548 // FIXME: inefficient
549 if ( hud_visibility_node->getBoolValue() ) {
550 // This will check the global hud linked list pointer.
551 // If there is anything to draw it will.
552 fgUpdateHUD( state );
555 glViewport( 0, 0, iwidth, iheight );
567 { "aileronval", get_aileronval },
568 { "altitude", get_altitude },
569 { "anzg", get_anzg },
572 { "climb", get_climb_rate },
573 { "elevatortrimval", get_elev_trimval },
574 { "elevatorval", get_elevatorval },
576 { "framerate", get_frame_rate },
577 { "heading", get_heading },
578 { "latitude", get_latitude },
579 { "longitude", get_longitude },
580 { "mach", get_mach },
581 { "rudderval", get_rudderval },
582 { "speed", get_speed },
583 { "throttleval", get_throttleval },
584 { "view_direction", get_view_direction },
585 { "vfc_tris_culled", get_vfc_tris_culled },
586 { "vfc_tris_drawn", get_vfc_tris_drawn },
588 { "aux1", get_aux1 },
589 { "aux2", get_aux2 },
590 { "aux3", get_aux3 },
591 { "aux4", get_aux4 },
592 { "aux5", get_aux5 },
593 { "aux6", get_aux6 },
594 { "aux7", get_aux7 },
595 { "aux8", get_aux8 },
596 { "aux9", get_aux9 },
597 { "aux10", get_aux10 },
598 { "aux11", get_aux11 },
599 { "aux12", get_aux12 },
600 { "aux13", get_aux13 },
601 { "aux14", get_aux14 },
602 { "aux15", get_aux15 },
603 { "aux16", get_aux16 },
604 { "aux17", get_aux17 },
605 { "aux18", get_aux18 },
611 FLTFNPTR get_func(const char *name)
613 for (int i = 0; fn_table[i].name; i++)
614 if (!strcmp(fn_table[i].name, name))
615 return fn_table[i].func;