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 <Include/general.hxx>
41 #include <Main/globals.hxx>
42 #include <Main/fg_props.hxx>
43 #include <Main/viewmgr.hxx>
44 #include <Main/viewer.hxx>
45 #include <Scenery/scenery.hxx>
48 #include "cockpit.hxx"
51 // The following routines obtain information concerntin the aircraft's
52 // current state and return it to calling instrument display routines.
53 // They should eventually be member functions of the aircraft.
56 float get_latitude( void )
58 return fgGetDouble("/position/latitude-deg");
61 float get_lat_min( void )
65 a = fgGetDouble("/position/latitude-deg");
69 d = (double) ( (int) a);
70 float lat_min = (a - d) * 60.0;
76 float get_longitude( void )
78 return fgGetDouble("/position/longitude-deg");
83 get_formated_gmt_time( void )
86 const struct tm *p = globals->get_time_params()->getGmt();
87 sprintf( buf, "%d/%d/%4d %d:%02d:%02d",
88 p->tm_mon+1, p->tm_mday, 1900 + p->tm_year,
89 p->tm_hour, p->tm_min, p->tm_sec);
95 float get_long_min( void )
98 a = fgGetDouble("/position/longitude-deg");
102 d = (double) ( (int) a);
103 float lon_min = (a - d) * 60.0;
108 float get_throttleval( void )
110 // Hack limiting to one engine
111 return globals->get_controls()->get_throttle( 0 );
114 float get_aileronval( void )
116 return globals->get_controls()->get_aileron();
119 float get_elevatorval( void )
121 return globals->get_controls()->get_elevator();
124 float get_elev_trimval( void )
126 return globals->get_controls()->get_elevator_trim();
129 float get_rudderval( void )
131 return globals->get_controls()->get_rudder();
134 float get_speed( void )
136 static const SGPropertyNode * speedup_node = fgGetNode("/sim/speed-up");
138 float speed = fgGetDouble("/velocities/airspeed-kt")
139 * speedup_node->getIntValue();
146 return fgGetDouble("/velocities/mach");
149 float get_aoa( void )
151 return fgGetDouble("/orientation/alpha-deg");
154 float get_roll( void )
156 return fgGetDouble("/orientation/roll-deg") * SG_DEGREES_TO_RADIANS;
159 float get_pitch( void )
161 return fgGetDouble("/orientation/pitch-deg") * SG_DEGREES_TO_RADIANS;
164 float get_heading( void )
166 return fgGetDouble("/orientation/heading-deg");
169 float get_altitude( void )
171 static const SGPropertyNode *startup_units_node
172 = fgGetNode("/sim/startup/units");
174 if ( !strcmp(startup_units_node->getStringValue(), "feet") ) {
175 return fgGetDouble("/position/altitude-ft");
177 return fgGetDouble("/position/altitude-ft") * SG_FEET_TO_METER;
181 float get_agl( void )
183 static const SGPropertyNode *startup_units_node
184 = fgGetNode("/sim/startup/units");
186 if ( !strcmp(startup_units_node->getStringValue(), "feet") ) {
187 return fgGetDouble("/position/altitude-agl-ft");
189 return fgGetDouble("/position/altitude-agl-ft") * SG_FEET_TO_METER;
193 float get_sideslip( void )
195 return fgGetDouble("/orientation/side-slip-rad");
198 float get_frame_rate( void )
200 return general.get_frame_rate();
203 float get_fov( void )
205 return globals->get_current_view()->get_fov();
208 float get_vfc_ratio( void )
210 // float vfc = current_view.get_vfc_ratio();
215 float get_vfc_tris_drawn ( void )
217 // float rendered = current_view.get_tris_rendered();
218 // return (rendered);
222 float get_vfc_tris_culled ( void )
224 // float culled = current_view.get_tris_culled();
229 float get_climb_rate( void )
231 static const SGPropertyNode *startup_units_node
232 = fgGetNode("/sim/startup/units");
234 float climb_rate = fgGetDouble("/velocities/vertical-speed-fps", 0.0);
235 if ( !strcmp(startup_units_node->getStringValue(), "feet") ) {
238 climb_rate *= SG_FEET_TO_METER * 60.0;
245 float get_view_direction( void )
247 double view_off = 360.0 - globals->get_current_view()->getHeadingOffset_deg();
248 double view = SGMiscd::normalizeAngle(fgGetDouble("/orientation/heading-deg") + view_off);
252 // Added by Markus Hof on 5. Jan 2004
253 float get_dme( void )
255 static const SGPropertyNode * dme_node =
256 fgGetNode("/instrumentation/dme/indicated-distance-nm");
258 return dme_node->getFloatValue();
261 float get_Ax ( void )
263 return fgGetDouble("/accelerations/ned/north-accel-fps_sec", 0.0);
266 float get_anzg ( void )
268 return fgGetDouble("/accelerations/n-z-cg-fps_sec", 0.0);
272 float get_aux1 (void)
274 return fgGetDouble("/fdm-ada/ship-lat", 0.0);
277 float get_aux2 (void)
279 return fgGetDouble("/fdm-ada/ship-lon", 0.0);
282 float get_aux3 (void)
284 return fgGetDouble("/fdm-ada/ship-alt", 0.0);
287 float get_aux4 (void)
289 return fgGetDouble("/fdm-ada/skijump-dist", 0.0);
292 float get_aux5 (void)
294 return fgGetDouble("/fdm-ada/aux5", 0.0);
297 float get_aux6 (void)
299 return fgGetDouble("/fdm-ada/aux6", 0.0);
302 float get_aux7 (void)
304 return fgGetDouble("/fdm-ada/aux7", 0.0);
307 float get_aux8 (void)
309 return fgGetDouble("/fdm-ada/aux8", 0.0);}
311 float get_aux9 (void)
313 return fgGetDouble("/fdm-ada/aux9", 0.0);}
315 float get_aux10 (void)
317 return fgGetDouble("/fdm-ada/aux10", 0.0);
320 float get_aux11 (void)
322 return fgGetDouble("/fdm-ada/aux11", 0.0);
325 float get_aux12 (void)
327 return fgGetDouble("/fdm-ada/aux12", 0.0);
330 float get_aux13 (void)
332 return fgGetDouble("/fdm-ada/aux13", 0.0);
335 float get_aux14 (void)
337 return fgGetDouble("/fdm-ada/aux14", 0.0);
340 float get_aux15 (void)
342 return fgGetDouble("/fdm-ada/aux15", 0.0);
345 float get_aux16 (void)
347 return fgGetDouble("/fdm-ada/aux16", 0.0);
350 float get_aux17 (void)
352 return fgGetDouble("/fdm-ada/aux17", 0.0);
355 float get_aux18 (void)
357 return fgGetDouble("/fdm-ada/aux18", 0.0);
364 SG_LOG( SG_COCKPIT, SG_INFO, "Initializing cockpit subsystem" );
366 // cockpit->code = 1; /* It will be aircraft dependent */
367 // cockpit->status = 0;
369 // If aircraft has HUD specified we will get the specs from its def
370 // file. For now we will depend upon hard coding in hud?
372 // We must insure that the existing instrument link is purged.
373 // This is done by deleting the links in the list.
375 // HI_Head is now a null pointer so we can generate a new list from the
383 void fgCockpitUpdate( osg::State* state ) {
385 static const SGPropertyNode * xsize_node = fgGetNode("/sim/startup/xsize");
386 static const SGPropertyNode * ysize_node = fgGetNode("/sim/startup/ysize");
387 static const SGPropertyNode * hud_visibility_node
388 = fgGetNode("/sim/hud/visibility");
390 int iwidth = xsize_node->getIntValue();
391 int iheight = ysize_node->getIntValue();
393 // FIXME: inefficient
394 if ( hud_visibility_node->getBoolValue() ) {
395 // This will check the global hud linked list pointer.
396 // If there is anything to draw it will.
397 fgUpdateHUD( state );
400 glViewport( 0, 0, iwidth, iheight );
412 { "aileronval", get_aileronval },
413 { "altitude", get_altitude },
414 { "anzg", get_anzg },
417 { "climb", get_climb_rate },
418 { "elevatortrimval", get_elev_trimval },
419 { "elevatorval", get_elevatorval },
421 { "framerate", get_frame_rate },
422 { "heading", get_heading },
423 { "latitude", get_latitude },
424 { "longitude", get_longitude },
425 { "mach", get_mach },
426 { "rudderval", get_rudderval },
427 { "speed", get_speed },
428 { "throttleval", get_throttleval },
429 { "view_direction", get_view_direction },
430 { "vfc_tris_culled", get_vfc_tris_culled },
431 { "vfc_tris_drawn", get_vfc_tris_drawn },
433 { "aux1", get_aux1 },
434 { "aux2", get_aux2 },
435 { "aux3", get_aux3 },
436 { "aux4", get_aux4 },
437 { "aux5", get_aux5 },
438 { "aux6", get_aux6 },
439 { "aux7", get_aux7 },
440 { "aux8", get_aux8 },
441 { "aux9", get_aux9 },
442 { "aux10", get_aux10 },
443 { "aux11", get_aux11 },
444 { "aux12", get_aux12 },
445 { "aux13", get_aux13 },
446 { "aux14", get_aux14 },
447 { "aux15", get_aux15 },
448 { "aux16", get_aux16 },
449 { "aux17", get_aux17 },
450 { "aux18", get_aux18 },
456 FLTFNPTR get_func(const char *name)
458 for (int i = 0; fn_table[i].name; i++)
459 if (!strcmp(fn_table[i].name, name))
460 return fn_table[i].func;