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 // This is a structure that contains all data related to
63 // cockpit/panel/hud system
65 static pCockpit ac_cockpit;
66 // The following routines obtain information concerntin the aircraft's
67 // current state and return it to calling instrument display routines.
68 // They should eventually be member functions of the aircraft.
71 float get_latitude( void )
73 return current_aircraft.fdm_state->get_Latitude() * SGD_RADIANS_TO_DEGREES;
76 float get_lat_min( void )
80 a = current_aircraft.fdm_state->get_Latitude() * SGD_RADIANS_TO_DEGREES;
84 d = (double) ( (int) a);
85 float lat_min = (a - d) * 60.0;
91 float get_longitude( void )
93 return current_aircraft.fdm_state->get_Longitude() * SGD_RADIANS_TO_DEGREES;
98 get_formated_gmt_time( void )
101 const struct tm *p = globals->get_time_params()->getGmt();
102 sprintf( buf, "%d/%d/%4d %d:%02d:%02d",
103 p->tm_mon+1, p->tm_mday, 1900 + p->tm_year,
104 p->tm_hour, p->tm_min, p->tm_sec);
110 float get_long_min( void )
113 a = current_aircraft.fdm_state->get_Longitude() * SGD_RADIANS_TO_DEGREES;
117 d = (double) ( (int) a);
118 float lon_min = (a - d) * 60.0;
123 float get_throttleval( void )
125 // Hack limiting to one engine
126 return globals->get_controls()->get_throttle( 0 );
129 float get_aileronval( void )
131 return globals->get_controls()->get_aileron();
134 float get_elevatorval( void )
136 return globals->get_controls()->get_elevator();
139 float get_elev_trimval( void )
141 return globals->get_controls()->get_elevator_trim();
144 float get_rudderval( void )
146 return globals->get_controls()->get_rudder();
149 float get_speed( void )
151 static const SGPropertyNode * speedup_node = fgGetNode("/sim/speed-up");
153 float speed = current_aircraft.fdm_state->get_V_calibrated_kts()
154 * speedup_node->getIntValue();
161 return current_aircraft.fdm_state->get_Mach_number();
164 float get_aoa( void )
166 return current_aircraft.fdm_state->get_Alpha() * SGD_RADIANS_TO_DEGREES;
169 float get_roll( void )
171 return current_aircraft.fdm_state->get_Phi();
174 float get_pitch( void )
176 return current_aircraft.fdm_state->get_Theta();
179 float get_heading( void )
181 return current_aircraft.fdm_state->get_Psi() * SGD_RADIANS_TO_DEGREES;
184 float get_altitude( void )
186 static const SGPropertyNode *startup_units_node
187 = fgGetNode("/sim/startup/units");
191 if ( !strcmp(startup_units_node->getStringValue(), "feet") ) {
192 altitude = current_aircraft.fdm_state->get_Altitude();
194 altitude = (current_aircraft.fdm_state->get_Altitude()
201 float get_agl( void )
203 static const SGPropertyNode *startup_units_node
204 = fgGetNode("/sim/startup/units");
208 if ( !strcmp(startup_units_node->getStringValue(), "feet") ) {
209 agl = (current_aircraft.fdm_state->get_Altitude()
210 - current_aircraft.fdm_state->get_Runway_altitude());
212 agl = (current_aircraft.fdm_state->get_Altitude()
213 - current_aircraft.fdm_state->get_Runway_altitude()) * SG_FEET_TO_METER;
219 float get_sideslip( void )
221 return current_aircraft.fdm_state->get_Beta();
224 float get_frame_rate( void )
226 return general.get_frame_rate();
229 float get_fov( void )
231 return globals->get_current_view()->get_fov();
234 float get_vfc_ratio( void )
236 // float vfc = current_view.get_vfc_ratio();
241 float get_vfc_tris_drawn ( void )
243 // float rendered = current_view.get_tris_rendered();
244 // return (rendered);
248 float get_vfc_tris_culled ( void )
250 // float culled = current_view.get_tris_culled();
255 float get_climb_rate( void )
257 static const SGPropertyNode *startup_units_node
258 = fgGetNode("/sim/startup/units");
261 if ( !strcmp(startup_units_node->getStringValue(), "feet") ) {
262 climb_rate = current_aircraft.fdm_state->get_Climb_Rate() * 60.0;
264 climb_rate = current_aircraft.fdm_state->get_Climb_Rate() * SG_FEET_TO_METER * 60.0;
271 float get_view_direction( void )
273 double view_off = SGD_2PI - globals->get_current_view()->getHeadingOffset_deg() * SGD_DEGREES_TO_RADIANS;
274 double view = ( current_aircraft.fdm_state->get_Psi() + view_off)
275 * SGD_RADIANS_TO_DEGREES;
285 // Added by Markus Hof on 5. Jan 2004
286 float get_dme( void )
288 static const SGPropertyNode * dme_node =
289 fgGetNode("/instrumentation/dme/indicated-distance-nm");
291 return dme_node->getFloatValue();
294 // $$$ begin - added, VS Renganathan 13 Oct 2K
295 // #ifdef FIGHTER_HUD
296 float get_Vx ( void )
298 // Curt dont comment this and return zero. - Ranga
299 // Please remove comments from get_V_..() function in flight.hxx
300 float Vxx = current_aircraft.fdm_state->get_V_north_rel_ground();
304 float get_Vy ( void )
306 // Curt dont comment this and return zero. - Ranga
307 // Please remove comments from get_V_..() function in flight.hxx
308 float Vyy = current_aircraft.fdm_state->get_V_east_rel_ground();
312 float get_Vz ( void )
314 // Curt dont comment this and return zero. - Ranga
315 // Please remove comments from get_V_..() function in flight.hxx
316 float Vzz = current_aircraft.fdm_state->get_V_down_rel_ground();
320 float get_Ax ( void )
322 float Ax = current_aircraft.fdm_state->get_V_dot_north();
326 float get_Ay ( void )
328 float Ay = current_aircraft.fdm_state->get_V_dot_east();
332 float get_Az ( void )
334 float Az = current_aircraft.fdm_state->get_V_dot_down();
338 float get_anzg ( void )
340 float anzg = current_aircraft.fdm_state->get_N_Z_cg();
344 #ifdef ENABLE_SP_FMDS
347 FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
348 return fdm->get_iaux(1);
353 FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
354 return fdm->get_iaux(2);
359 FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
360 return fdm->get_iaux(3);
365 FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
366 return fdm->get_iaux(4);
371 FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
372 return fdm->get_iaux(5);
377 FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
378 return fdm->get_iaux(6);
383 FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
384 return fdm->get_iaux(7);
389 FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
390 return fdm->get_iaux(8);
395 FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
396 return fdm->get_iaux(9);
399 int get_iaux10 (void)
401 FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
402 return fdm->get_iaux(10);
405 int get_iaux11 (void)
407 FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
408 return fdm->get_iaux(11);
411 int get_iaux12 (void)
413 FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
414 return fdm->get_iaux(12);
417 float get_aux1 (void)
419 FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
420 return fdm->get_daux(1);
423 float get_aux2 (void)
425 FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
426 return fdm->get_daux(2);
429 float get_aux3 (void)
431 FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
432 return fdm->get_daux(3);
435 float get_aux4 (void)
437 FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
438 return fdm->get_daux(4);
441 float get_aux5 (void)
443 FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
444 return fdm->get_daux(5);
447 float get_aux6 (void)
449 FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
450 return fdm->get_daux(6);
453 float get_aux7 (void)
455 FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
456 return fdm->get_daux(7);
459 float get_aux8 (void)
461 FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
462 return fdm->get_daux(8);
465 float get_aux9 (void)
467 FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
468 return fdm->get_faux(1);
471 float get_aux10 (void)
473 FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
474 return fdm->get_faux(2);
477 float get_aux11 (void)
479 FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
480 return fdm->get_faux(3);
483 float get_aux12 (void)
485 FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
486 return fdm->get_faux(4);
489 float get_aux13 (void)
491 FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
492 return fdm->get_faux(5);
495 float get_aux14 (void)
497 FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
498 return fdm->get_faux(6);
501 float get_aux15 (void)
503 FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
504 return fdm->get_faux(7);
507 float get_aux16 (void)
509 FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
510 return fdm->get_faux(8);
513 float get_aux17 (void)
515 FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
516 return fdm->get_faux(9);
519 float get_aux18 (void)
521 FGADA *fdm = (FGADA *)current_aircraft.fdm_state;
522 return fdm->get_faux(10);
527 bool fgCockpitInit( fgAIRCRAFT *cur_aircraft )
529 SG_LOG( SG_COCKPIT, SG_INFO, "Initializing cockpit subsystem" );
531 // cockpit->code = 1; /* It will be aircraft dependent */
532 // cockpit->status = 0;
534 // If aircraft has HUD specified we will get the specs from its def
535 // file. For now we will depend upon hard coding in hud?
537 // We must insure that the existing instrument link is purged.
538 // This is done by deleting the links in the list.
540 // HI_Head is now a null pointer so we can generate a new list from the
543 fgHUDInit( cur_aircraft );
544 ac_cockpit = new fg_Cockpit();
546 SG_LOG( SG_COCKPIT, SG_INFO,
547 " Code " << ac_cockpit->code() << " Status "
548 << ac_cockpit->status() );
553 void fgCockpitUpdate( void ) {
555 SG_LOG( SG_COCKPIT, SG_DEBUG,
556 "Cockpit: code " << ac_cockpit->code() << " status "
557 << ac_cockpit->status() );
559 static const SGPropertyNode * xsize_node = fgGetNode("/sim/startup/xsize");
560 static const SGPropertyNode * ysize_node = fgGetNode("/sim/startup/ysize");
561 static const SGPropertyNode * hud_visibility_node
562 = fgGetNode("/sim/hud/visibility");
564 int iwidth = xsize_node->getIntValue();
565 int iheight = ysize_node->getIntValue();
567 // FIXME: inefficient
568 if ( hud_visibility_node->getBoolValue() ) {
569 // This will check the global hud linked list pointer.
570 // If there is anything to draw it will.
574 glViewport( 0, 0, iwidth, iheight );
586 { "aileronval", get_aileronval },
587 { "altitude", get_altitude },
588 { "anzg", get_anzg },
591 { "climb", get_climb_rate },
592 { "elevatortrimval", get_elev_trimval },
593 { "elevatorval", get_elevatorval },
595 { "framerate", get_frame_rate },
596 { "heading", get_heading },
597 { "latitude", get_latitude },
598 { "longitude", get_longitude },
599 { "mach", get_mach },
600 { "rudderval", get_rudderval },
601 { "speed", get_speed },
602 { "throttleval", get_throttleval },
603 { "view_direction", get_view_direction },
604 { "vfc_tris_culled", get_vfc_tris_culled },
605 { "vfc_tris_drawn", get_vfc_tris_drawn },
606 #ifdef ENABLE_SP_FMDS
607 { "aux1", get_aux1 },
608 { "aux2", get_aux2 },
609 { "aux3", get_aux3 },
610 { "aux4", get_aux4 },
611 { "aux5", get_aux5 },
612 { "aux6", get_aux6 },
613 { "aux7", get_aux7 },
614 { "aux8", get_aux8 },
615 { "aux9", get_aux9 },
616 { "aux10", get_aux10 },
617 { "aux11", get_aux11 },
618 { "aux12", get_aux12 },
619 { "aux13", get_aux13 },
620 { "aux14", get_aux14 },
621 { "aux15", get_aux15 },
622 { "aux16", get_aux16 },
623 { "aux17", get_aux17 },
624 { "aux18", get_aux18 },
630 FLTFNPTR get_func(const char *name)
632 for (int i = 0; fn_table[i].name; i++)
633 if (!strcmp(fn_table[i].name, name))
634 return fn_table[i].func;