1 // keyboard.cxx -- handle GLUT keyboard events
3 // Written by Curtis Olson, started May 1997.
5 // Copyright (C) 1997 - 1999 Curtis L. Olson - curt@flightgear.org
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.
35 #if defined(FX) && defined(XMESA)
42 #include <pu.h> // plib include
44 #include <Debug/logstream.hxx>
45 #include <Aircraft/aircraft.hxx>
46 #include <Astro/solarsystem.hxx>
47 #include <Astro/sky.hxx>
48 #include <Autopilot/autopilot.hxx>
49 #include <Cockpit/hud.hxx>
51 #include <Include/fg_constants.h>
52 #include <Scenery/tilemgr.hxx>
53 #include <Objects/materialmgr.hxx>
54 #include <Time/fg_time.hxx>
55 #include <Time/light.hxx>
56 #include <Weather/weather.hxx>
58 #include "keyboard.hxx"
59 #include "options.hxx"
62 extern void NewAltitude( puObject *cb );
63 extern void NewHeading( puObject *cb );
65 // Force an update of the sky and lighting parameters
66 static void local_update_sky_and_lighting_params( void ) {
68 SolarSystem::theSolarSystem->rebuild();
69 cur_light_params.Update();
74 // Handle keyboard events
75 void GLUTkey(unsigned char k, int x, int y) {
81 static bool winding_ccw = true;
83 f = current_aircraft.fdm_state;
84 t = FGTime::cur_time_params;
88 FG_LOG( FG_INPUT, FG_DEBUG, "Key hit = " << k );
89 if ( puKeyboard(k, PU_DOWN) ) {
93 if ( GLUT_ACTIVE_ALT && glutGetModifiers() ) {
94 FG_LOG( FG_INPUT, FG_DEBUG, " SHIFTED" );
102 case 18: // Ctrl-R key
104 winding_ccw = !winding_ccw;
106 glFrontFace ( GL_CCW );
108 glFrontFace ( GL_CW );
111 case 19: // Ctrl-S key
112 fgAPToggleAutoThrottle();
114 case 20: // Ctrl-T key
115 fgAPToggleTerrainFollow();
117 case 49: // numeric keypad 1
118 v->set_goal_view_offset( FG_PI * 0.75 );
120 case 50: // numeric keypad 2
121 v->set_goal_view_offset( FG_PI );
123 case 51: // numeric keypad 3
124 v->set_goal_view_offset( FG_PI * 1.25 );
126 case 52: // numeric keypad 4
127 v->set_goal_view_offset( FG_PI * 0.50 );
129 case 54: // numeric keypad 6
130 v->set_goal_view_offset( FG_PI * 1.50 );
132 case 55: // numeric keypad 7
133 v->set_goal_view_offset( FG_PI * 0.25 );
135 case 56: // numeric keypad 8
136 v->set_goal_view_offset( 0.00 );
138 case 57: // numeric keypad 9
139 v->set_goal_view_offset( FG_PI * 1.75 );
142 // status = current_options.get_hud_status();
143 // current_options.set_hud_status(!status);
144 HUD_brightkey( true );
148 fgHUDInit2(¤t_aircraft);
152 local_update_sky_and_lighting_params();
155 current_options.toggle_panel();
158 t->adjust_warp_delta(-30);
159 local_update_sky_and_lighting_params();
162 #if defined(FX) && !defined(WIN32)
163 global_fullscreen = ( !global_fullscreen );
164 # if defined(XMESA_FX_FULLSCREEN) && defined(XMESA_FX_WINDOW)
165 XMesaSetFXmode( global_fullscreen ?
166 XMESA_FX_FULLSCREEN : XMESA_FX_WINDOW );
171 fov = current_options.get_fov();
173 if ( fov > FG_FOV_MAX ) {
176 current_options.set_fov(fov);
177 v->force_update_fov_math();
180 tmp = w->get_visibility(); // in meters
182 w->set_visibility( tmp );
186 FG_LOG( FG_INPUT, FG_DEBUG, "" );
188 case 50: // numeric keypad 2
189 if( fgAPAltitudeEnabled() || fgAPTerrainFollowEnabled() ) {
190 fgAPAltitudeAdjust( 100 );
192 controls.move_elevator(-0.05);
195 case 56: // numeric keypad 8
196 if( fgAPAltitudeEnabled() || fgAPTerrainFollowEnabled() ) {
197 fgAPAltitudeAdjust( -100 );
199 controls.move_elevator(0.05);
202 case 49: // numeric keypad 1
203 controls.move_elevator_trim(-0.001);
205 case 55: // numeric keypad 7
206 controls.move_elevator_trim(0.001);
208 case 52: // numeric keypad 4
209 controls.move_aileron(-0.05);
211 case 54: // numeric keypad 6
212 controls.move_aileron(0.05);
214 case 48: // numeric keypad Ins
215 if( fgAPHeadingEnabled() ) {
216 fgAPHeadingAdjust( -1 );
218 controls.move_rudder(-0.05);
221 case 13: // numeric keypad Enter
222 if( fgAPHeadingEnabled() ) {
223 fgAPHeadingAdjust( 1 );
225 controls.move_rudder(0.05);
228 case 53: // numeric keypad 5
229 controls.set_aileron(0.0);
230 controls.set_elevator(0.0);
231 controls.set_rudder(0.0);
233 case 57: // numeric keypad 9 (Pg Up)
234 if( fgAPAutoThrottleEnabled() ) {
235 fgAPAutoThrottleAdjust( 5 );
237 controls.move_throttle( FGControls::ALL_ENGINES, 0.01 );
240 case 51: // numeric keypad 3 (Pg Dn)
241 if( fgAPAutoThrottleEnabled() ) {
242 fgAPAutoThrottleAdjust( -5 );
244 controls.move_throttle( FGControls::ALL_ENGINES, -0.01 );
250 b_ret = int( controls.get_brake( 0 ) );
251 b_set = double(!b_ret);
252 controls.set_brake( FGControls::ALL_WHEELS, b_set);
255 HUD_brightkey( false );
258 fgHUDInit(¤t_aircraft); // normal HUD
261 t->adjust_warp (+60);
262 local_update_sky_and_lighting_params();
265 t->togglePauseMode();
266 // printf position and attitude information
267 FG_LOG( FG_INPUT, FG_INFO,
268 "Lon = " << f->get_Longitude() * RAD_TO_DEG
269 << " Lat = " << f->get_Latitude() * RAD_TO_DEG
270 << " Altitude = " << f->get_Altitude() * FEET_TO_METER );
271 FG_LOG( FG_INPUT, FG_INFO,
272 "Heading = " << f->get_Psi() * RAD_TO_DEG
273 << " Roll = " << f->get_Phi() * RAD_TO_DEG
274 << " Pitch = " << f->get_Theta() * RAD_TO_DEG );
277 t->adjust_warp_delta (+30);
278 local_update_sky_and_lighting_params();
281 v->cycle_view_mode();
284 fov = current_options.get_fov();
286 if ( fov < FG_FOV_MIN ) {
289 current_options.set_fov(fov);
290 v->force_update_fov_math();
293 tmp = w->get_visibility(); // in meters
295 w->set_visibility( tmp );
298 // if( fg_DebugOutput ) {
299 // fclose( fg_DebugOutput );
301 FG_LOG( FG_INPUT, FG_ALERT,
302 "Program exiting normally at user request." );
310 // Handle "special" keyboard events
311 void GLUTspecialkey(int k, int x, int y) {
316 FG_LOG( FG_INPUT, FG_DEBUG, "Special key hit = " << k );
318 if ( puKeyboard(k + PU_KEY_GLUT_SPECIAL_OFFSET, PU_DOWN) ) {
322 if ( GLUT_ACTIVE_SHIFT && glutGetModifiers() ) {
323 FG_LOG( FG_INPUT, FG_DEBUG, " SHIFTED" );
325 case GLUT_KEY_END: // numeric keypad 1
326 v->set_goal_view_offset( FG_PI * 0.75 );
328 case GLUT_KEY_DOWN: // numeric keypad 2
329 v->set_goal_view_offset( FG_PI );
331 case GLUT_KEY_PAGE_DOWN: // numeric keypad 3
332 v->set_goal_view_offset( FG_PI * 1.25 );
334 case GLUT_KEY_LEFT: // numeric keypad 4
335 v->set_goal_view_offset( FG_PI * 0.50 );
337 case GLUT_KEY_RIGHT: // numeric keypad 6
338 v->set_goal_view_offset( FG_PI * 1.50 );
340 case GLUT_KEY_HOME: // numeric keypad 7
341 v->set_goal_view_offset( FG_PI * 0.25 );
343 case GLUT_KEY_UP: // numeric keypad 8
344 v->set_goal_view_offset( 0.00 );
346 case GLUT_KEY_PAGE_UP: // numeric keypad 9
347 v->set_goal_view_offset( FG_PI * 1.75 );
351 FG_LOG( FG_INPUT, FG_DEBUG, "" );
353 case GLUT_KEY_F2: // F2 Reload Tile Cache...
356 FG_LOG(FG_INPUT, FG_INFO, "ReIniting TileCache");
357 FGTime *t = FGTime::cur_time_params;
358 if( (toggle_pause = !t->getPause()) )
359 t->togglePauseMode();
361 if( global_tile_mgr.init() ) {
362 // Load the local scenery data
363 global_tile_mgr.update();
365 FG_LOG( FG_GENERAL, FG_ALERT,
366 "Error in Tile Manager initialization!" );
371 t->togglePauseMode();
374 case GLUT_KEY_F8: // F8 toggles fog ... off fastest nicest...
375 current_options.cycle_fog();
377 if ( current_options.get_fog() == fgOPTIONS::FG_FOG_DISABLED ) {
378 FG_LOG( FG_INPUT, FG_INFO, "Fog disabled" );
379 } else if ( current_options.get_fog() ==
380 fgOPTIONS::FG_FOG_FASTEST )
382 FG_LOG( FG_INPUT, FG_INFO,
383 "Fog enabled, hint set to fastest" );
384 } else if ( current_options.get_fog() ==
385 fgOPTIONS::FG_FOG_NICEST )
387 FG_LOG( FG_INPUT, FG_INFO,
388 "Fog enabled, hint set to nicest" );
392 case GLUT_KEY_F9: // F9 toggles textures on and off...
393 if ( material_mgr.loaded() ) {
394 current_options.get_textures() ?
395 current_options.set_textures(false) :
396 current_options.set_textures(true);
397 FG_LOG( FG_INPUT, FG_INFO, "Toggling texture" );
399 FG_LOG( FG_INPUT, FG_INFO,
400 "No textures loaded, cannot toggle" );
403 case GLUT_KEY_F10: // F10 toggles menu on and off...
404 FG_LOG(FG_INPUT, FG_INFO, "Invoking call back function");
407 case GLUT_KEY_F11: // F11 Altitude Dialog.
408 FG_LOG(FG_INPUT, FG_INFO, "Invoking Altitude call back function");
411 case GLUT_KEY_F12: // F12 Heading Dialog...
412 FG_LOG(FG_INPUT, FG_INFO, "Invoking Heading call back function");
416 if( fgAPAltitudeEnabled() || fgAPTerrainFollowEnabled() ) {
417 fgAPAltitudeAdjust( -100 );
419 controls.move_elevator(0.05);
423 if( fgAPAltitudeEnabled() || fgAPTerrainFollowEnabled() ) {
424 fgAPAltitudeAdjust( 100 );
426 controls.move_elevator(-0.05);
430 controls.move_aileron(-0.05);
433 controls.move_aileron(0.05);
435 case GLUT_KEY_HOME: // numeric keypad 1
436 controls.move_elevator_trim(0.001);
438 case GLUT_KEY_END: // numeric keypad 7
439 controls.move_elevator_trim(-0.001);
441 case GLUT_KEY_INSERT: // numeric keypad Ins
442 if( fgAPHeadingEnabled() ) {
443 fgAPHeadingAdjust( -1 );
445 controls.move_rudder(-0.05);
448 case 13: // numeric keypad Enter
449 if( fgAPHeadingEnabled() ) {
450 fgAPHeadingAdjust( 1 );
452 controls.move_rudder(0.05);
455 case 53: // numeric keypad 5
456 controls.set_aileron(0.0);
457 controls.set_elevator(0.0);
458 controls.set_rudder(0.0);
460 case GLUT_KEY_PAGE_UP: // numeric keypad 9 (Pg Up)
461 if( fgAPAutoThrottleEnabled() ) {
462 fgAPAutoThrottleAdjust( 5 );
464 controls.move_throttle( FGControls::ALL_ENGINES, 0.01 );
467 case GLUT_KEY_PAGE_DOWN: // numeric keypad 3 (Pg Dn)
468 if( fgAPAutoThrottleEnabled() ) {
469 fgAPAutoThrottleAdjust( -5 );
471 controls.move_throttle( FGControls::ALL_ENGINES, -0.01 );