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 <Misc/fgpath.hxx>
53 #include <Scenery/tilemgr.hxx>
54 #include <Objects/materialmgr.hxx>
55 #include <Time/fg_time.hxx>
56 #include <Time/light.hxx>
58 #ifndef FG_OLD_WEATHER
59 # include <WeatherCM/FGLocalWeatherDatabase.h>
61 # include <Weather/weather.hxx>
64 #include "keyboard.hxx"
65 #include "options.hxx"
68 extern void NewAltitude( puObject *cb );
69 extern void NewHeading( puObject *cb );
71 // Force an update of the sky and lighting parameters
72 static void local_update_sky_and_lighting_params( void ) {
74 SolarSystem::theSolarSystem->rebuild();
75 cur_light_params.Update();
80 // Handle keyboard events
81 void GLUTkey(unsigned char k, int x, int y) {
86 static bool winding_ccw = true;
89 f = current_aircraft.fdm_state;
90 t = FGTime::cur_time_params;
93 FG_LOG( FG_INPUT, FG_DEBUG, "Key hit = " << k );
94 if ( puKeyboard(k, PU_DOWN) ) {
98 if ( GLUT_ACTIVE_ALT && glutGetModifiers() ) {
99 FG_LOG( FG_INPUT, FG_DEBUG, " SHIFTED" );
101 case 1: // Ctrl-A key
102 fgAPToggleAltitude();
104 case 8: // Ctrl-H key
107 case 18: // Ctrl-R key
109 winding_ccw = !winding_ccw;
111 glFrontFace ( GL_CCW );
113 glFrontFace ( GL_CW );
116 case 19: // Ctrl-S key
117 fgAPToggleAutoThrottle();
119 case 20: // Ctrl-T key
120 fgAPToggleTerrainFollow();
122 case 49: // numeric keypad 1
123 v->set_goal_view_offset( FG_PI * 0.75 );
125 case 50: // numeric keypad 2
126 v->set_goal_view_offset( FG_PI );
128 case 51: // numeric keypad 3
129 v->set_goal_view_offset( FG_PI * 1.25 );
131 case 52: // numeric keypad 4
132 v->set_goal_view_offset( FG_PI * 0.50 );
134 case 54: // numeric keypad 6
135 v->set_goal_view_offset( FG_PI * 1.50 );
137 case 55: // numeric keypad 7
138 v->set_goal_view_offset( FG_PI * 0.25 );
140 case 56: // numeric keypad 8
141 v->set_goal_view_offset( 0.00 );
143 case 57: // numeric keypad 9
144 v->set_goal_view_offset( FG_PI * 1.75 );
147 speed = current_options.get_speed_up();
152 current_options.set_speed_up( speed );
155 // status = current_options.get_hud_status();
156 // current_options.set_hud_status(!status);
157 HUD_brightkey( true );
161 fgHUDInit2(¤t_aircraft);
165 local_update_sky_and_lighting_params();
168 current_options.toggle_panel();
171 t->adjust_warp_delta(-30);
172 local_update_sky_and_lighting_params();
175 #if defined(FX) && !defined(WIN32)
176 global_fullscreen = ( !global_fullscreen );
177 # if defined(XMESA_FX_FULLSCREEN) && defined(XMESA_FX_WINDOW)
178 XMesaSetFXmode( global_fullscreen ?
179 XMESA_FX_FULLSCREEN : XMESA_FX_WINDOW );
184 fov = current_options.get_fov();
186 if ( fov > FG_FOV_MAX ) {
189 current_options.set_fov(fov);
190 v->force_update_fov_math();
193 #ifndef FG_OLD_WEATHER
194 tmp = WeatherDatabase->getWeatherVisibility();
196 WeatherDatabase->setWeatherVisibility( tmp );
198 tmp = current_weather.get_visibility(); // in meters
200 current_weather.set_visibility( tmp );
205 FG_LOG( FG_INPUT, FG_DEBUG, "" );
207 case 50: // numeric keypad 2
208 if( fgAPAltitudeEnabled() || fgAPTerrainFollowEnabled() ) {
209 fgAPAltitudeAdjust( 100 );
211 controls.move_elevator(-0.05);
214 case 56: // numeric keypad 8
215 if( fgAPAltitudeEnabled() || fgAPTerrainFollowEnabled() ) {
216 fgAPAltitudeAdjust( -100 );
218 controls.move_elevator(0.05);
221 case 49: // numeric keypad 1
222 controls.move_elevator_trim(-0.001);
224 case 55: // numeric keypad 7
225 controls.move_elevator_trim(0.001);
227 case 52: // numeric keypad 4
228 controls.move_aileron(-0.05);
230 case 54: // numeric keypad 6
231 controls.move_aileron(0.05);
233 case 48: // numeric keypad Ins
234 if( fgAPHeadingEnabled() ) {
235 fgAPHeadingAdjust( -1 );
237 controls.move_rudder(-0.05);
240 case 13: // numeric keypad Enter
241 if( fgAPHeadingEnabled() ) {
242 fgAPHeadingAdjust( 1 );
244 controls.move_rudder(0.05);
247 case 53: // numeric keypad 5
248 controls.set_aileron(0.0);
249 controls.set_elevator(0.0);
250 controls.set_rudder(0.0);
252 case 57: // numeric keypad 9 (Pg Up)
253 if( fgAPAutoThrottleEnabled() ) {
254 fgAPAutoThrottleAdjust( 5 );
256 controls.move_throttle( FGControls::ALL_ENGINES, 0.01 );
259 case 51: // numeric keypad 3 (Pg Dn)
260 if( fgAPAutoThrottleEnabled() ) {
261 fgAPAutoThrottleAdjust( -5 );
263 controls.move_throttle( FGControls::ALL_ENGINES, -0.01 );
267 speed = current_options.get_speed_up();
269 current_options.set_speed_up( speed );
274 b_ret = int( controls.get_brake( 0 ) );
275 b_set = double(!b_ret);
276 controls.set_brake( FGControls::ALL_WHEELS, b_set);
279 HUD_brightkey( false );
282 fgHUDInit(¤t_aircraft); // normal HUD
285 t->adjust_warp (+60);
286 local_update_sky_and_lighting_params();
289 t->togglePauseMode();
292 FGBucket p( f->get_Longitude() * RAD_TO_DEG,
293 f->get_Latitude() * RAD_TO_DEG );
294 FGPath tile_path( current_options.get_fg_root() );
295 tile_path.append( "Scenery" );
296 tile_path.append( p.gen_base_path() );
297 tile_path.append( p.gen_index_str() );
299 // printf position and attitude information
300 FG_LOG( FG_INPUT, FG_INFO,
301 "Lon = " << f->get_Longitude() * RAD_TO_DEG
302 << " Lat = " << f->get_Latitude() * RAD_TO_DEG
303 << " Altitude = " << f->get_Altitude() * FEET_TO_METER
305 FG_LOG( FG_INPUT, FG_INFO,
306 "Heading = " << f->get_Psi() * RAD_TO_DEG
307 << " Roll = " << f->get_Phi() * RAD_TO_DEG
308 << " Pitch = " << f->get_Theta() * RAD_TO_DEG );
309 FG_LOG( FG_INPUT, FG_INFO, tile_path.c_str());
313 t->adjust_warp_delta (+30);
314 local_update_sky_and_lighting_params();
317 current_options.cycle_view_mode();
320 fov = current_options.get_fov();
322 if ( fov < FG_FOV_MIN ) {
325 current_options.set_fov(fov);
326 v->force_update_fov_math();
329 #ifndef FG_OLD_WEATHER
330 tmp = WeatherDatabase->getWeatherVisibility();
332 WeatherDatabase->setWeatherVisibility( tmp );
334 tmp = current_weather.get_visibility(); // in meters
336 current_weather.set_visibility( tmp );
340 // if( fg_DebugOutput ) {
341 // fclose( fg_DebugOutput );
343 FG_LOG( FG_INPUT, FG_ALERT,
344 "Program exiting normally at user request." );
352 // Handle "special" keyboard events
353 void GLUTspecialkey(int k, int x, int y) {
358 FG_LOG( FG_INPUT, FG_DEBUG, "Special key hit = " << k );
360 if ( puKeyboard(k + PU_KEY_GLUT_SPECIAL_OFFSET, PU_DOWN) ) {
364 if ( GLUT_ACTIVE_SHIFT && glutGetModifiers() ) {
365 FG_LOG( FG_INPUT, FG_DEBUG, " SHIFTED" );
367 case GLUT_KEY_END: // numeric keypad 1
368 v->set_goal_view_offset( FG_PI * 0.75 );
370 case GLUT_KEY_DOWN: // numeric keypad 2
371 v->set_goal_view_offset( FG_PI );
373 case GLUT_KEY_PAGE_DOWN: // numeric keypad 3
374 v->set_goal_view_offset( FG_PI * 1.25 );
376 case GLUT_KEY_LEFT: // numeric keypad 4
377 v->set_goal_view_offset( FG_PI * 0.50 );
379 case GLUT_KEY_RIGHT: // numeric keypad 6
380 v->set_goal_view_offset( FG_PI * 1.50 );
382 case GLUT_KEY_HOME: // numeric keypad 7
383 v->set_goal_view_offset( FG_PI * 0.25 );
385 case GLUT_KEY_UP: // numeric keypad 8
386 v->set_goal_view_offset( 0.00 );
388 case GLUT_KEY_PAGE_UP: // numeric keypad 9
389 v->set_goal_view_offset( FG_PI * 1.75 );
393 FG_LOG( FG_INPUT, FG_DEBUG, "" );
395 case GLUT_KEY_F2: // F2 Reload Tile Cache...
398 FG_LOG(FG_INPUT, FG_INFO, "ReIniting TileCache");
399 FGTime *t = FGTime::cur_time_params;
400 if( (toggle_pause = !t->getPause()) )
401 t->togglePauseMode();
403 if( global_tile_mgr.init() ) {
404 // Load the local scenery data
405 global_tile_mgr.update();
407 FG_LOG( FG_GENERAL, FG_ALERT,
408 "Error in Tile Manager initialization!" );
413 t->togglePauseMode();
416 case GLUT_KEY_F3: // F2 Take a screen shot
419 case GLUT_KEY_F6: // F6 toggles Autopilot target location
420 fgAPToggleWayPoint();
422 case GLUT_KEY_F8: // F8 toggles fog ... off fastest nicest...
423 current_options.cycle_fog();
425 if ( current_options.get_fog() == fgOPTIONS::FG_FOG_DISABLED ) {
426 FG_LOG( FG_INPUT, FG_INFO, "Fog disabled" );
427 } else if ( current_options.get_fog() ==
428 fgOPTIONS::FG_FOG_FASTEST )
430 FG_LOG( FG_INPUT, FG_INFO,
431 "Fog enabled, hint set to fastest" );
432 } else if ( current_options.get_fog() ==
433 fgOPTIONS::FG_FOG_NICEST )
435 FG_LOG( FG_INPUT, FG_INFO,
436 "Fog enabled, hint set to nicest" );
440 case GLUT_KEY_F9: // F9 toggles textures on and off...
441 if ( material_mgr.loaded() ) {
442 if (current_options.get_textures()) {
443 current_options.set_textures(false);
444 glDisable(GL_TEXTURE_2D);
445 ssgOverrideTexture(true);
447 current_options.set_textures(true);
448 glEnable(GL_TEXTURE_2D);
449 ssgOverrideTexture(false);
451 FG_LOG( FG_INPUT, FG_INFO, "Toggling texture" );
453 FG_LOG( FG_INPUT, FG_INFO,
454 "No textures loaded, cannot toggle" );
457 case GLUT_KEY_F10: // F10 toggles menu on and off...
458 FG_LOG(FG_INPUT, FG_INFO, "Invoking call back function");
461 case GLUT_KEY_F11: // F11 Altitude Dialog.
462 FG_LOG(FG_INPUT, FG_INFO, "Invoking Altitude call back function");
465 case GLUT_KEY_F12: // F12 Heading Dialog...
466 FG_LOG(FG_INPUT, FG_INFO, "Invoking Heading call back function");
470 if( fgAPAltitudeEnabled() || fgAPTerrainFollowEnabled() ) {
471 fgAPAltitudeAdjust( -100 );
473 controls.move_elevator(0.05);
477 if( fgAPAltitudeEnabled() || fgAPTerrainFollowEnabled() ) {
478 fgAPAltitudeAdjust( 100 );
480 controls.move_elevator(-0.05);
484 controls.move_aileron(-0.05);
487 controls.move_aileron(0.05);
489 case GLUT_KEY_HOME: // numeric keypad 1
490 controls.move_elevator_trim(0.001);
492 case GLUT_KEY_END: // numeric keypad 7
493 controls.move_elevator_trim(-0.001);
495 case GLUT_KEY_INSERT: // numeric keypad Ins
496 if( fgAPHeadingEnabled() ) {
497 fgAPHeadingAdjust( -1 );
499 controls.move_rudder(-0.05);
502 case 13: // numeric keypad Enter
503 if( fgAPHeadingEnabled() ) {
504 fgAPHeadingAdjust( 1 );
506 controls.move_rudder(0.05);
509 case 53: // numeric keypad 5
510 controls.set_aileron(0.0);
511 controls.set_elevator(0.0);
512 controls.set_rudder(0.0);
514 case GLUT_KEY_PAGE_UP: // numeric keypad 9 (Pg Up)
515 if( fgAPAutoThrottleEnabled() ) {
516 fgAPAutoThrottleAdjust( 5 );
518 controls.move_throttle( FGControls::ALL_ENGINES, 0.01 );
521 case GLUT_KEY_PAGE_DOWN: // numeric keypad 3 (Pg Dn)
522 if( fgAPAutoThrottleEnabled() ) {
523 fgAPAutoThrottleAdjust( -5 );
525 controls.move_throttle( FGControls::ALL_ENGINES, -0.01 );