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., 675 Mass Ave, Cambridge, MA 02139, USA.
39 #include <Aircraft/aircraft.hxx>
40 #include <Debug/logstream.hxx>
41 #include <Include/fg_constants.h>
42 #include <Include/general.hxx>
43 #include <Main/options.hxx>
44 #include <Main/views.hxx>
45 #include <Math/fg_random.h>
46 #include <Math/mat3.h>
47 #include <Math/polar3d.hxx>
48 #include <Scenery/scenery.hxx>
49 #include <Time/fg_timer.hxx>
51 #include "cockpit.hxx"
55 // This is a structure that contains all data related to
56 // cockpit/panel/hud system
58 static pCockpit ac_cockpit;
60 // The following routines obtain information concerntin the aircraft's
61 // current state and return it to calling instrument display routines.
62 // They should eventually be member functions of the aircraft.
64 double get_latitude( void )
66 return((double)((int)( current_aircraft.fdm_state->get_Latitude()
70 double get_lat_min( void )
74 a = current_aircraft.fdm_state->get_Latitude() * RAD_TO_DEG;
78 d = (double) ( (int) a);
79 return( (a - d) * 60.0);
82 double get_longitude( void )
84 return( (double)((int) (current_aircraft.fdm_state->get_Longitude()
88 double get_long_min( void )
92 a = current_aircraft.fdm_state->get_Longitude() * RAD_TO_DEG;
96 d = (double) ( (int) a);
97 return( (a - d) * 60.0);
100 double get_throttleval( void )
102 return controls.get_throttle( 0 ); // Hack limiting to one engine
105 double get_aileronval( void )
107 return controls.get_aileron();
110 double get_elevatorval( void )
112 return controls.get_elevator();
115 double get_elev_trimval( void )
117 return controls.get_elevator_trim();
120 double get_rudderval( void )
122 return controls.get_rudder();
125 double get_speed( void )
127 return( current_aircraft.fdm_state->get_V_equiv_kts() );
130 double get_aoa( void )
132 return( current_aircraft.fdm_state->get_Alpha() * RAD_TO_DEG );
135 double get_roll( void )
137 return( current_aircraft.fdm_state->get_Phi() );
140 double get_pitch( void )
142 return( current_aircraft.fdm_state->get_Theta() );
145 double get_heading( void )
147 return( current_aircraft.fdm_state->get_Psi() * RAD_TO_DEG );
150 double get_altitude( void )
152 if ( current_options.get_units() == fgOPTIONS::FG_UNITS_FEET ) {
153 return current_aircraft.fdm_state->get_Altitude();
155 return current_aircraft.fdm_state->get_Altitude() * FEET_TO_METER;
159 double get_agl( void )
161 if ( current_options.get_units() == fgOPTIONS::FG_UNITS_FEET ) {
162 return current_aircraft.fdm_state->get_Altitude()
163 - scenery.cur_elev * METER_TO_FEET;
165 return current_aircraft.fdm_state->get_Altitude() * FEET_TO_METER
170 double get_sideslip( void )
172 return( current_aircraft.fdm_state->get_Beta() );
175 double get_frame_rate( void )
177 return (double) general.get_frame_rate();
180 double get_fov( void )
182 return (current_options.get_fov());
185 double get_vfc_ratio( void )
187 return current_view.get_vfc_ratio();
190 double get_vfc_tris_drawn ( void )
192 return current_view.get_tris_rendered();
195 double get_climb_rate( void )
197 if ( current_options.get_units() == fgOPTIONS::FG_UNITS_FEET ) {
198 return current_aircraft.fdm_state->get_Climb_Rate() * 60.0;
200 return current_aircraft.fdm_state->get_Climb_Rate()
201 * FEET_TO_METER * 60.0;
206 bool fgCockpitInit( fgAIRCRAFT *cur_aircraft )
208 FG_LOG( FG_COCKPIT, FG_INFO, "Initializing cockpit subsystem" );
210 // cockpit->code = 1; /* It will be aircraft dependent */
211 // cockpit->status = 0;
213 // If aircraft has HUD specified we will get the specs from its def
214 // file. For now we will depend upon hard coding in hud?
216 // We must insure that the existing instrument link is purged.
217 // This is done by deleting the links in the list.
219 // HI_Head is now a null pointer so we can generate a new list from the
222 fgHUDInit( cur_aircraft );
223 ac_cockpit = new fg_Cockpit();
225 if ( current_options.get_panel_status() ) {
229 FG_LOG( FG_COCKPIT, FG_INFO,
230 " Code " << ac_cockpit->code() << " Status "
231 << ac_cockpit->status() );
237 void fgCockpitUpdate( void ) {
238 FG_LOG( FG_COCKPIT, FG_DEBUG,
239 "Cockpit: code " << ac_cockpit->code() << " status "
240 << ac_cockpit->status() );
242 if ( current_options.get_hud_status() ) {
243 // This will check the global hud linked list pointer.
244 // If these is anything to draw it will.
248 if ( current_options.get_panel_status() &&
249 (fabs( current_view.get_view_offset() ) < 0.2) )
252 current_view.get_winWidth(),
253 current_view.get_winHeight() );
254 FGPanel::OurPanel->Update();