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>
57 #include <WeatherCM/FGLocalWeatherDatabase.h>
59 #include "keyboard.hxx"
60 #include "options.hxx"
63 extern void NewAltitude( puObject *cb );
64 extern void NewHeading( puObject *cb );
66 // Force an update of the sky and lighting parameters
67 static void local_update_sky_and_lighting_params( void ) {
69 SolarSystem::theSolarSystem->rebuild();
70 cur_light_params.Update();
75 // Handle keyboard events
76 void GLUTkey(unsigned char k, int x, int y) {
82 static bool winding_ccw = true;
85 f = current_aircraft.fdm_state;
86 t = FGTime::cur_time_params;
88 // w = ¤t_weather;
90 FG_LOG( FG_INPUT, FG_DEBUG, "Key hit = " << k );
91 if ( puKeyboard(k, PU_DOWN) ) {
95 if ( GLUT_ACTIVE_ALT && glutGetModifiers() ) {
96 FG_LOG( FG_INPUT, FG_DEBUG, " SHIFTED" );
101 case 8: // Ctrl-H key
104 case 18: // Ctrl-R key
106 winding_ccw = !winding_ccw;
108 glFrontFace ( GL_CCW );
110 glFrontFace ( GL_CW );
113 case 19: // Ctrl-S key
114 fgAPToggleAutoThrottle();
116 case 20: // Ctrl-T key
117 fgAPToggleTerrainFollow();
119 case 49: // numeric keypad 1
120 v->set_goal_view_offset( FG_PI * 0.75 );
122 case 50: // numeric keypad 2
123 v->set_goal_view_offset( FG_PI );
125 case 51: // numeric keypad 3
126 v->set_goal_view_offset( FG_PI * 1.25 );
128 case 52: // numeric keypad 4
129 v->set_goal_view_offset( FG_PI * 0.50 );
131 case 54: // numeric keypad 6
132 v->set_goal_view_offset( FG_PI * 1.50 );
134 case 55: // numeric keypad 7
135 v->set_goal_view_offset( FG_PI * 0.25 );
137 case 56: // numeric keypad 8
138 v->set_goal_view_offset( 0.00 );
140 case 57: // numeric keypad 9
141 v->set_goal_view_offset( FG_PI * 1.75 );
144 speed = current_options.get_speed_up();
149 current_options.set_speed_up( speed );
152 // status = current_options.get_hud_status();
153 // current_options.set_hud_status(!status);
154 HUD_brightkey( true );
158 fgHUDInit2(¤t_aircraft);
162 local_update_sky_and_lighting_params();
165 current_options.toggle_panel();
168 t->adjust_warp_delta(-30);
169 local_update_sky_and_lighting_params();
172 #if defined(FX) && !defined(WIN32)
173 global_fullscreen = ( !global_fullscreen );
174 # if defined(XMESA_FX_FULLSCREEN) && defined(XMESA_FX_WINDOW)
175 XMesaSetFXmode( global_fullscreen ?
176 XMESA_FX_FULLSCREEN : XMESA_FX_WINDOW );
181 fov = current_options.get_fov();
183 if ( fov > FG_FOV_MAX ) {
186 current_options.set_fov(fov);
187 v->force_update_fov_math();
190 // tmp = w->get_visibility(); // in meters
192 // w->set_visibility( tmp );
193 tmp = WeatherDatabase->getWeatherVisibility();
195 WeatherDatabase->setWeatherVisibility( tmp );
199 FG_LOG( FG_INPUT, FG_DEBUG, "" );
201 case 50: // numeric keypad 2
202 if( fgAPAltitudeEnabled() || fgAPTerrainFollowEnabled() ) {
203 fgAPAltitudeAdjust( 100 );
205 controls.move_elevator(-0.05);
208 case 56: // numeric keypad 8
209 if( fgAPAltitudeEnabled() || fgAPTerrainFollowEnabled() ) {
210 fgAPAltitudeAdjust( -100 );
212 controls.move_elevator(0.05);
215 case 49: // numeric keypad 1
216 controls.move_elevator_trim(-0.001);
218 case 55: // numeric keypad 7
219 controls.move_elevator_trim(0.001);
221 case 52: // numeric keypad 4
222 controls.move_aileron(-0.05);
224 case 54: // numeric keypad 6
225 controls.move_aileron(0.05);
227 case 48: // numeric keypad Ins
228 if( fgAPHeadingEnabled() ) {
229 fgAPHeadingAdjust( -1 );
231 controls.move_rudder(-0.05);
234 case 13: // numeric keypad Enter
235 if( fgAPHeadingEnabled() ) {
236 fgAPHeadingAdjust( 1 );
238 controls.move_rudder(0.05);
241 case 53: // numeric keypad 5
242 controls.set_aileron(0.0);
243 controls.set_elevator(0.0);
244 controls.set_rudder(0.0);
246 case 57: // numeric keypad 9 (Pg Up)
247 if( fgAPAutoThrottleEnabled() ) {
248 fgAPAutoThrottleAdjust( 5 );
250 controls.move_throttle( FGControls::ALL_ENGINES, 0.01 );
253 case 51: // numeric keypad 3 (Pg Dn)
254 if( fgAPAutoThrottleEnabled() ) {
255 fgAPAutoThrottleAdjust( -5 );
257 controls.move_throttle( FGControls::ALL_ENGINES, -0.01 );
261 speed = current_options.get_speed_up();
263 current_options.set_speed_up( speed );
268 b_ret = int( controls.get_brake( 0 ) );
269 b_set = double(!b_ret);
270 controls.set_brake( FGControls::ALL_WHEELS, b_set);
273 HUD_brightkey( false );
276 fgHUDInit(¤t_aircraft); // normal HUD
279 t->adjust_warp (+60);
280 local_update_sky_and_lighting_params();
283 t->togglePauseMode();
284 // printf position and attitude information
285 FG_LOG( FG_INPUT, FG_INFO,
286 "Lon = " << f->get_Longitude() * RAD_TO_DEG
287 << " Lat = " << f->get_Latitude() * RAD_TO_DEG
288 << " Altitude = " << f->get_Altitude() * FEET_TO_METER );
289 FG_LOG( FG_INPUT, FG_INFO,
290 "Heading = " << f->get_Psi() * RAD_TO_DEG
291 << " Roll = " << f->get_Phi() * RAD_TO_DEG
292 << " Pitch = " << f->get_Theta() * RAD_TO_DEG );
295 t->adjust_warp_delta (+30);
296 local_update_sky_and_lighting_params();
299 v->cycle_view_mode();
302 fov = current_options.get_fov();
304 if ( fov < FG_FOV_MIN ) {
307 current_options.set_fov(fov);
308 v->force_update_fov_math();
311 // tmp = w->get_visibility(); // in meters
313 // w->set_visibility( tmp );
314 tmp = WeatherDatabase->getWeatherVisibility();
316 WeatherDatabase->setWeatherVisibility( tmp );
319 // if( fg_DebugOutput ) {
320 // fclose( fg_DebugOutput );
322 FG_LOG( FG_INPUT, FG_ALERT,
323 "Program exiting normally at user request." );
331 // Handle "special" keyboard events
332 void GLUTspecialkey(int k, int x, int y) {
337 FG_LOG( FG_INPUT, FG_DEBUG, "Special key hit = " << k );
339 if ( puKeyboard(k + PU_KEY_GLUT_SPECIAL_OFFSET, PU_DOWN) ) {
343 if ( GLUT_ACTIVE_SHIFT && glutGetModifiers() ) {
344 FG_LOG( FG_INPUT, FG_DEBUG, " SHIFTED" );
346 case GLUT_KEY_END: // numeric keypad 1
347 v->set_goal_view_offset( FG_PI * 0.75 );
349 case GLUT_KEY_DOWN: // numeric keypad 2
350 v->set_goal_view_offset( FG_PI );
352 case GLUT_KEY_PAGE_DOWN: // numeric keypad 3
353 v->set_goal_view_offset( FG_PI * 1.25 );
355 case GLUT_KEY_LEFT: // numeric keypad 4
356 v->set_goal_view_offset( FG_PI * 0.50 );
358 case GLUT_KEY_RIGHT: // numeric keypad 6
359 v->set_goal_view_offset( FG_PI * 1.50 );
361 case GLUT_KEY_HOME: // numeric keypad 7
362 v->set_goal_view_offset( FG_PI * 0.25 );
364 case GLUT_KEY_UP: // numeric keypad 8
365 v->set_goal_view_offset( 0.00 );
367 case GLUT_KEY_PAGE_UP: // numeric keypad 9
368 v->set_goal_view_offset( FG_PI * 1.75 );
372 FG_LOG( FG_INPUT, FG_DEBUG, "" );
374 case GLUT_KEY_F2: // F2 Reload Tile Cache...
377 FG_LOG(FG_INPUT, FG_INFO, "ReIniting TileCache");
378 FGTime *t = FGTime::cur_time_params;
379 if( (toggle_pause = !t->getPause()) )
380 t->togglePauseMode();
382 if( global_tile_mgr.init() ) {
383 // Load the local scenery data
384 global_tile_mgr.update();
386 FG_LOG( FG_GENERAL, FG_ALERT,
387 "Error in Tile Manager initialization!" );
392 t->togglePauseMode();
395 case GLUT_KEY_F8: // F8 toggles fog ... off fastest nicest...
396 current_options.cycle_fog();
398 if ( current_options.get_fog() == fgOPTIONS::FG_FOG_DISABLED ) {
399 FG_LOG( FG_INPUT, FG_INFO, "Fog disabled" );
400 } else if ( current_options.get_fog() ==
401 fgOPTIONS::FG_FOG_FASTEST )
403 FG_LOG( FG_INPUT, FG_INFO,
404 "Fog enabled, hint set to fastest" );
405 } else if ( current_options.get_fog() ==
406 fgOPTIONS::FG_FOG_NICEST )
408 FG_LOG( FG_INPUT, FG_INFO,
409 "Fog enabled, hint set to nicest" );
413 case GLUT_KEY_F9: // F9 toggles textures on and off...
414 if ( material_mgr.loaded() ) {
415 current_options.get_textures() ?
416 current_options.set_textures(false) :
417 current_options.set_textures(true);
418 FG_LOG( FG_INPUT, FG_INFO, "Toggling texture" );
420 FG_LOG( FG_INPUT, FG_INFO,
421 "No textures loaded, cannot toggle" );
424 case GLUT_KEY_F10: // F10 toggles menu on and off...
425 FG_LOG(FG_INPUT, FG_INFO, "Invoking call back function");
428 case GLUT_KEY_F11: // F11 Altitude Dialog.
429 FG_LOG(FG_INPUT, FG_INFO, "Invoking Altitude call back function");
432 case GLUT_KEY_F12: // F12 Heading Dialog...
433 FG_LOG(FG_INPUT, FG_INFO, "Invoking Heading call back function");
437 if( fgAPAltitudeEnabled() || fgAPTerrainFollowEnabled() ) {
438 fgAPAltitudeAdjust( -100 );
440 controls.move_elevator(0.05);
444 if( fgAPAltitudeEnabled() || fgAPTerrainFollowEnabled() ) {
445 fgAPAltitudeAdjust( 100 );
447 controls.move_elevator(-0.05);
451 controls.move_aileron(-0.05);
454 controls.move_aileron(0.05);
456 case GLUT_KEY_HOME: // numeric keypad 1
457 controls.move_elevator_trim(0.001);
459 case GLUT_KEY_END: // numeric keypad 7
460 controls.move_elevator_trim(-0.001);
462 case GLUT_KEY_INSERT: // numeric keypad Ins
463 if( fgAPHeadingEnabled() ) {
464 fgAPHeadingAdjust( -1 );
466 controls.move_rudder(-0.05);
469 case 13: // numeric keypad Enter
470 if( fgAPHeadingEnabled() ) {
471 fgAPHeadingAdjust( 1 );
473 controls.move_rudder(0.05);
476 case 53: // numeric keypad 5
477 controls.set_aileron(0.0);
478 controls.set_elevator(0.0);
479 controls.set_rudder(0.0);
481 case GLUT_KEY_PAGE_UP: // numeric keypad 9 (Pg Up)
482 if( fgAPAutoThrottleEnabled() ) {
483 fgAPAutoThrottleAdjust( 5 );
485 controls.move_throttle( FGControls::ALL_ENGINES, 0.01 );
488 case GLUT_KEY_PAGE_DOWN: // numeric keypad 3 (Pg Dn)
489 if( fgAPAutoThrottleEnabled() ) {
490 fgAPAutoThrottleAdjust( -5 );
492 controls.move_throttle( FGControls::ALL_ENGINES, -0.01 );