1 /**************************************************************************
4 * Written 1998 by Durk Talsma, started Juni, 1998. For the flight gear
7 * Additional mouse supported added by David Megginson, 1999.
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License as
11 * published by the Free Software Foundation; either version 2 of the
12 * License, or (at your option) any later version.
14 * This program is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 **************************************************************************/
31 #include <simgear/compiler.h>
33 #ifdef FG_MATH_EXCEPTION_CLASH
42 #include <simgear/xgl/xgl.h>
44 #if defined(FX) && defined(XMESA)
45 # include <GL/xmesa.h>
54 #include <simgear/constants.h>
55 #include <simgear/debug/logstream.hxx>
56 #include <simgear/misc/fgpath.hxx>
57 #include <simgear/screen/screen-dump.hxx>
59 #include <Include/general.hxx>
60 #include <Aircraft/aircraft.hxx>
61 #include <Airports/simple.hxx>
62 #include <Autopilot/auto_gui.hxx>
63 #include <Autopilot/newauto.hxx>
64 #include <Cockpit/panel.hxx>
65 #include <Controls/controls.hxx>
66 #include <FDM/flight.hxx>
67 #include <Main/bfi.hxx>
68 #include <Main/fg_init.hxx>
69 #include <Main/fg_io.hxx>
70 #include <Main/globals.hxx>
71 #include <Main/save.hxx>
73 #include <NetworkOLK/network.h>
76 #if defined( WIN32 ) && !defined( __CYGWIN__ )
77 # include <simgear/screen/win32-printer.h>
78 # include <simgear/screen/GlBitmaps.h>
83 * A virtual trackball implementation
84 * Written by Gavin Bell for Silicon Graphics, November 1988.
87 * Pass the x and y coordinates of the last and current positions of
88 * the mouse, scaled so they are from (-1.0 ... 1.0).
90 * The resulting rotation is returned as a quaternion rotation in the
94 trackball(float q[4], float p1x, float p1y, float p2x, float p2y);
97 * Given two quaternions, add them together to get a third quaternion.
98 * Adding quaternions to get a compound rotation is analagous to adding
99 * translations to get a compound translation. When incrementally
100 * adding rotations, the first argument here should be the new
102 * rotation, the second and third the total rotation (which will be
103 * over-written with the resulting new total rotation).
106 add_quats(float *q1, float *q2, float *dest);
109 * A useful function, builds a rotation matrix in Matrix based on
113 build_rotmatrix(float m[4][4], float q[4]);
116 * This function computes a quaternion based on an axis (defined by
117 * the given vector) and an angle about which to rotate. The angle is
118 * expressed in radians. The result is put into the third argument.
121 axis_to_quat(float a[3], float phi, float q[4]);
126 FG_USING_STD(string);
128 #ifndef FG_HAVE_NATIVE_SGI_COMPILERS
132 #if defined(WIN32) || defined(__CYGWIN32__)
133 #define WIN32_CURSOR_TWEAKS
134 #elif (GLUT_API_VERSION >= 4 || GLUT_XLIB_IMPLEMENTATION >= 9)
135 #define X_CURSOR_TWEAKS
138 // hack, should come from an include someplace
139 extern void fgInitVisuals( void );
140 extern void fgReshape( int width, int height );
141 extern void fgRenderFrame( void );
144 fntTexFont *guiFntHandle = 0;
146 static puMenuBar *mainMenuBar = 0;
147 //static puButton *hideMenuButton = 0;
149 static puDialogBox *dialogBox = 0;
150 static puFrame *dialogFrame = 0;
151 static puText *dialogBoxMessage = 0;
152 static puOneShot *dialogBoxOkButton = 0;
155 static puDialogBox *YNdialogBox = 0;
156 static puFrame *YNdialogFrame = 0;
157 static puText *YNdialogBoxMessage = 0;
158 static puOneShot *YNdialogBoxOkButton = 0;
159 static puOneShot *YNdialogBoxNoButton = 0;
161 static char msg_OK[] = "OK";
162 static char msg_NO[] = "NO";
163 static char msg_YES[] = "YES";
164 static char msg_CANCEL[] = "Cancel";
165 static char msg_RESET[] = "Reset";
167 char *gui_msg_OK; // "OK"
168 char *gui_msg_NO; // "NO"
169 char *gui_msg_YES; // "YES"
170 char *gui_msg_CANCEL; // "CANCEL"
171 char *gui_msg_RESET; // "RESET"
173 static char global_dialog_string[256];
175 // from autopilot.cxx
176 // extern void NewAltitude( puObject *cb );
177 // extern void NewHeading( puObject *cb );
178 // extern void fgAPAdjust( puObject * );
179 // extern void NewTgtAirport( puObject *cb );
180 // bool fgAPTerrainFollowEnabled( void );
181 // bool fgAPAltitudeEnabled( void );
182 // bool fgAPHeadingEnabled( void );
183 // bool fgAPWayPointEnabled( void );
184 // bool fgAPAutoThrottleEnabled( void );
187 extern void fgLatLonFormatToggle( puObject *);
189 /* --------------------------------------------------------------------
191 ---------------------------------------------------------------------*/
195 static int _savedX = 0;
196 static int _savedY = 0;
197 static int last_buttons = 0 ;
198 static int mouse_active = 0;
199 static int menu_on = 0;
200 static int mouse_joystick_control = 0;
202 //static time_t mouse_off_time;
203 //static int mouse_timed_out;
205 // to allow returning to previous view
206 // on second left click in MOUSE_VIEW mode
207 // This has file scope so that it can be reset
208 // if the little rodent is moved NHV
209 static int _mVtoggle;
211 // we break up the glutGetModifiers return mask
212 // once per loop and stash what we need in these
213 static int glut_active_shift;
214 static int glut_active_ctrl;
215 static int glut_active_alt;
217 static float lastquat[4];
218 static float curquat[4];
219 static float _quat0[4];
220 float quat_mat[4][4];
222 // uncomment this for view to exactly follow mouse in MOUSE_VIEW mode
223 // else smooth out the view panning to .01 radian per frame
224 // see view_offset smoothing mechanism in main.cxx
225 #define NO_SMOOTH_MOUSE_VIEW
227 // uncomment following to
228 #define RESET_VIEW_ON_LEAVING_MOUSE_VIEW
230 /* --------------------------------------------------------------------
231 Support for mouse as control yoke (david@megginson.com)
233 - right button toggles between pointer and yoke
234 - horizontal drag with no buttons moves ailerons
235 - vertical drag with no buttons moves elevators
236 - horizontal drag with left button moves brakes (left=on)
237 - vertical drag with left button moves throttle (up=more)
238 - horizontal drag with middle button moves rudder
239 - vertical drag with middle button moves trim
241 For the *_sensitivity variables, a lower number means more sensitive.
243 TODO: figure out how to keep pointer from leaving window in yoke mode.
244 TODO: add thresholds and null zones
245 TODO: sensitivity should be configurable at user option.
246 TODO: allow differential braking (this will be useful if FlightGear
247 ever supports tail-draggers like the DC-3)
248 ---------------------------------------------------------------------*/
256 MouseMode mouse_mode = MOUSE_POINTER;
258 static double aileron_sensitivity = 1.0/500.0;
259 static double elevator_sensitivity = 1.0/500.0;
260 static double brake_sensitivity = 1.0/250.0;
261 static double throttle_sensitivity = 1.0/250.0;
262 static double rudder_sensitivity = 1.0/500.0;
263 static double trim_sensitivity = 1.0/1000.0;
265 static inline void Quat0( void ) {
266 curquat[0] = _quat0[0];
267 curquat[1] = _quat0[1];
268 curquat[2] = _quat0[2];
269 curquat[3] = _quat0[3];
272 static inline int left_button( void ) {
273 return( last_buttons & (1 << GLUT_LEFT_BUTTON) );
276 static inline int middle_button( void ) {
277 return( last_buttons & (1 << GLUT_MIDDLE_BUTTON) );
280 static inline int right_button( void ) {
281 return( last_buttons & (1 << GLUT_RIGHT_BUTTON) );
284 static inline void TurnCursorOn( void )
287 #if defined(WIN32_CURSOR_TWEAKS)
288 switch (mouse_mode) {
290 glutSetCursor(GLUT_CURSOR_INHERIT);
293 glutSetCursor(GLUT_CURSOR_CROSSHAIR);
296 glutSetCursor(GLUT_CURSOR_LEFT_RIGHT);
300 #if defined(X_CURSOR_TWEAKS)
301 glutWarpPointer( globals->get_options()->get_xsize()/2,
302 globals->get_options()->get_ysize()/2);
306 static inline void TurnCursorOff( void )
309 #if defined(WIN32_CURSOR_TWEAKS)
310 glutSetCursor(GLUT_CURSOR_NONE);
311 #elif defined(X_CURSOR_TWEAKS)
312 glutWarpPointer( globals->get_options()->get_xsize(),
313 globals->get_options()->get_ysize());
317 void maybeToggleMouse( void )
319 #if defined(WIN32_CURSOR_TWEAKS)
320 static int first_time = ~0;
321 static int mouse_changed = 0;
325 mouse_changed = ~mouse_changed;
329 if( mouse_mode != MOUSE_POINTER )
331 if( mouse_changed ) {
332 mouse_changed = ~mouse_changed;
338 first_time = ~first_time;
339 #endif // #ifdef WIN32
342 // Call with FALSE to init and TRUE to restore
343 void BusyCursor( int restore )
345 static GLenum cursor = (GLenum) 0;
347 glutSetCursor(cursor);
349 cursor = (GLenum) glutGet( (GLenum) GLUT_WINDOW_CURSOR );
350 #if defined(WIN32_CURSOR_TWEAKS)
353 glutSetCursor( GLUT_CURSOR_WAIT );
358 // Center the view offsets
359 void CenterView( void ) {
360 if( mouse_mode = MOUSE_VIEW ) {
361 mouse_mode = MOUSE_POINTER;
362 _savedX = globals->get_options()->get_xsize()/2;
363 _savedY = globals->get_options()->get_ysize()/2;
366 build_rotmatrix(quat_mat, curquat);
367 glutSetCursor(GLUT_CURSOR_INHERIT);
369 // Is this necessary ??
370 if( !menu_on ) TurnCursorOff();
372 glutWarpPointer( _savedX, _savedY );
374 globals->get_current_view()->set_goal_view_offset(0.0);
375 globals->get_current_view()->set_view_offset(0.0);
379 int guiGetMouseButton(void)
384 void guiGetMouse(int *x, int *y)
390 void guiMotionFunc ( int x, int y )
392 int ww, wh, need_warp = 0;
396 if (mouse_mode == MOUSE_POINTER) {
398 glutPostRedisplay () ;
400 if( x == _mX && y == _mY)
403 // reset left click MOUSE_VIEW toggle feature
406 ww = globals->get_options()->get_xsize();
407 wh = globals->get_options()->get_ysize();
409 switch (mouse_mode) {
411 if( !mouse_joystick_control ) {
412 mouse_joystick_control = 1;
413 globals->get_options()->set_control_mode( FGOptions::FG_MOUSE );
415 if ( left_button() ) {
416 offset = (_mX - x) * brake_sensitivity;
417 controls.move_brake(FGControls::ALL_WHEELS, offset);
418 offset = (_mY - y) * throttle_sensitivity;
419 controls.move_throttle(FGControls::ALL_ENGINES, offset);
420 } else if ( right_button() ) {
421 if( ! current_autopilot->get_HeadingEnabled() ) {
422 offset = (x - _mX) * rudder_sensitivity;
423 controls.move_rudder(offset);
425 if( ! current_autopilot->get_AltitudeEnabled() ) {
426 offset = (_mY - y) * trim_sensitivity;
427 controls.move_elevator_trim(offset);
430 if( ! current_autopilot->get_HeadingEnabled() ) {
431 offset = (x - _mX) * aileron_sensitivity;
432 controls.move_aileron(offset);
434 if( ! current_autopilot->get_AltitudeEnabled() ) {
435 offset = (_mY - y) * elevator_sensitivity;
436 controls.move_elevator(offset);
440 // Keep the mouse in the window.
441 if (x < 5 || x > ww-5 || y < 5 || y > wh-5) {
450 #define CONTRAINED_MOUSE_VIEW_Y
451 #ifdef CONTRAINED_MOUSE_VIEW_Y
455 #endif // CONTRAINED_MOUSE_VIEW_Y
457 } else if( y >= wh-1) {
458 #ifdef CONTRAINED_MOUSE_VIEW_Y
462 #endif // CONTRAINED_MOUSE_VIEW_Y
465 // wrap MOUSE_VIEW mode cursor x position
469 } else if ( x >= ww-1 ) {
473 // try to get FG_PI movement in each half of screen
477 if( middle_button() ) {
479 (2.0f * _mX - W) / W,
480 0, //(H - 2.0f * y) / H, // 3
482 0 //(H - 2.0f * _mY) / H // 1
489 0, //(2.0f * _mX - W) / W, // 0
490 (H - 2.0f * y) / H, // 3
491 0, //(2.0f * x - W) / W, // 2
492 (H - 2.0f * _mY) / H // 1
495 add_quats(lastquat, curquat, curquat);
496 build_rotmatrix(quat_mat, curquat);
499 // this could be done in above quat
500 // but requires redoing view pipeline
501 offset = globals->get_current_view()->get_goal_view_offset();
502 offset += ((_mX - x) * FG_2PI / W );
503 while (offset < 0.0) {
506 while (offset > FG_2PI) {
509 globals->get_current_view()->set_goal_view_offset(offset);
510 #ifdef NO_SMOOTH_MOUSE_VIEW
511 globals->get_current_view()->set_view_offset(offset);
520 glutWarpPointer(x, y);
522 // Record the new mouse position.
528 void guiMouseFunc(int button, int updown, int x, int y)
532 // private MOUSE_VIEW state variables
533 // to allow alternate left clicks in MOUSE_VIEW mode
534 // to toggle between current offsets and straight ahead
536 static int _mVx, _mVy, _Vx, _Vy;
537 static float _quat[4];
538 static double _view_offset;
540 // general purpose variables
543 glutModifiers = glutGetModifiers();
544 glut_active_shift = glutModifiers & GLUT_ACTIVE_SHIFT;
545 glut_active_ctrl = glutModifiers & GLUT_ACTIVE_CTRL;
546 glut_active_alt = glutModifiers & GLUT_ACTIVE_ALT;
548 // Was the left button pressed?
549 if (updown == GLUT_DOWN ) {
550 if( button == GLUT_LEFT_BUTTON)
552 switch (mouse_mode) {
559 // resume previous view offsets
564 curquat[0] = _quat[0];
565 curquat[1] = _quat[1];
566 curquat[2] = _quat[2];
567 curquat[3] = _quat[3];
568 globals->get_current_view()->set_goal_view_offset(_view_offset);
569 #ifdef NO_SMOOTH_MOUSE_VIEW
570 globals->get_current_view()->set_view_offset(_view_offset);
578 _quat[0] = curquat[0];
579 _quat[1] = curquat[1];
580 _quat[2] = curquat[2];
581 _quat[3] = curquat[3];
582 x = globals->get_options()->get_xsize()/2;
583 y = globals->get_options()->get_ysize()/2;
586 globals->get_current_view()->get_goal_view_offset();
587 globals->get_current_view()->set_goal_view_offset(0.0);
588 #ifdef NO_SMOOTH_MOUSE_VIEW
589 globals->get_current_view()->set_view_offset(0.0);
592 glutWarpPointer( x , y);
593 build_rotmatrix(quat_mat, curquat);
594 _mVtoggle = ~_mVtoggle;
597 }else if ( button == GLUT_RIGHT_BUTTON) {
598 switch (mouse_mode) {
600 mouse_mode = MOUSE_YOKE;
601 mouse_joystick_control = 0;
604 // start with zero point in center of screen
605 _mX = globals->get_options()->get_xsize()/2;
606 _mY = globals->get_options()->get_ysize()/2;
608 // try to have the MOUSE_YOKE position
609 // reflect the current stick position
610 offset = controls.get_aileron();
611 x = _mX - (int)(offset * aileron_sensitivity);
612 offset = controls.get_elevator();
613 y = _mY - (int)(offset * elevator_sensitivity);
615 glutSetCursor(GLUT_CURSOR_CROSSHAIR);
616 FG_LOG( FG_INPUT, FG_INFO, "Mouse in yoke mode" );
620 mouse_mode = MOUSE_VIEW;
621 globals->get_options()->set_control_mode( FGOptions::FG_JOYSTICK );
622 x = globals->get_options()->get_xsize()/2;
623 y = globals->get_options()->get_ysize()/2;
626 build_rotmatrix(quat_mat, curquat);
627 glutSetCursor(GLUT_CURSOR_LEFT_RIGHT);
628 FG_LOG( FG_INPUT, FG_INFO, "Mouse in view mode" );
632 mouse_mode = MOUSE_POINTER;
635 #ifdef RESET_VIEW_ON_LEAVING_MOUSE_VIEW
637 build_rotmatrix(quat_mat, curquat);
638 globals->get_current_view()->set_goal_view_offset(0.0);
639 #ifdef NO_SMOOTH_MOUSE_VIEW
640 globals->get_current_view()->set_view_offset(0.0);
642 #endif // RESET_VIEW_ON_LEAVING_MOUSE_VIEW
643 glutSetCursor(GLUT_CURSOR_INHERIT);
648 FG_LOG( FG_INPUT, FG_INFO, "Mouse in pointer mode" );
651 glutWarpPointer( x, y );
652 } // END RIGHT BUTTON
653 } // END UPDOWN == GLUT_DOWN
655 // Note which button is pressed.
656 if ( updown == GLUT_DOWN ) {
657 last_buttons |= ( 1 << button ) ;
659 last_buttons &= ~( 1 << button ) ;
662 // If we're in pointer mode, let PUI
663 // know what's going on.
664 if (mouse_mode == MOUSE_POINTER) {
665 if (!puMouse (button, updown, x,y)) {
666 current_panel->doMouseAction(button, updown, x, y);
670 // Register the new position (if it
671 // hasn't been registered already).
675 glutPostRedisplay ();
678 /* ================ General Purpose Functions ================ */
680 // Intercept the Escape Key
681 void ConfirmExitDialog(void)
683 FG_PUSH_PUI_DIALOG( YNdialogBox );
686 // General Purpose Message Box
687 void mkDialog (const char *txt)
689 strncpy(global_dialog_string, txt, 256);
690 dialogBoxMessage->setLabel(global_dialog_string);
691 FG_PUSH_PUI_DIALOG( dialogBox );
694 // Toggle the Menu and Mouse display state
695 void guiToggleMenu(void)
698 // printf("Hiding Menu\n");
699 mainMenuBar->hide ();
700 #if defined(WIN32_CURSOR_TWEAKS)
701 if( mouse_mode == MOUSE_POINTER )
703 #endif // #ifdef WIN32_CURSOR_TWEAKS
705 // printf("Showing Menu\n");
706 mainMenuBar->reveal();
709 #endif // #ifdef WIN32
714 /* -----------------------------------------------------------------------
715 the Gui callback functions
716 ____________________________________________________________________*/
719 // Hier Neu :-) This is my newly added code
720 // Added by David Findlay <nedz@bigpond.com>
721 // on Sunday 3rd of December
723 // Start new Save Dialog Box
724 static puDialogBox *SaveDialog = 0;
725 static puFrame *SaveDialogFrame = 0;
726 static puText *SaveDialogMessage = 0;
727 static puInput *SaveDialogInput = 0;
729 static puOneShot *SaveDialogOkButton = 0;
730 static puOneShot *SaveDialogCancelButton = 0;
731 static puOneShot *SaveDialogResetButton = 0;
733 // Default save filename
734 static char saveFile[256] = "fgfs.sav";
737 void SaveDialogCancel(puObject *) {
738 FG_POP_PUI_DIALOG( SaveDialog );
741 // If press OK do this
742 void SaveDialogOk(puObject*) {
744 FG_POP_PUI_DIALOG( SaveDialog );
747 SaveDialogInput->getValue(&s);
750 cout << saveFile << endl;
751 if (output.good() && fgSaveFlight(output)) {
753 mkDialog("Saved flight");
754 FG_LOG(FG_INPUT, FG_INFO, "Saved flight");
756 mkDialog("Cannot save flight");
757 FG_LOG(FG_INPUT, FG_ALERT, "Cannot save flight");
762 static void saveFlight(puObject *cv) {
763 SaveDialog = new puDialogBox (150, 50);
765 SaveDialogFrame = new puFrame (0,0,350, 150);
766 SaveDialogMessage = new puText ((150 - puGetStringWidth( puGetDefaultLabelFont(), "File Name:" ) / 2), 110);
767 SaveDialogMessage -> setLabel ("File Name:");
769 SaveDialogInput = new puInput (50, 70, 300, 100);
770 SaveDialogInput -> setValue (saveFile);
771 SaveDialogInput -> acceptInput();
773 SaveDialogOkButton = new puOneShot (50, 10, 110, 50);
774 SaveDialogOkButton -> setLegend (gui_msg_OK);
775 SaveDialogOkButton -> setCallback ( SaveDialogOk );
776 SaveDialogOkButton -> makeReturnDefault(TRUE);
778 SaveDialogCancelButton = new puOneShot (140, 10, 210, 50);
779 SaveDialogCancelButton -> setLegend (gui_msg_CANCEL);
780 SaveDialogCancelButton -> setCallback ( SaveDialogCancel );
782 FG_FINALIZE_PUI_DIALOG( SaveDialog );
784 SaveDialog -> reveal();
788 static puDialogBox *LoadDialog = 0;
789 static puFrame *LoadDialogFrame = 0;
790 static puText *LoadDialogMessage = 0;
791 static puInput *LoadDialogInput = 0;
793 static puOneShot *LoadDialogOkButton = 0;
794 static puOneShot *LoadDialogCancelButton = 0;
795 static puOneShot *LoadDialogResetButton = 0;
797 // Default load filename
798 static char loadFile[256] = "fgfs.sav";
800 // Do this if the person click okay
801 void LoadDialogOk(puObject *) {
803 FG_POP_PUI_DIALOG( LoadDialog );
806 LoadDialogInput->getValue(&l);
809 if (input.good() && fgLoadFlight(input)) {
811 mkDialog("Loaded flight");
812 FG_LOG(FG_INPUT, FG_INFO, "Restored flight");
814 mkDialog("Failed to load flight");
815 FG_LOG(FG_INPUT, FG_ALERT, "Cannot load flight");
819 // Do this is the person presses cancel
820 void LoadDialogCancel(puObject *) {
821 FG_POP_PUI_DIALOG( LoadDialog );
824 // Create Load Dialog
825 static void loadFlight(puObject *cb)
827 LoadDialog = new puDialogBox (150, 50);
829 LoadDialogFrame = new puFrame (0,0,350, 150);
830 LoadDialogMessage = new puText ((150 - puGetStringWidth( puGetDefaultLabelFont(), "File Name:" ) / 2), 110);
831 LoadDialogMessage -> setLabel ("File Name:");
833 LoadDialogInput = new puInput (50, 70, 300, 100);
834 LoadDialogInput -> setValue (loadFile);
835 LoadDialogInput -> acceptInput();
837 LoadDialogOkButton = new puOneShot (50, 10, 110, 50);
838 LoadDialogOkButton -> setLegend (gui_msg_OK);
839 LoadDialogOkButton -> setCallback ( LoadDialogOk );
840 LoadDialogOkButton -> makeReturnDefault(TRUE);
842 LoadDialogCancelButton = new puOneShot (140, 10, 210, 50);
843 LoadDialogCancelButton -> setLegend (gui_msg_CANCEL);
844 LoadDialogCancelButton -> setCallback ( LoadDialogCancel );
846 FG_FINALIZE_PUI_DIALOG( LoadDialog );
848 LoadDialog -> reveal();
851 void reInit(puObject *cb)
855 build_rotmatrix(quat_mat, curquat);
856 fgReInitSubsystems();
860 // This is the accessor function
861 void guiTogglePanel(puObject *cb)
863 globals->get_options()->toggle_panel();
866 //void MenuHideMenuCb(puObject *cb)
867 void hideMenuCb (puObject *cb)
872 void goodBye(puObject *)
874 // FG_LOG( FG_INPUT, FG_ALERT,
875 // "Program exiting normally at user request." );
876 cout << "Program exiting normally at user request." << endl;
878 #ifdef FG_NETWORK_OLK
879 if ( globals->get_options()->get_network_olk() ) {
880 if ( net_is_registered == 0 ) fgd_send_com( "8", FGFS_host);
884 // close all external I/O connections
891 void goAwayCb (puObject *me)
893 FG_POP_PUI_DIALOG( dialogBox );
896 void mkDialogInit (void)
898 // printf("mkDialogInit\n");
899 int x = (globals->get_options()->get_xsize()/2 - 400/2);
900 int y = (globals->get_options()->get_ysize()/2 - 100/2);
901 dialogBox = new puDialogBox (x, y); // 150, 50
903 dialogFrame = new puFrame (0,0,400,100);
904 dialogBoxMessage = new puText (10, 70);
905 dialogBoxMessage -> setLabel ("");
906 dialogBoxOkButton = new puOneShot (180, 10, 240, 50);
907 dialogBoxOkButton -> setLegend (gui_msg_OK);
908 dialogBoxOkButton -> makeReturnDefault (TRUE );
909 dialogBoxOkButton -> setCallback (goAwayCb);
911 FG_FINALIZE_PUI_DIALOG( dialogBox );
914 void MayBeGoodBye(puObject *)
919 void goAwayYesNoCb(puObject *me)
921 FG_POP_PUI_DIALOG( YNdialogBox);
924 void ConfirmExitDialogInit(void)
926 char msg[] = "Really Quit";
929 // printf("ConfirmExitDialogInit\n");
930 int len = 200 - puGetStringWidth( puGetDefaultLabelFont(), msg )/2;
932 int x = (globals->get_options()->get_xsize()/2 - 400/2);
933 int y = (globals->get_options()->get_ysize()/2 - 100/2);
935 YNdialogBox = new puDialogBox (x, y); // 150, 50
936 // YNdialogBox = new puDialogBox (150, 50);
938 YNdialogFrame = new puFrame (0,0,400, 100);
940 YNdialogBoxMessage = new puText (len, 70);
941 YNdialogBoxMessage -> setDefaultValue (msg);
942 YNdialogBoxMessage -> getDefaultValue (&s);
943 YNdialogBoxMessage -> setLabel (s);
945 YNdialogBoxOkButton = new puOneShot (100, 10, 160, 50);
946 YNdialogBoxOkButton -> setLegend (gui_msg_OK);
947 YNdialogBoxOkButton -> makeReturnDefault (TRUE );
948 YNdialogBoxOkButton -> setCallback (goodBye);
950 YNdialogBoxNoButton = new puOneShot (240, 10, 300, 50);
951 YNdialogBoxNoButton -> setLegend (gui_msg_NO);
952 YNdialogBoxNoButton -> setCallback (goAwayYesNoCb);
954 FG_FINALIZE_PUI_DIALOG( YNdialogBox );
957 void notCb (puObject *)
959 mkDialog ("This function isn't implemented yet");
962 void helpCb (puObject *)
966 #if defined(FX) && !defined(WIN32)
967 # if defined(XMESA_FX_FULLSCREEN) && defined(XMESA_FX_WINDOW)
968 if ( global_fullscreen ) {
969 global_fullscreen = false;
970 XMesaSetFXmode( XMESA_FX_WINDOW );
976 string url = "http://www.flightgear.org/Docs/InstallGuide/getstart.html";
978 if ( system("xwininfo -name Netscape > /dev/null 2>&1") == 0 ) {
979 command = "netscape -remote \"openURL(" + url + ")\" &";
981 command = "netscape " + url + " &";
984 command = "webrun.bat";
987 system( command.c_str() );
988 //string text = "Help started in netscape window.";
990 //mkDialog (text.c_str());
991 mkDialog ("Help started in netscape window.");
994 #if defined( WIN32 ) && !defined( __CYGWIN__)
996 static void rotateView( double roll, double pitch, double yaw )
1001 static GlBitmap *b1 = NULL;
1002 extern FGInterface cur_view_fdm;
1003 GLubyte *hiResScreenCapture( int multiplier )
1005 float oldfov = globals->get_options()->get_fov();
1006 float fov = oldfov / multiplier;
1007 FGViewer *v = globals->get_current_view();
1008 globals->get_options()->set_fov(fov);
1010 int cur_width = globals->get_options()->get_xsize( );
1011 int cur_height = globals->get_options()->get_ysize( );
1012 if (b1) delete( b1 );
1013 // New empty (mostly) bitmap
1014 b1 = new GlBitmap( GL_RGB, 1, 1, (unsigned char *)"123" );
1016 for ( y = 0; y < multiplier; y++ ) {
1017 for ( x = 0; x < multiplier; x++ ) {
1018 fgReshape( cur_width, cur_height );
1020 rotateView( 0, (y*fov)-((multiplier-1)*fov/2), (x*fov)-((multiplier-1)*fov/2) );
1024 b1->copyBitmap( &b2, cur_width*x, cur_height*y );
1027 globals->get_options()->set_fov(oldfov);
1028 return b1->getBitmap();
1033 #if defined( WIN32 ) && !defined( __CYGWIN__)
1034 // win32 print screen function
1035 void printScreen ( puObject *obj ) {
1036 bool show_pu_cursor = false;
1038 if ( !puCursorIsHidden() ) {
1039 show_pu_cursor = true;
1043 mainMenuBar->hide();
1045 CGlPrinter p( CGlPrinter::PRINT_BITMAP );
1046 int cur_width = globals->get_options()->get_xsize( );
1047 int cur_height = globals->get_options()->get_ysize( );
1048 p.Begin( "FlightGear", cur_width*3, cur_height*3 );
1049 p.End( hiResScreenCapture(3) );
1052 mainMenuBar->reveal();
1055 if ( show_pu_cursor ) {
1060 #endif // #ifdef WIN32
1063 void dumpSnapShot ( puObject *obj ) {
1068 // do a screen snap shot
1069 void fgDumpSnapShot () {
1070 bool show_pu_cursor = false;
1072 int freeze = globals->get_freeze();
1074 globals->set_freeze( true );
1076 mainMenuBar->hide();
1078 if ( !puCursorIsHidden() ) {
1079 show_pu_cursor = true;
1084 fgReshape( globals->get_options()->get_xsize(),
1085 globals->get_options()->get_ysize() );
1087 // we need two render frames here to clear the menu and cursor
1088 // ... not sure why but doing an extra fgFenderFrame() shoulnd't
1093 my_glDumpWindow( "fgfs-screen.ppm",
1094 globals->get_options()->get_xsize(),
1095 globals->get_options()->get_ysize() );
1097 mkDialog ("Snap shot saved to fgfs-screen.ppm");
1099 if ( show_pu_cursor ) {
1105 mainMenuBar->reveal();
1109 globals->set_freeze( false );
1113 /// The beginnings of teleportation :-)
1114 // Needs cleaning up but works
1115 // These statics should disapear when this is a class
1116 static puDialogBox *AptDialog = 0;
1117 static puFrame *AptDialogFrame = 0;
1118 static puText *AptDialogMessage = 0;
1119 static puInput *AptDialogInput = 0;
1121 static char NewAirportId[16];
1122 static char NewAirportLabel[] = "Enter New Airport ID";
1124 static puOneShot *AptDialogOkButton = 0;
1125 static puOneShot *AptDialogCancelButton = 0;
1126 static puOneShot *AptDialogResetButton = 0;
1128 void AptDialog_Cancel(puObject *)
1130 FG_POP_PUI_DIALOG( AptDialog );
1133 void AptDialog_OK (puObject *)
1135 FGPath path( globals->get_options()->get_fg_root() );
1136 path.append( "Airports" );
1137 path.append( "simple.mk4" );
1138 FGAirports airports( path.c_str() );
1142 int freeze = globals->get_freeze();
1144 globals->set_freeze( true );
1147 AptDialogInput->getValue(&s);
1150 cout << "AptDialog_OK " << AptId << " " << AptId.length() << endl;
1152 AptDialog_Cancel( NULL );
1154 if ( AptId.length() ) {
1155 // set initial position from airport id
1156 FG_LOG( FG_GENERAL, FG_INFO,
1157 "Attempting to set starting position from airport code "
1160 if ( airports.search( AptId, &a ) )
1162 globals->get_options()->set_airport_id( AptId.c_str() );
1163 globals->get_options()->set_altitude( -9999.0 );
1164 // fgSetPosFromAirportID( AptId );
1165 fgSetPosFromAirportIDandHdg( AptId,
1166 cur_fdm_state->get_Psi() * RAD_TO_DEG);
1168 fgReInitSubsystems();
1171 AptId += " not in database.";
1172 mkDialog(AptId.c_str());
1176 globals->set_freeze( false );
1179 void AptDialog_Reset(puObject *)
1181 // strncpy( NewAirportId, globals->get_options()->get_airport_id().c_str(), 16 );
1182 sprintf( NewAirportId, "%s", globals->get_options()->get_airport_id().c_str() );
1183 AptDialogInput->setValue ( NewAirportId );
1184 AptDialogInput->setCursor( 0 ) ;
1187 void NewAirport(puObject *cb)
1189 // strncpy( NewAirportId, globals->get_options()->get_airport_id().c_str(), 16 );
1190 sprintf( NewAirportId, "%s", globals->get_options()->get_airport_id().c_str() );
1191 // cout << "NewAirport " << NewAirportId << endl;
1192 AptDialogInput->setValue( NewAirportId );
1194 FG_PUSH_PUI_DIALOG( AptDialog );
1197 static void NewAirportInit(void)
1199 sprintf( NewAirportId, "%s", globals->get_options()->get_airport_id().c_str() );
1200 int len = 150 - puGetStringWidth( puGetDefaultLabelFont(),
1201 NewAirportLabel ) / 2;
1203 AptDialog = new puDialogBox (150, 50);
1205 AptDialogFrame = new puFrame (0,0,350, 150);
1206 AptDialogMessage = new puText (len, 110);
1207 AptDialogMessage -> setLabel (NewAirportLabel);
1209 AptDialogInput = new puInput (50, 70, 300, 100);
1210 AptDialogInput -> setValue (NewAirportId);
1211 AptDialogInput -> acceptInput();
1213 AptDialogOkButton = new puOneShot (50, 10, 110, 50);
1214 AptDialogOkButton -> setLegend (gui_msg_OK);
1215 AptDialogOkButton -> setCallback (AptDialog_OK);
1216 AptDialogOkButton -> makeReturnDefault(TRUE);
1218 AptDialogCancelButton = new puOneShot (140, 10, 210, 50);
1219 AptDialogCancelButton -> setLegend (gui_msg_CANCEL);
1220 AptDialogCancelButton -> setCallback (AptDialog_Cancel);
1222 AptDialogResetButton = new puOneShot (240, 10, 300, 50);
1223 AptDialogResetButton -> setLegend (gui_msg_RESET);
1224 AptDialogResetButton -> setCallback (AptDialog_Reset);
1226 cout << "NewAirportInit " << NewAirportId << endl;
1227 FG_FINALIZE_PUI_DIALOG( AptDialog );
1230 #ifdef FG_NETWORK_OLK
1232 /// The beginnings of networking :-)
1233 // Needs cleaning up but works
1234 // These statics should disapear when this is a class
1235 static puDialogBox *NetIdDialog = 0;
1236 static puFrame *NetIdDialogFrame = 0;
1237 static puText *NetIdDialogMessage = 0;
1238 static puInput *NetIdDialogInput = 0;
1240 static char NewNetId[16];
1241 static char NewNetIdLabel[] = "Enter New Callsign";
1242 extern char *fgd_callsign;
1244 static puOneShot *NetIdDialogOkButton = 0;
1245 static puOneShot *NetIdDialogCancelButton = 0;
1247 void NetIdDialog_Cancel(puObject *)
1249 FG_POP_PUI_DIALOG( NetIdDialog );
1252 void NetIdDialog_OK (puObject *)
1256 bool freeze = globals->get_freeze();
1258 globals->set_freeze( true );
1260 The following needs some cleanup because
1261 "string options.NetId" and "char *net_callsign"
1263 NetIdDialogInput->getValue(&net_callsign);
1264 NetId = net_callsign;
1266 NetIdDialog_Cancel( NULL );
1267 globals->get_options()->set_net_id( NetId.c_str() );
1268 strcpy( fgd_callsign, net_callsign);
1269 // strcpy( fgd_callsign, globals->get_options()->get_net_id().c_str());
1270 /* Entering a callsign indicates : user wants Net HUD Info */
1271 net_hud_display = 1;
1274 globals->set_freeze( false );
1277 void NewCallSign(puObject *cb)
1279 sprintf( NewNetId, "%s", globals->get_options()->get_net_id().c_str() );
1280 // sprintf( NewNetId, "%s", fgd_callsign );
1281 NetIdDialogInput->setValue( NewNetId );
1283 FG_PUSH_PUI_DIALOG( NetIdDialog );
1286 static void NewNetIdInit(void)
1288 sprintf( NewNetId, "%s", globals->get_options()->get_net_id().c_str() );
1289 // sprintf( NewNetId, "%s", fgd_callsign );
1290 int len = 150 - puGetStringWidth( puGetDefaultLabelFont(),
1291 NewNetIdLabel ) / 2;
1293 NetIdDialog = new puDialogBox (150, 50);
1295 NetIdDialogFrame = new puFrame (0,0,350, 150);
1296 NetIdDialogMessage = new puText (len, 110);
1297 NetIdDialogMessage -> setLabel (NewNetIdLabel);
1299 NetIdDialogInput = new puInput (50, 70, 300, 100);
1300 NetIdDialogInput -> setValue (NewNetId);
1301 NetIdDialogInput -> acceptInput();
1303 NetIdDialogOkButton = new puOneShot (50, 10, 110, 50);
1304 NetIdDialogOkButton -> setLegend (gui_msg_OK);
1305 NetIdDialogOkButton -> setCallback (NetIdDialog_OK);
1306 NetIdDialogOkButton -> makeReturnDefault(TRUE);
1308 NetIdDialogCancelButton = new puOneShot (240, 10, 300, 50);
1309 NetIdDialogCancelButton -> setLegend (gui_msg_CANCEL);
1310 NetIdDialogCancelButton -> setCallback (NetIdDialog_Cancel);
1313 FG_FINALIZE_PUI_DIALOG( NetIdDialog );
1316 static void net_display_toggle( puObject *cb)
1318 net_hud_display = (net_hud_display) ? 0 : 1;
1319 printf("Toggle net_hud_display : %d\n", net_hud_display);
1322 static void net_register( puObject *cb)
1324 fgd_send_com( "1", FGFS_host );
1325 net_is_registered = 0;
1326 printf("Registering to deamon\n");
1329 static void net_unregister( puObject *cb)
1331 fgd_send_com( "8", FGFS_host );
1332 net_is_registered = -1;
1333 printf("Unregistering from deamon\n");
1337 /*************** Deamon communication **********/
1339 // These statics should disapear when this is a class
1340 static puDialogBox *NetFGDDialog = 0;
1341 static puFrame *NetFGDDialogFrame = 0;
1342 static puText *NetFGDDialogMessage = 0;
1343 //static puInput *NetFGDDialogInput = 0;
1345 //static char NewNetId[16];
1346 static char NewNetFGDLabel[] = "Scan for deamon ";
1347 static char NewFGDHost[64] = "olk.mcp.de";
1348 static int NewFGDPortLo = 10000;
1349 static int NewFGDPortHi = 10001;
1351 //extern char *fgd_callsign;
1352 extern u_short base_port, end_port;
1353 extern int fgd_ip, verbose, current_port;
1354 extern char *fgd_host;
1357 static puOneShot *NetFGDDialogOkButton = 0;
1358 static puOneShot *NetFGDDialogCancelButton = 0;
1359 static puOneShot *NetFGDDialogScanButton = 0;
1361 static puInput *NetFGDHostDialogInput = 0;
1362 static puInput *NetFGDPortLoDialogInput = 0;
1363 static puInput *NetFGDPortHiDialogInput = 0;
1365 void NetFGDDialog_Cancel(puObject *)
1367 FG_POP_PUI_DIALOG( NetFGDDialog );
1370 void NetFGDDialog_OK (puObject *)
1374 bool freeze = globals->get_freeze();
1376 globals->set_freeze( true );
1377 NetFGDHostDialogInput->getValue( &NetFGD );
1378 strcpy( fgd_host, NetFGD);
1379 NetFGDPortLoDialogInput->getValue( (int *) &base_port );
1380 NetFGDPortHiDialogInput->getValue( (int *) &end_port );
1381 NetFGDDialog_Cancel( NULL );
1383 globals->set_freeze( false );
1386 void NetFGDDialog_SCAN (puObject *)
1391 bool freeze = globals->get_freeze();
1393 globals->set_freeze( true );
1394 // printf("Vor getvalue %s\n");
1395 NetFGDHostDialogInput->getValue( &NetFGD );
1396 // printf("Vor strcpy %s\n", (char *) NetFGD);
1397 strcpy( fgd_host, NetFGD);
1398 NetFGDPortLoDialogInput->getValue( (int *) &base_port );
1399 NetFGDPortHiDialogInput->getValue( (int *) &end_port );
1400 printf("FGD: %s Port-Start: %d Port-End: %d\n", fgd_host,
1401 base_port, end_port);
1402 net_resolv_fgd(fgd_host);
1403 printf("Resolve : %d\n", net_r);
1405 globals->set_freeze( false );
1408 strcpy( fgd_name, "");
1409 for( current_port = base_port; ( current_port <= end_port); current_port++) {
1410 fgd_send_com("0" , FGFS_host);
1411 sprintf( NewNetFGDLabel , "Scanning for deamon Port: %d", current_port);
1412 printf("FGD: searching %s\n", fgd_name);
1413 if ( strcmp( fgd_name, "") != 0 ) {
1414 sprintf( NewNetFGDLabel , "Found %s at Port: %d",
1415 fgd_name, current_port);
1416 fgd_port = current_port;
1417 current_port = end_port+1;
1420 current_port = end_port = base_port = fgd_port;
1422 NetFGDDialog_Cancel( NULL );
1426 void net_fgd_scan(puObject *cb)
1428 NewFGDPortLo = base_port;
1429 NewFGDPortHi = end_port;
1430 strcpy( NewFGDHost, fgd_host);
1431 NetFGDPortLoDialogInput->setValue( NewFGDPortLo );
1432 NetFGDPortHiDialogInput->setValue( NewFGDPortHi );
1433 NetFGDHostDialogInput->setValue( NewFGDHost );
1435 FG_PUSH_PUI_DIALOG( NetFGDDialog );
1439 static void NewNetFGDInit(void)
1441 // sprintf( NewNetId, "%s", globals->get_options()->get_net_id().c_str() );
1442 // sprintf( NewNetId, "%s", fgd_callsign );
1443 int len = 170 - puGetStringWidth( puGetDefaultLabelFont(),
1444 NewNetFGDLabel ) / 2;
1446 NetFGDDialog = new puDialogBox (310, 30);
1448 NetFGDDialogFrame = new puFrame (0,0,320, 170);
1449 NetFGDDialogMessage = new puText (len, 140);
1450 NetFGDDialogMessage -> setLabel (NewNetFGDLabel);
1452 NetFGDPortLoDialogInput = new puInput (50, 70, 127, 100);
1453 NetFGDPortLoDialogInput -> setValue (NewFGDPortLo);
1454 NetFGDPortLoDialogInput -> acceptInput();
1456 NetFGDPortHiDialogInput = new puInput (199, 70, 275, 100);
1457 NetFGDPortHiDialogInput -> setValue (NewFGDPortHi);
1458 NetFGDPortHiDialogInput -> acceptInput();
1460 NetFGDHostDialogInput = new puInput (50, 100, 275, 130);
1461 NetFGDHostDialogInput -> setValue (NewFGDHost);
1462 NetFGDHostDialogInput -> acceptInput();
1464 NetFGDDialogScanButton = new puOneShot (130, 10, 200, 50);
1465 NetFGDDialogScanButton -> setLegend ("Scan");
1466 NetFGDDialogScanButton -> setCallback (NetFGDDialog_SCAN);
1467 NetFGDDialogScanButton -> makeReturnDefault(FALSE);
1469 NetFGDDialogOkButton = new puOneShot (50, 10, 120, 50);
1470 NetFGDDialogOkButton -> setLegend (gui_msg_OK);
1471 NetFGDDialogOkButton -> setCallback (NetFGDDialog_OK);
1472 NetFGDDialogOkButton -> makeReturnDefault(TRUE);
1474 NetFGDDialogCancelButton = new puOneShot (210, 10, 280, 50);
1475 NetFGDDialogCancelButton -> setLegend (gui_msg_CANCEL);
1476 NetFGDDialogCancelButton -> setCallback (NetFGDDialog_Cancel);
1479 FG_FINALIZE_PUI_DIALOG( NetFGDDialog );
1483 static void net_display_toggle( puObject *cb)
1485 net_hud_display = (net_hud_display) ? 0 : 1;
1486 printf("Toggle net_hud_display : %d\n", net_hud_display);
1493 /*************** End Networking **************/
1497 /* -----------------------------------------------------------------------
1499 ---------------------------------------------------------------------*/
1500 char *fileSubmenu [] = {
1501 "Exit", /* "Close", "---------", */
1502 #if defined( WIN32 ) && !defined( __CYGWIN__)
1512 puCallback fileSubmenuCb [] = {
1513 MayBeGoodBye, /* hideMenuCb, NULL, */
1514 #if defined( WIN32 ) && !defined( __CYGWIN__)
1527 char *editSubmenu [] = {
1530 puCallback editSubmenuCb [] = {
1535 extern void fgHUDalphaAdjust( puObject * );
1536 char *viewSubmenu [] = {
1538 /* "Cockpit View > ", "View >","------------", */
1539 "Toggle Panel...", NULL
1541 puCallback viewSubmenuCb [] = {
1543 /* notCb, notCb, NULL, */
1544 guiTogglePanel, NULL
1549 char *autopilotSubmenu [] = {
1550 "Toggle HUD Format", "Adjust AP Settings",
1552 "Clear Route", "Skip Current Waypoint", "Add Waypoint",
1554 "Set Altitude", "Set Heading",
1558 puCallback autopilotSubmenuCb [] = {
1559 fgLatLonFormatToggle, fgAPAdjust,
1561 ClearRoute, PopWayPoint, AddWayPoint,
1563 NewAltitude, NewHeading,
1567 char *environmentSubmenu [] = {
1568 "Goto Airport", /* "Terrain", "Weather", */ NULL
1570 puCallback environmentSubmenuCb [] = {
1571 NewAirport, /* notCb, notCb, */ NULL
1575 char *optionsSubmenu [] = {
1576 "Preferences", "Realism & Reliablity...", NULL
1578 puCallback optionsSubmenuCb [] = {
1583 #ifdef FG_NETWORK_OLK
1584 char *networkSubmenu [] = {
1585 "Unregister from FGD ", /* "Send MSG to All", "Send MSG", "Show Pilots", */
1587 "Scan for Deamons", "Enter Callsign", /* "Display Netinfos", */
1588 "Toggle Display", NULL
1590 puCallback networkSubmenuCb [] = {
1591 /* notCb, notCb, notCb, notCb, */
1594 net_fgd_scan, NewCallSign,
1595 net_display_toggle, NULL
1599 char *helpSubmenu [] = {
1600 /* "About...", */ "Help", NULL
1602 puCallback helpSubmenuCb [] = {
1603 /* notCb, */ helpCb, NULL
1607 /* -------------------------------------------------------------------------
1609 _____________________________________________________________________*/
1614 char *mesa_win_state;
1618 puSetDefaultStyle ( PUSTYLE_SMALL_BEVELLED ); //PUSTYLE_DEFAULT
1619 puSetDefaultColourScheme (0.8, 0.8, 0.8, 0.4);
1621 // Initialize our GLOBAL GUI STRINGS
1622 gui_msg_OK = msg_OK; // "OK"
1623 gui_msg_NO = msg_NO; // "NO"
1624 gui_msg_YES = msg_YES; // "YES"
1625 gui_msg_CANCEL = msg_CANCEL; // "CANCEL"
1626 gui_msg_RESET = msg_RESET; // "RESET"
1628 // Next check home directory
1630 char* envp = ::getenv( "FG_FONTS" );
1631 if ( envp != NULL ) {
1632 fntpath.set( envp );
1634 fntpath.set( globals->get_options()->get_fg_root() );
1635 fntpath.append( "Fonts" );
1638 // Install our fast fonts
1639 fntpath.append( "typewriter.txf" );
1640 guiFntHandle = new fntTexFont ;
1641 guiFntHandle -> load ( (char *)fntpath.c_str() ) ;
1642 puFont GuiFont ( guiFntHandle, 15 ) ;
1643 puSetDefaultFonts( GuiFont, GuiFont ) ;
1644 guiFnt = puGetDefaultLabelFont();
1646 if ( globals->get_options()->get_mouse_pointer() == 0 ) {
1647 // no preference specified for mouse pointer, attempt to autodetect...
1648 // Determine if we need to render the cursor, or if the windowing
1649 // system will do it. First test if we are rendering with glide.
1650 if ( strstr ( general.get_glRenderer(), "Glide" ) ) {
1651 // Test for the MESA_GLX_FX env variable
1652 if ( (mesa_win_state = getenv( "MESA_GLX_FX" )) != NULL) {
1653 // test if we are fullscreen mesa/glide
1654 if ( (mesa_win_state[0] == 'f') ||
1655 (mesa_win_state[0] == 'F') ) {
1660 mouse_active = ~mouse_active;
1661 } else if ( globals->get_options()->get_mouse_pointer() == 1 ) {
1662 // don't show pointer
1663 } else if ( globals->get_options()->get_mouse_pointer() == 2 ) {
1664 // force showing pointer
1666 mouse_active = ~mouse_active;
1669 // MOUSE_VIEW mode stuff
1670 trackball(_quat0, 0.0, 0.0, 0.0, 0.0);
1672 build_rotmatrix(quat_mat, curquat);
1674 // Set up our Dialog Boxes
1675 ConfirmExitDialogInit();
1677 #ifdef FG_NETWORK_OLK
1683 // Make the menu bar
1684 mainMenuBar = new puMenuBar ();
1685 mainMenuBar -> add_submenu ("File", fileSubmenu, fileSubmenuCb);
1686 // mainMenuBar -> add_submenu ("Edit", editSubmenu, editSubmenuCb);
1687 mainMenuBar -> add_submenu ("View", viewSubmenu, viewSubmenuCb);
1688 mainMenuBar -> add_submenu ("Environment", environmentSubmenu, environmentSubmenuCb);
1689 mainMenuBar -> add_submenu ("Autopilot", autopilotSubmenu, autopilotSubmenuCb);
1690 // mainMenuBar -> add_submenu ("Options", optionsSubmenu, optionsSubmenuCb);
1691 #ifdef FG_NETWORK_OLK
1692 if ( globals->get_options()->get_network_olk() ) {
1693 mainMenuBar -> add_submenu ("Network", networkSubmenu, networkSubmenuCb);
1696 mainMenuBar -> add_submenu ("Help", helpSubmenu, helpSubmenuCb);
1697 mainMenuBar-> close ();
1698 // Set up menu bar toggle
1707 * Implementation of a virtual trackball.
1708 * Implemented by Gavin Bell, lots of ideas from Thant Tessman and
1709 * the August '88 issue of Siggraph's "Computer Graphics," pp. 121-129.
1711 * Vector manip code:
1713 * Original code from:
1714 * David M. Ciemiewicz, Mark Grossman, Henry Moreton, and Paul Haeberli
1716 * Much mucking with by:
1719 #if defined(_WIN32) && !defined( __CYGWIN32__ )
1720 #pragma warning (disable:4244) /* disable bogus conversion warnings */
1724 //#include "trackball.h"
1727 * This size should really be based on the distance from the center of
1728 * rotation to the point on the object underneath the mouse. That
1729 * point would then track the mouse as closely as possible. This is a
1730 * simple example, though, so that is left as an Exercise for the
1733 #define TRACKBALLSIZE (0.8f)
1734 #define SQRT(x) sqrt(x)
1737 * Local function prototypes (not defined in trackball.h)
1739 static float tb_project_to_sphere(float, float, float);
1740 static void normalize_quat(float [4]);
1751 vset(float *v, float x, float y, float z)
1759 vsub(const float *src1, const float *src2, float *dst)
1761 dst[0] = src1[0] - src2[0];
1762 dst[1] = src1[1] - src2[1];
1763 dst[2] = src1[2] - src2[2];
1767 vcopy(const float *v1, float *v2)
1770 for (i = 0 ; i < 3 ; i++)
1775 vcross(const float *v1, const float *v2, float *cross)
1779 temp[0] = (v1[1] * v2[2]) - (v1[2] * v2[1]);
1780 temp[1] = (v1[2] * v2[0]) - (v1[0] * v2[2]);
1781 temp[2] = (v1[0] * v2[1]) - (v1[1] * v2[0]);
1786 vlength(const float *v)
1788 float tmp = v[0] * v[0] + v[1] * v[1] + v[2] * v[2];
1793 vscale(float *v, float div)
1803 vscale(v,1.0/vlength(v));
1807 vdot(const float *v1, const float *v2)
1809 return v1[0]*v2[0] + v1[1]*v2[1] + v1[2]*v2[2];
1813 vadd(const float *src1, const float *src2, float *dst)
1815 dst[0] = src1[0] + src2[0];
1816 dst[1] = src1[1] + src2[1];
1817 dst[2] = src1[2] + src2[2];
1821 * Given an axis and angle, compute quaternion.
1824 axis_to_quat(float a[3], float phi, float q[4])
1826 double sinphi2, cosphi2;
1827 double phi2 = phi/2.0;
1828 sinphi2 = sin(phi2);
1829 cosphi2 = cos(phi2);
1837 * Project an x,y pair onto a sphere of radius r OR a hyperbolic sheet
1838 * if we are away from the center of the sphere.
1841 tb_project_to_sphere(float r, float x, float y)
1847 if (d < r * 0.70710678118654752440) { /* Inside sphere */
1850 } else { /* On hyperbola */
1851 t = r / 1.41421356237309504880;
1858 * Quaternions always obey: a^2 + b^2 + c^2 + d^2 = 1.0
1859 * If they don't add up to 1.0, dividing by their magnitued will
1862 * Note: See the following for more information on quaternions:
1864 * - Shoemake, K., Animating rotation with quaternion curves, Computer
1865 * Graphics 19, No 3 (Proc. SIGGRAPH'85), 245-254, 1985.
1866 * - Pletinckx, D., Quaternion calculus as a basic tool in computer
1867 * graphics, The Visual Computer 5, 2-13, 1989.
1870 normalize_quat(float q[4])
1875 tmp = q[0]*q[0] + q[1]*q[1] + q[2]*q[2] + q[3]*q[3];
1876 mag = 1.0 / SQRT(tmp);
1877 for (i = 0; i < 4; i++)
1882 * Ok, simulate a track-ball. Project the points onto the virtual
1883 * trackball, then figure out the axis of rotation, which is the cross
1884 * product of P1 P2 and O P1 (O is the center of the ball, 0,0,0)
1885 * Note: This is a deformed trackball-- is a trackball in the center,
1886 * but is deformed into a hyperbolic sheet of rotation away from the
1887 * center. This particular function was chosen after trying out
1888 * several variations.
1890 * It is assumed that the arguments to this routine are in the range
1894 trackball(float q[4], float p1x, float p1y, float p2x, float p2y)
1896 float a[3]; /* Axis of rotation */
1897 float phi; /* how much to rotate about axis */
1898 float p1[3], p2[3], d[3];
1901 if (p1x == p2x && p1y == p2y) {
1909 * First, figure out z-coordinates for projection of P1 and P2 to
1912 vset(p1,p1x,p1y,tb_project_to_sphere(TRACKBALLSIZE,p1x,p1y));
1913 vset(p2,p2x,p2y,tb_project_to_sphere(TRACKBALLSIZE,p2x,p2y));
1916 * Now, we want the cross product of P1 and P2
1921 * Figure out how much to rotate around that axis.
1924 t = vlength(d) / (2.0*TRACKBALLSIZE);
1927 * Avoid problems with out-of-control values...
1929 if (t > 1.0) t = 1.0;
1930 if (t < -1.0) t = -1.0;
1931 phi = 2.0 * asin(t);
1933 axis_to_quat(a,phi,q);
1937 * Given two rotations, e1 and e2, expressed as quaternion rotations,
1938 * figure out the equivalent single rotation and stuff it into dest.
1940 * This routine also normalizes the result every RENORMCOUNT times it is
1941 * called, to keep error from creeping in.
1943 * NOTE: This routine is written so that q1 or q2 may be the same
1944 * as dest (or each other).
1947 #define RENORMCOUNT 97
1950 add_quats(float q1[4], float q2[4], float dest[4])
1953 float t1[4], t2[4], t3[4];
1957 printf("q1 = %f %f %f %f\n", q1[0], q1[1], q1[2], q1[3]);
1958 printf("q2 = %f %f %f %f\n", q2[0], q2[1], q2[2], q2[3]);
1970 tf[3] = q1[3] * q2[3] - vdot(q1,q2);
1973 printf("tf = %f %f %f %f\n", tf[0], tf[1], tf[2], tf[3]);
1981 if (++count > RENORMCOUNT) {
1983 normalize_quat(dest);
1988 * Build a rotation matrix, given a quaternion rotation.
1992 build_rotmatrix(float m[4][4], float q[4])
1994 //#define TRANSPOSED_QUAT
1995 #ifndef TRANSPOSED_QUAT
1996 m[0][0] = 1.0 - 2.0 * (q[1] * q[1] + q[2] * q[2]);
1997 m[0][1] = 2.0 * (q[0] * q[1] - q[2] * q[3]);
1998 m[0][2] = 2.0 * (q[2] * q[0] + q[1] * q[3]);
2001 m[1][0] = 2.0 * (q[0] * q[1] + q[2] * q[3]);
2002 m[1][1]= 1.0 - 2.0 * (q[2] * q[2] + q[0] * q[0]);
2003 m[1][2] = 2.0 * (q[1] * q[2] - q[0] * q[3]);
2006 m[2][0] = 2.0 * (q[2] * q[0] - q[1] * q[3]);
2007 m[2][1] = 2.0 * (q[1] * q[2] + q[0] * q[3]);
2008 m[2][2] = 1.0 - 2.0 * (q[1] * q[1] + q[0] * q[0]);
2015 #else // TRANSPOSED_QUAT
2016 m[0][0] = 1.0 - 2.0 * (q[1] * q[1] + q[2] * q[2]);
2017 m[0][1] = 2.0 * (q[0] * q[1] + q[2] * q[3]);
2018 m[0][2] = 2.0 * (q[2] * q[0] - q[1] * q[3]);
2021 m[1][0] = 2.0 * (q[0] * q[1] - q[2] * q[3]);
2022 m[1][1] = 1.0 - 2.0 * (q[2] * q[2] + q[0] * q[0]);
2023 m[1][2] = 2.0 * (q[1] * q[2] + q[0] * q[3]);
2026 m[2][0] = 2.0 * (q[2] * q[0] + q[1] * q[3]);
2027 m[2][1] = 2.0 * (q[1] * q[2] - q[0] * q[3]);
2028 m[2][2] = 1.0 - 2.0 * (q[1] * q[1] + q[0] * q[0]);