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 <Main/globals.hxx>
43 #include <Main/fg_props.hxx>
44 #include <Main/viewmgr.hxx>
45 #include <Main/viewer.hxx>
46 #include <Scenery/scenery.hxx>
49 #include "cockpit.hxx"
52 // The following routines obtain information concerntin the aircraft's
53 // current state and return it to calling instrument display routines.
54 // They should eventually be member functions of the aircraft.
57 float get_latitude( void )
59 return fgGetDouble("/position/latitude-deg");
62 float get_lat_min( void )
66 a = fgGetDouble("/position/latitude-deg");
70 d = (double) ( (int) a);
71 float lat_min = (a - d) * 60.0;
77 float get_longitude( void )
79 return fgGetDouble("/position/longitude-deg");
84 get_formated_gmt_time( void )
87 const struct tm *p = globals->get_time_params()->getGmt();
88 sprintf( buf, "%d/%d/%4d %d:%02d:%02d",
89 p->tm_mon+1, p->tm_mday, 1900 + p->tm_year,
90 p->tm_hour, p->tm_min, p->tm_sec);
96 float get_long_min( void )
99 a = fgGetDouble("/position/longitude-deg");
103 d = (double) ( (int) a);
104 float lon_min = (a - d) * 60.0;
109 float get_throttleval( void )
111 // Hack limiting to one engine
112 return globals->get_controls()->get_throttle( 0 );
115 float get_aileronval( void )
117 return globals->get_controls()->get_aileron();
120 float get_elevatorval( void )
122 return globals->get_controls()->get_elevator();
125 float get_elev_trimval( void )
127 return globals->get_controls()->get_elevator_trim();
130 float get_rudderval( void )
132 return globals->get_controls()->get_rudder();
135 float get_speed( void )
137 static const SGPropertyNode * speedup_node = fgGetNode("/sim/speed-up");
139 float speed = fgGetDouble("/velocities/airspeed-kt")
140 * speedup_node->getIntValue();
147 return fgGetDouble("/velocities/mach");
150 float get_aoa( void )
152 return fgGetDouble("/orientation/alpha-deg");
155 float get_roll( void )
157 return fgGetDouble("/orientation/roll-deg") * SG_DEGREES_TO_RADIANS;
160 float get_pitch( void )
162 return fgGetDouble("/orientation/pitch-deg") * SG_DEGREES_TO_RADIANS;
165 float get_heading( void )
167 return fgGetDouble("/orientation/heading-deg");
170 float get_altitude( void )
172 static const SGPropertyNode *startup_units_node
173 = fgGetNode("/sim/startup/units");
175 if ( !strcmp(startup_units_node->getStringValue(), "feet") ) {
176 return fgGetDouble("/position/altitude-ft");
178 return fgGetDouble("/position/altitude-ft") * SG_FEET_TO_METER;
182 float get_agl( void )
184 static const SGPropertyNode *startup_units_node
185 = fgGetNode("/sim/startup/units");
187 if ( !strcmp(startup_units_node->getStringValue(), "feet") ) {
188 return fgGetDouble("/position/altitude-agl-ft");
190 return fgGetDouble("/position/altitude-agl-ft") * SG_FEET_TO_METER;
194 float get_sideslip( void )
196 return fgGetDouble("/orientation/side-slip-rad");
199 float get_frame_rate( void )
201 return general.get_frame_rate();
204 float get_fov( void )
206 return globals->get_current_view()->get_fov();
209 float get_vfc_ratio( void )
211 // float vfc = current_view.get_vfc_ratio();
216 float get_vfc_tris_drawn ( void )
218 // float rendered = current_view.get_tris_rendered();
219 // return (rendered);
223 float get_vfc_tris_culled ( void )
225 // float culled = current_view.get_tris_culled();
230 float get_climb_rate( void )
232 static const SGPropertyNode *startup_units_node
233 = fgGetNode("/sim/startup/units");
235 float climb_rate = fgGetDouble("/velocities/vertical-speed-fps", 0.0);
236 if ( !strcmp(startup_units_node->getStringValue(), "feet") ) {
239 climb_rate *= SG_FEET_TO_METER * 60.0;
246 float get_view_direction( void )
248 double view_off = 360.0 - globals->get_current_view()->getHeadingOffset_deg();
249 double view = SGMiscd::normalizeAngle(fgGetDouble("/orientation/heading-deg") + view_off);
253 // Added by Markus Hof on 5. Jan 2004
254 float get_dme( void )
256 static const SGPropertyNode * dme_node =
257 fgGetNode("/instrumentation/dme/indicated-distance-nm");
259 return dme_node->getFloatValue();
262 float get_Ax ( void )
264 return fgGetDouble("/accelerations/ned/north-accel-fps_sec", 0.0);
267 float get_anzg ( void )
269 return fgGetDouble("/accelerations/n-z-cg-fps_sec", 0.0);
273 float get_aux1 (void)
275 return fgGetDouble("/fdm-ada/ship-lat", 0.0);
278 float get_aux2 (void)
280 return fgGetDouble("/fdm-ada/ship-lon", 0.0);
283 float get_aux3 (void)
285 return fgGetDouble("/fdm-ada/ship-alt", 0.0);
288 float get_aux4 (void)
290 return fgGetDouble("/fdm-ada/skijump-dist", 0.0);
293 float get_aux5 (void)
295 return fgGetDouble("/fdm-ada/aux5", 0.0);
298 float get_aux6 (void)
300 return fgGetDouble("/fdm-ada/aux6", 0.0);
303 float get_aux7 (void)
305 return fgGetDouble("/fdm-ada/aux7", 0.0);
308 float get_aux8 (void)
310 return fgGetDouble("/fdm-ada/aux8", 0.0);}
312 float get_aux9 (void)
314 return fgGetDouble("/fdm-ada/aux9", 0.0);}
316 float get_aux10 (void)
318 return fgGetDouble("/fdm-ada/aux10", 0.0);
321 float get_aux11 (void)
323 return fgGetDouble("/fdm-ada/aux11", 0.0);
326 float get_aux12 (void)
328 return fgGetDouble("/fdm-ada/aux12", 0.0);
331 float get_aux13 (void)
333 return fgGetDouble("/fdm-ada/aux13", 0.0);
336 float get_aux14 (void)
338 return fgGetDouble("/fdm-ada/aux14", 0.0);
341 float get_aux15 (void)
343 return fgGetDouble("/fdm-ada/aux15", 0.0);
346 float get_aux16 (void)
348 return fgGetDouble("/fdm-ada/aux16", 0.0);
351 float get_aux17 (void)
353 return fgGetDouble("/fdm-ada/aux17", 0.0);
356 float get_aux18 (void)
358 return fgGetDouble("/fdm-ada/aux18", 0.0);
363 bool fgCockpitInit( fgAIRCRAFT *cur_aircraft )
365 SG_LOG( SG_COCKPIT, SG_INFO, "Initializing cockpit subsystem" );
367 // cockpit->code = 1; /* It will be aircraft dependent */
368 // cockpit->status = 0;
370 // If aircraft has HUD specified we will get the specs from its def
371 // file. For now we will depend upon hard coding in hud?
373 // We must insure that the existing instrument link is purged.
374 // This is done by deleting the links in the list.
376 // HI_Head is now a null pointer so we can generate a new list from the
379 fgHUDInit( cur_aircraft );
384 void fgCockpitUpdate( osg::State* state ) {
386 static const SGPropertyNode * xsize_node = fgGetNode("/sim/startup/xsize");
387 static const SGPropertyNode * ysize_node = fgGetNode("/sim/startup/ysize");
388 static const SGPropertyNode * hud_visibility_node
389 = fgGetNode("/sim/hud/visibility");
391 int iwidth = xsize_node->getIntValue();
392 int iheight = ysize_node->getIntValue();
394 // FIXME: inefficient
395 if ( hud_visibility_node->getBoolValue() ) {
396 // This will check the global hud linked list pointer.
397 // If there is anything to draw it will.
398 fgUpdateHUD( state );
401 glViewport( 0, 0, iwidth, iheight );
413 { "aileronval", get_aileronval },
414 { "altitude", get_altitude },
415 { "anzg", get_anzg },
418 { "climb", get_climb_rate },
419 { "elevatortrimval", get_elev_trimval },
420 { "elevatorval", get_elevatorval },
422 { "framerate", get_frame_rate },
423 { "heading", get_heading },
424 { "latitude", get_latitude },
425 { "longitude", get_longitude },
426 { "mach", get_mach },
427 { "rudderval", get_rudderval },
428 { "speed", get_speed },
429 { "throttleval", get_throttleval },
430 { "view_direction", get_view_direction },
431 { "vfc_tris_culled", get_vfc_tris_culled },
432 { "vfc_tris_drawn", get_vfc_tris_drawn },
434 { "aux1", get_aux1 },
435 { "aux2", get_aux2 },
436 { "aux3", get_aux3 },
437 { "aux4", get_aux4 },
438 { "aux5", get_aux5 },
439 { "aux6", get_aux6 },
440 { "aux7", get_aux7 },
441 { "aux8", get_aux8 },
442 { "aux9", get_aux9 },
443 { "aux10", get_aux10 },
444 { "aux11", get_aux11 },
445 { "aux12", get_aux12 },
446 { "aux13", get_aux13 },
447 { "aux14", get_aux14 },
448 { "aux15", get_aux15 },
449 { "aux16", get_aux16 },
450 { "aux17", get_aux17 },
451 { "aux18", get_aux18 },
457 FLTFNPTR get_func(const char *name)
459 for (int i = 0; fn_table[i].name; i++)
460 if (!strcmp(fn_table[i].name, name))
461 return fn_table[i].func;