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 <Scenery/scenery.hxx>
50 #include "cockpit.hxx"
54 // The following routines obtain information concerntin the aircraft's
55 // current state and return it to calling instrument display routines.
56 // They should eventually be member functions of the aircraft.
59 float get_latitude( void )
61 return current_aircraft.fdm_state->get_Latitude() * SGD_RADIANS_TO_DEGREES;
64 float get_lat_min( void )
68 a = current_aircraft.fdm_state->get_Latitude() * SGD_RADIANS_TO_DEGREES;
72 d = (double) ( (int) a);
73 float lat_min = (a - d) * 60.0;
79 float get_longitude( void )
81 return current_aircraft.fdm_state->get_Longitude() * SGD_RADIANS_TO_DEGREES;
86 get_formated_gmt_time( void )
89 const struct tm *p = globals->get_time_params()->getGmt();
90 sprintf( buf, "%d/%d/%4d %d:%02d:%02d",
91 p->tm_mon+1, p->tm_mday, 1900 + p->tm_year,
92 p->tm_hour, p->tm_min, p->tm_sec);
98 float get_long_min( void )
101 a = current_aircraft.fdm_state->get_Longitude() * SGD_RADIANS_TO_DEGREES;
105 d = (double) ( (int) a);
106 float lon_min = (a - d) * 60.0;
111 float get_throttleval( void )
113 // Hack limiting to one engine
114 return globals->get_controls()->get_throttle( 0 );
117 float get_aileronval( void )
119 return globals->get_controls()->get_aileron();
122 float get_elevatorval( void )
124 return globals->get_controls()->get_elevator();
127 float get_elev_trimval( void )
129 return globals->get_controls()->get_elevator_trim();
132 float get_rudderval( void )
134 return globals->get_controls()->get_rudder();
137 float get_speed( void )
139 static const SGPropertyNode * speedup_node = fgGetNode("/sim/speed-up");
141 float speed = current_aircraft.fdm_state->get_V_calibrated_kts()
142 * speedup_node->getIntValue();
149 return current_aircraft.fdm_state->get_Mach_number();
152 float get_aoa( void )
154 return current_aircraft.fdm_state->get_Alpha() * SGD_RADIANS_TO_DEGREES;
157 float get_roll( void )
159 return current_aircraft.fdm_state->get_Phi();
162 float get_pitch( void )
164 return current_aircraft.fdm_state->get_Theta();
167 float get_heading( void )
169 return current_aircraft.fdm_state->get_Psi() * SGD_RADIANS_TO_DEGREES;
172 float get_altitude( void )
174 static const SGPropertyNode *startup_units_node
175 = fgGetNode("/sim/startup/units");
179 if ( !strcmp(startup_units_node->getStringValue(), "feet") ) {
180 altitude = current_aircraft.fdm_state->get_Altitude();
182 altitude = (current_aircraft.fdm_state->get_Altitude()
189 float get_agl( void )
191 static const SGPropertyNode *startup_units_node
192 = fgGetNode("/sim/startup/units");
196 if ( !strcmp(startup_units_node->getStringValue(), "feet") ) {
197 agl = (current_aircraft.fdm_state->get_Altitude()
198 - current_aircraft.fdm_state->get_Runway_altitude());
200 agl = (current_aircraft.fdm_state->get_Altitude()
201 - current_aircraft.fdm_state->get_Runway_altitude()) * SG_FEET_TO_METER;
207 float get_sideslip( void )
209 return current_aircraft.fdm_state->get_Beta();
212 float get_frame_rate( void )
214 return general.get_frame_rate();
217 float get_fov( void )
219 return globals->get_current_view()->get_fov();
222 float get_vfc_ratio( void )
224 // float vfc = current_view.get_vfc_ratio();
229 float get_vfc_tris_drawn ( void )
231 // float rendered = current_view.get_tris_rendered();
232 // return (rendered);
236 float get_vfc_tris_culled ( void )
238 // float culled = current_view.get_tris_culled();
243 float get_climb_rate( void )
245 static const SGPropertyNode *startup_units_node
246 = fgGetNode("/sim/startup/units");
249 if ( !strcmp(startup_units_node->getStringValue(), "feet") ) {
250 climb_rate = current_aircraft.fdm_state->get_Climb_Rate() * 60.0;
252 climb_rate = current_aircraft.fdm_state->get_Climb_Rate() * SG_FEET_TO_METER * 60.0;
259 float get_view_direction( void )
261 double view_off = SGD_2PI - globals->get_current_view()->getHeadingOffset_deg() * SGD_DEGREES_TO_RADIANS;
262 double view = ( current_aircraft.fdm_state->get_Psi() + view_off)
263 * SGD_RADIANS_TO_DEGREES;
273 // Added by Markus Hof on 5. Jan 2004
274 float get_dme( void )
276 static const SGPropertyNode * dme_node =
277 fgGetNode("/instrumentation/dme/indicated-distance-nm");
279 return dme_node->getFloatValue();
282 // $$$ begin - added, VS Renganathan 13 Oct 2K
283 // #ifdef FIGHTER_HUD
284 float get_Vx ( void )
286 // Curt dont comment this and return zero. - Ranga
287 // Please remove comments from get_V_..() function in flight.hxx
288 float Vxx = current_aircraft.fdm_state->get_V_north_rel_ground();
292 float get_Vy ( void )
294 // Curt dont comment this and return zero. - Ranga
295 // Please remove comments from get_V_..() function in flight.hxx
296 float Vyy = current_aircraft.fdm_state->get_V_east_rel_ground();
300 float get_Vz ( void )
302 // Curt dont comment this and return zero. - Ranga
303 // Please remove comments from get_V_..() function in flight.hxx
304 float Vzz = current_aircraft.fdm_state->get_V_down_rel_ground();
308 float get_Ax ( void )
310 float Ax = current_aircraft.fdm_state->get_V_dot_north();
314 float get_Ay ( void )
316 float Ay = current_aircraft.fdm_state->get_V_dot_east();
320 float get_Az ( void )
322 float Az = current_aircraft.fdm_state->get_V_dot_down();
326 float get_anzg ( void )
328 float anzg = current_aircraft.fdm_state->get_N_Z_cg();
335 FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
336 return fdm->get_iaux(1);
341 FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
342 return fdm->get_iaux(2);
347 FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
348 return fdm->get_iaux(3);
353 FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
354 return fdm->get_iaux(4);
359 FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
360 return fdm->get_iaux(5);
365 FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
366 return fdm->get_iaux(6);
371 FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
372 return fdm->get_iaux(7);
377 FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
378 return fdm->get_iaux(8);
383 FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
384 return fdm->get_iaux(9);
387 int get_iaux10 (void)
389 FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
390 return fdm->get_iaux(10);
393 int get_iaux11 (void)
395 FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
396 return fdm->get_iaux(11);
399 int get_iaux12 (void)
401 FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
402 return fdm->get_iaux(12);
405 float get_aux1 (void)
407 FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
408 return fdm->get_daux(1);
411 float get_aux2 (void)
413 FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
414 return fdm->get_daux(2);
417 float get_aux3 (void)
419 FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
420 return fdm->get_daux(3);
423 float get_aux4 (void)
425 FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
426 return fdm->get_daux(4);
429 float get_aux5 (void)
431 FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
432 return fdm->get_daux(5);
435 float get_aux6 (void)
437 FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
438 return fdm->get_daux(6);
441 float get_aux7 (void)
443 FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
444 return fdm->get_daux(7);
447 float get_aux8 (void)
449 FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
450 return fdm->get_daux(8);
453 float get_aux9 (void)
455 FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
456 return fdm->get_faux(1);
459 float get_aux10 (void)
461 FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
462 return fdm->get_faux(2);
465 float get_aux11 (void)
467 FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
468 return fdm->get_faux(3);
471 float get_aux12 (void)
473 FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
474 return fdm->get_faux(4);
477 float get_aux13 (void)
479 FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
480 return fdm->get_faux(5);
483 float get_aux14 (void)
485 FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
486 return fdm->get_faux(6);
489 float get_aux15 (void)
491 FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
492 return fdm->get_faux(7);
495 float get_aux16 (void)
497 FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
498 return fdm->get_faux(8);
501 float get_aux17 (void)
503 FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
504 return fdm->get_faux(9);
507 float get_aux18 (void)
509 FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
510 return fdm->get_faux(10);
515 bool fgCockpitInit( fgAIRCRAFT *cur_aircraft )
517 SG_LOG( SG_COCKPIT, SG_INFO, "Initializing cockpit subsystem" );
519 // cockpit->code = 1; /* It will be aircraft dependent */
520 // cockpit->status = 0;
522 // If aircraft has HUD specified we will get the specs from its def
523 // file. For now we will depend upon hard coding in hud?
525 // We must insure that the existing instrument link is purged.
526 // This is done by deleting the links in the list.
528 // HI_Head is now a null pointer so we can generate a new list from the
531 fgHUDInit( cur_aircraft );
536 void fgCockpitUpdate( osg::State* state ) {
538 static const SGPropertyNode * xsize_node = fgGetNode("/sim/startup/xsize");
539 static const SGPropertyNode * ysize_node = fgGetNode("/sim/startup/ysize");
540 static const SGPropertyNode * hud_visibility_node
541 = fgGetNode("/sim/hud/visibility");
543 int iwidth = xsize_node->getIntValue();
544 int iheight = ysize_node->getIntValue();
546 // FIXME: inefficient
547 if ( hud_visibility_node->getBoolValue() ) {
548 // This will check the global hud linked list pointer.
549 // If there is anything to draw it will.
550 fgUpdateHUD( state );
553 glViewport( 0, 0, iwidth, iheight );
565 { "aileronval", get_aileronval },
566 { "altitude", get_altitude },
567 { "anzg", get_anzg },
570 { "climb", get_climb_rate },
571 { "elevatortrimval", get_elev_trimval },
572 { "elevatorval", get_elevatorval },
574 { "framerate", get_frame_rate },
575 { "heading", get_heading },
576 { "latitude", get_latitude },
577 { "longitude", get_longitude },
578 { "mach", get_mach },
579 { "rudderval", get_rudderval },
580 { "speed", get_speed },
581 { "throttleval", get_throttleval },
582 { "view_direction", get_view_direction },
583 { "vfc_tris_culled", get_vfc_tris_culled },
584 { "vfc_tris_drawn", get_vfc_tris_drawn },
586 { "aux1", get_aux1 },
587 { "aux2", get_aux2 },
588 { "aux3", get_aux3 },
589 { "aux4", get_aux4 },
590 { "aux5", get_aux5 },
591 { "aux6", get_aux6 },
592 { "aux7", get_aux7 },
593 { "aux8", get_aux8 },
594 { "aux9", get_aux9 },
595 { "aux10", get_aux10 },
596 { "aux11", get_aux11 },
597 { "aux12", get_aux12 },
598 { "aux13", get_aux13 },
599 { "aux14", get_aux14 },
600 { "aux15", get_aux15 },
601 { "aux16", get_aux16 },
602 { "aux17", get_aux17 },
603 { "aux18", get_aux18 },
609 FLTFNPTR get_func(const char *name)
611 for (int i = 0; fn_table[i].name; i++)
612 if (!strcmp(fn_table[i].name, name))
613 return fn_table[i].func;