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>
29 #include <simgear/sg_inlines.h>
35 #include <simgear/constants.h>
36 #include <simgear/debug/logstream.hxx>
37 #include <simgear/props/props.hxx>
38 #include <simgear/timing/sg_time.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 = fgGetDouble("/orientation/heading-deg") + view_off;
250 SG_NORMALIZE_RANGE(view, 0.0, 360.0);
254 // Added by Markus Hof on 5. Jan 2004
255 float get_dme( void )
257 static const SGPropertyNode * dme_node =
258 fgGetNode("/instrumentation/dme/indicated-distance-nm");
260 return dme_node->getFloatValue();
263 float get_Ax ( void )
265 return fgGetDouble("/accelerations/ned/north-accel-fps_sec", 0.0);
268 float get_anzg ( void )
270 return fgGetDouble("/accelerations/n-z-cg-fps_sec", 0.0);
274 float get_aux1 (void)
276 return fgGetDouble("/fdm-ada/ship-lat", 0.0);
279 float get_aux2 (void)
281 return fgGetDouble("/fdm-ada/ship-lon", 0.0);
284 float get_aux3 (void)
286 return fgGetDouble("/fdm-ada/ship-alt", 0.0);
289 float get_aux4 (void)
291 return fgGetDouble("/fdm-ada/skijump-dist", 0.0);
294 float get_aux5 (void)
296 return fgGetDouble("/fdm-ada/aux5", 0.0);
299 float get_aux6 (void)
301 return fgGetDouble("/fdm-ada/aux6", 0.0);
304 float get_aux7 (void)
306 return fgGetDouble("/fdm-ada/aux7", 0.0);
309 float get_aux8 (void)
311 return fgGetDouble("/fdm-ada/aux8", 0.0);}
313 float get_aux9 (void)
315 return fgGetDouble("/fdm-ada/aux9", 0.0);}
317 float get_aux10 (void)
319 return fgGetDouble("/fdm-ada/aux10", 0.0);
322 float get_aux11 (void)
324 return fgGetDouble("/fdm-ada/aux11", 0.0);
327 float get_aux12 (void)
329 return fgGetDouble("/fdm-ada/aux12", 0.0);
332 float get_aux13 (void)
334 return fgGetDouble("/fdm-ada/aux13", 0.0);
337 float get_aux14 (void)
339 return fgGetDouble("/fdm-ada/aux14", 0.0);
342 float get_aux15 (void)
344 return fgGetDouble("/fdm-ada/aux15", 0.0);
347 float get_aux16 (void)
349 return fgGetDouble("/fdm-ada/aux16", 0.0);
352 float get_aux17 (void)
354 return fgGetDouble("/fdm-ada/aux17", 0.0);
357 float get_aux18 (void)
359 return fgGetDouble("/fdm-ada/aux18", 0.0);
366 SG_LOG( SG_COCKPIT, SG_INFO, "Initializing cockpit subsystem" );
368 // cockpit->code = 1; /* It will be aircraft dependent */
369 // cockpit->status = 0;
371 // If aircraft has HUD specified we will get the specs from its def
372 // file. For now we will depend upon hard coding in hud?
374 // We must insure that the existing instrument link is purged.
375 // This is done by deleting the links in the list.
377 // HI_Head is now a null pointer so we can generate a new list from the
385 void fgCockpitUpdate( osg::State* state ) {
387 static const SGPropertyNode * xsize_node = fgGetNode("/sim/startup/xsize");
388 static const SGPropertyNode * ysize_node = fgGetNode("/sim/startup/ysize");
389 static const SGPropertyNode * hud_visibility_node
390 = fgGetNode("/sim/hud/visibility");
392 int iwidth = xsize_node->getIntValue();
393 int iheight = ysize_node->getIntValue();
395 // FIXME: inefficient
396 if ( hud_visibility_node->getBoolValue() ) {
397 // This will check the global hud linked list pointer.
398 // If there is anything to draw it will.
399 fgUpdateHUD( state );
402 glViewport( 0, 0, iwidth, iheight );
414 { "aileronval", get_aileronval },
415 { "altitude", get_altitude },
416 { "anzg", get_anzg },
419 { "climb", get_climb_rate },
420 { "elevatortrimval", get_elev_trimval },
421 { "elevatorval", get_elevatorval },
423 { "framerate", get_frame_rate },
424 { "heading", get_heading },
425 { "latitude", get_latitude },
426 { "longitude", get_longitude },
427 { "mach", get_mach },
428 { "rudderval", get_rudderval },
429 { "speed", get_speed },
430 { "throttleval", get_throttleval },
431 { "view_direction", get_view_direction },
432 { "vfc_tris_culled", get_vfc_tris_culled },
433 { "vfc_tris_drawn", get_vfc_tris_drawn },
435 { "aux1", get_aux1 },
436 { "aux2", get_aux2 },
437 { "aux3", get_aux3 },
438 { "aux4", get_aux4 },
439 { "aux5", get_aux5 },
440 { "aux6", get_aux6 },
441 { "aux7", get_aux7 },
442 { "aux8", get_aux8 },
443 { "aux9", get_aux9 },
444 { "aux10", get_aux10 },
445 { "aux11", get_aux11 },
446 { "aux12", get_aux12 },
447 { "aux13", get_aux13 },
448 { "aux14", get_aux14 },
449 { "aux15", get_aux15 },
450 { "aux16", get_aux16 },
451 { "aux17", get_aux17 },
452 { "aux18", get_aux18 },
458 FLTFNPTR get_func(const char *name)
460 for (int i = 0; fn_table[i].name; i++)
461 if (!strcmp(fn_table[i].name, name))
462 return fn_table[i].func;