]> git.mxchange.org Git - flightgear.git/blobdiff - src/GUI/mouse.cxx
Moved some of the low level scene graph construction code over to simgear.
[flightgear.git] / src / GUI / mouse.cxx
index 1bd1e5be8cb4775df5693a3d8225b51c69479797..4f63d7c4f522a2e26b572b747a78a8e47c9d9c92 100644 (file)
@@ -38,8 +38,7 @@
 #  include <windows.h>
 #endif
 
-#include <GL/glut.h>
-#include <GL/gl.h>
+#include GLUT_H
 
 #if defined(FX) && defined(XMESA)
 #  include <GL/xmesa.h>
 #include "gui_local.hxx"
 
 SG_USING_STD(string);
-
-#ifndef SG_HAVE_NATIVE_SGI_COMPILERS
 SG_USING_STD(cout);
-#endif
 
 /* --------------------------------------------------------------------
 Mouse stuff
@@ -107,6 +103,11 @@ static int glut_active_alt = 0;
 static int MOUSE_XSIZE = 0;
 static int MOUSE_YSIZE = 0;
 
+// uncomment this for view to exactly follow mouse in MOUSE_VIEW mode
+// else smooth out the view panning to .01 radian per frame
+// see view_offset smoothing mechanism in main.cxx
+#define NO_SMOOTH_MOUSE_VIEW
+
 // uncomment following to
 #define RESET_VIEW_ON_LEAVING_MOUSE_VIEW
 
@@ -170,34 +171,30 @@ static inline int right_button( void ) {
 
 static inline void set_goal_view_offset( float offset )
 {
-       globals->get_current_view()->set_goal_view_offset(offset);
+       globals->get_current_view()->setGoalHeadingOffset_deg(offset * SGD_RADIANS_TO_DEGREES);
 }
 
 static inline void set_view_offset( float offset )
 {
-       globals->get_current_view()->set_view_offset(offset);
-}
-
-static inline float get_view_offset() {
-       return globals->get_current_view()->get_view_offset();
-}
-
-static inline float get_goal_view_offset() {
-       return globals->get_current_view()->get_goal_view_offset();
+       globals->get_current_view()->setHeadingOffset_deg(offset * SGD_RADIANS_TO_DEGREES);
 }
 
 static inline void set_goal_view_tilt( float tilt )
 {
-       globals->get_current_view()->set_goal_view_tilt(tilt);
+       globals->get_current_view()->setGoalPitchOffset_deg(tilt);
 }
 
 static inline void set_view_tilt( float tilt )
 {
-       globals->get_current_view()->set_view_tilt(tilt);
+       globals->get_current_view()->setPitchOffset_deg(tilt);
 }
 
-static inline float get_view_tilt() {
-       return globals->get_current_view()->get_view_tilt();
+static inline float get_view_offset() {
+       return globals->get_current_view()->getHeadingOffset_deg() * SGD_DEGREES_TO_RADIANS;
+}
+
+static inline float get_goal_view_offset() {
+       return globals->get_current_view()->getGoalHeadingOffset_deg() * SGD_DEGREES_TO_RADIANS;
 }
 
 static inline void move_brake(float offset) {
@@ -233,11 +230,11 @@ static inline float get_elevator() {
 }
 
 static inline bool AP_HeadingEnabled() {
-       return current_autopilot->get_HeadingEnabled();
+       return globals->get_autopilot()->get_HeadingEnabled();
 }
 
 static inline bool AP_AltitudeEnabled() {
-       return current_autopilot->get_AltitudeEnabled();
+       return globals->get_autopilot()->get_AltitudeEnabled();
 }
 
 void TurnCursorOn( void )
@@ -326,7 +323,9 @@ void CenterView( void ) {
        glutSetCursor(GLUT_CURSOR_INHERIT);
 
        // Is this necessary ??
+#if defined(FG_OLD_MENU)
        if( !gui_menu_on )   TurnCursorOff();
+#endif
 
        glutWarpPointer( _savedX, _savedY );
     }
@@ -371,6 +370,7 @@ void guiMotionFunc ( int x, int y )
     wh = MOUSE_YSIZE;
 
     if (mouse_mode == MOUSE_POINTER) {
+#if defined(FG_OLD_MENU)
         // TURN MENU ON IF MOUSE AT TOP
         if( y < 1 ) {
             if( !gui_menu_on )
@@ -381,6 +381,7 @@ void guiMotionFunc ( int x, int y )
             if( gui_menu_on )
                 guiToggleMenu();                       
         }
+#endif
         puMouse ( x, y ) ;
         glutPostRedisplay () ;
     } else {
@@ -425,10 +426,19 @@ void guiMotionFunc ( int x, int y )
                 
             case MOUSE_VIEW:
                 if( y <= 0 ) {
+#define CONTRAINED_MOUSE_VIEW_Y
+#ifdef CONTRAINED_MOUSE_VIEW_Y
                     y = 1;
+#else
+                    y = wh-2;
+#endif // CONTRAINED_MOUSE_VIEW_Y
                     need_warp = 1;
                 } else if( y >= wh-1) {
+#ifdef CONTRAINED_MOUSE_VIEW_Y
                     y = wh-2;
+#else
+                    y = 1;
+#endif // CONTRAINED_MOUSE_VIEW_Y
                     need_warp = 1;
                 }
                 // wrap MOUSE_VIEW mode cursor x position
@@ -439,20 +449,51 @@ void guiMotionFunc ( int x, int y )
                     need_warp = 1;
                     x = 1;
                 }
-
-               {
-                   float scale = SGD_PI / MOUSE_XSIZE;
-                   float dx = (_mX - x) * scale;
-                   float dy = (_mY - y) * scale;
-                   
-                   float newOffset = get_view_offset() + dx;
-                   set_goal_view_offset(newOffset);
-                   set_view_offset(newOffset);
-                   
-                   float newTilt = get_view_tilt() + dy;
-                   set_goal_view_tilt(newTilt);
-                   set_view_tilt(newTilt);
-               }
+                // try to get SGD_PI movement in each half of screen
+                // do spherical pan
+                W = ww;
+                H = wh;
+                if( middle_button() ) {
+                    trackball(lastGuiQuat,
+                              (2.0f * _mX - W) / W,
+                              0, //(H - 2.0f * y) / H,         // 3
+                              (2.0f * x - W) / W,
+                              0 //(H - 2.0f * _mY) / H       // 1
+                             );
+                    x = _mX;
+                    y = _mY;
+                    need_warp = 1;
+                } else {
+                    trackball(lastGuiQuat,
+                              0, //(2.0f * _mX - W) / W,  // 0
+                              (H - 2.0f * y) / H,         // 3
+                              0, //(2.0f * x - W) / W,    // 2
+                              (H - 2.0f * _mY) / H        // 1 
+                             );
+                }
+                add_quats(lastGuiQuat, curGuiQuat, curGuiQuat);
+                build_rotmatrix(GuiQuat_mat, curGuiQuat);
+                
+                // do horizontal pan
+                // this could be done in above quat
+                // but requires redoing view pipeline
+                offset = get_goal_view_offset();
+                offset += ((_mX - x) * SGD_2PI / W );
+                while (offset < 0.0) {
+                    offset += SGD_2PI;
+                }
+                while (offset > SGD_2PI) {
+                    offset -= SGD_2PI;
+                }
+                set_goal_view_offset(offset);
+                set_goal_view_tilt(asin( GuiQuat_mat[1][2]) * SGD_RADIANS_TO_DEGREES );
+#ifdef NO_SMOOTH_MOUSE_VIEW
+                set_view_offset(offset);
+                set_view_tilt(asin( GuiQuat_mat[1][2]) * SGD_RADIANS_TO_DEGREES );
+#endif
+                break;
+            
+            default:
                 break;
         }
     }
@@ -477,9 +518,6 @@ void guiMouseFunc(int button, int updown, int x, int y)
     static float _quat[4];
     static double _view_offset;
     
-    // general purpose variables
-    double offset;
-            
     glutModifiers = glutGetModifiers();
     glut_active_shift = glutModifiers & GLUT_ACTIVE_SHIFT;
     glut_active_ctrl  = glutModifiers & GLUT_ACTIVE_CTRL; 
@@ -503,6 +541,7 @@ void guiMouseFunc(int button, int updown, int x, int y)
                         y = _Vy;
                         sgCopyVec4(curGuiQuat, _quat);
                         set_goal_view_offset(_view_offset);
+                        set_goal_view_tilt(0.0);
 #ifdef NO_SMOOTH_MOUSE_VIEW
                         set_view_offset(_view_offset);
 #endif
@@ -518,8 +557,10 @@ void guiMouseFunc(int button, int updown, int x, int y)
                         Quat0();
                         _view_offset = get_goal_view_offset();
                         set_goal_view_offset(0.0);
+                        set_goal_view_tilt(0.0);
 #ifdef NO_SMOOTH_MOUSE_VIEW
                         set_view_offset(0.0);
+                        set_view_tilt(0.0);
 #endif
                     }
                     glutWarpPointer( x , y);
@@ -576,16 +617,20 @@ void guiMouseFunc(int button, int updown, int x, int y)
                     Quat0();
                     build_rotmatrix(GuiQuat_mat, curGuiQuat);
                     set_goal_view_offset(0.0);
+                    set_goal_view_tilt(0.0);
 #ifdef NO_SMOOTH_MOUSE_VIEW
                     set_view_offset(0.0);
+                    set_view_tilt(0.0);
 #endif // NO_SMOOTH_MOUSE_VIEW
 #endif // RESET_VIEW_ON_LEAVING_MOUSE_VIEW
                     glutSetCursor(GLUT_CURSOR_INHERIT);
-                    
+
+#if defined(FG_OLD_MENU)                    
 #if defined(WIN32_CURSOR_TWEAKS_OFF)
                     if(!gui_menu_on)
                         TurnCursorOff();
 #endif // WIN32_CURSOR_TWEAKS_OFF
+#endif // FG_OLD_MENU
                     break;
             } // end switch (mouse_mode)
             glutWarpPointer( x, y );
@@ -603,8 +648,8 @@ void guiMouseFunc(int button, int updown, int x, int y)
     // know what's going on.
     if (mouse_mode == MOUSE_POINTER) {
       if (!puMouse (button, updown, x,y)) {
-        if ( current_panel != NULL ) {
-          current_panel->doMouseAction(button, updown, x, y);
+        if ( globals->get_current_panel() != NULL ) {
+          globals->get_current_panel()->doMouseAction(button, updown, x, y);
         }
       }
     }
@@ -617,3 +662,6 @@ void guiMouseFunc(int button, int updown, int x, int y)
     glutPostRedisplay ();
 }
 
+
+
+