[GRASS-SVN] r49280 - in grass/trunk: gui/wxpython/gui_modules lib/nviz

svn_grass at osgeo.org svn_grass at osgeo.org
Wed Nov 16 15:39:53 EST 2011


Author: annakrat
Date: 2011-11-16 12:39:53 -0800 (Wed, 16 Nov 2011)
New Revision: 49280

Modified:
   grass/trunk/gui/wxpython/gui_modules/nviz_mapdisp.py
   grass/trunk/gui/wxpython/gui_modules/preferences.py
   grass/trunk/lib/nviz/change_view.c
Log:
wxNviz: fix last commit (forgot to commit changes in nviz library), change flythrough behaviour

Modified: grass/trunk/gui/wxpython/gui_modules/nviz_mapdisp.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/nviz_mapdisp.py	2011-11-16 20:32:18 UTC (rev 49279)
+++ grass/trunk/gui/wxpython/gui_modules/nviz_mapdisp.py	2011-11-16 20:39:53 UTC (rev 49280)
@@ -121,8 +121,8 @@
         self.dragid = -1
         self.hitradius = 5
         # layer manager toolwindow
-        self.toolWin = None        
-    
+        self.toolWin = None
+        
         if self.lmgr:
             self.log = self.lmgr.goutput
             logerr = self.lmgr.goutput.GetLog(err = True)
@@ -194,9 +194,11 @@
                     'move' : UserSettings.Get(group = 'nviz', key = 'fly', subkey = ['exag', 'move']),
                     'turn' : UserSettings.Get(group = 'nviz', key = 'fly', subkey = ['exag', 'turn'])},
                'exagMultiplier' : 3,        # speed up by Shift
+               'flySpeed' : 4,              # speed of flying
                'mouseControl' : None,       # if mouse or keys are used
                'pos' : {'x' : 0, 'y' : 0},  # virtual mouse position when using arrows
                'arrowStep' : 50,            # step in pixels (when using arrows)
+               'flySpeedStep' : 2,
             }
             
         return fly
@@ -261,13 +263,20 @@
         self.fly['value'] = [0, 0, 0]
         
         if self.fly['mode'] == 0:
-            self.fly['value'][0] = - my * 500.0 * self.fly['interval'] / 1000. # forward */
-            self.fly['value'][1] = mx * 0.1 *self.fly['interval'] / 1000.  # heading */
+            self.fly['value'][0] = self.fly['flySpeed'] * self.fly['interval'] / 1000. # forward */
+            self.fly['value'][1] = mx * 0.1 * self.fly['interval'] / 1000. # heading 
+            self.fly['value'][2] = my * 0.1 * self.fly['interval'] / 1000. # pitch 
         else:
             self.fly['value'][0] = mx * 100.0 * self.fly['interval'] /1000.
             self.fly['value'][2] = - my * 100.0 * self.fly['interval'] /1000.
     
-    
+    def ChangeFlySpeed(self, increase):
+        """!Increase/decrease flight spped"""
+        if increase:
+            self.fly['flySpeed'] += self.fly['flySpeedStep']
+        else:
+            self.fly['flySpeed'] -= self.fly['flySpeedStep']
+        
     def __del__(self):
         """!Stop timers if running, unload data"""
         self.StopTimer(self.timerAnim)
@@ -541,15 +550,28 @@
             self.Refresh(False)
             
         elif key in (wx.WXK_UP, wx.WXK_DOWN, wx.WXK_LEFT, wx.WXK_RIGHT):
-            if not self.timerFly.IsRunning():
-                sx, sy = self.GetClientSizeTuple()
-                self.fly['pos']['x'] = sx / 2
-                self.fly['pos']['y'] = sy / 2
-                self.fly['mouseControl'] = False # controlled by keyboard
-                self.timerFly.Start(self.fly['interval'])
-
-            self.ProcessFlyByArrows(keyCode = key)
+            if not self.fly['mouseControl']:
+                if not self.timerFly.IsRunning():
+                    sx, sy = self.GetClientSizeTuple()
+                    self.fly['pos']['x'] = sx / 2
+                    self.fly['pos']['y'] = sy / 2
+                    self.fly['mouseControl'] = False # controlled by keyboard
+                    self.timerFly.Start(self.fly['interval'])
+    
+                self.ProcessFlyByArrows(keyCode = key)
+                
+            # change speed of flight when using mouse
+            else:
+                if key == wx.WXK_UP:
+                    self.ChangeFlySpeed(increase = True)
+                elif key == wx.WXK_DOWN:
+                    self.ChangeFlySpeed(increase = False)
         
+        elif key in (wx.WXK_HOME, wx.WXK_PAGEUP) and self.timerFly.IsRunning():
+            self.ChangeFlySpeed(increase = True)
+        elif key in (wx.WXK_END, wx.WXK_PAGEDOWN) and self.timerFly.IsRunning():
+            self.ChangeFlySpeed(increase = False)
+            
         event.Skip()
         
     def ProcessFlyByArrows(self, keyCode):
@@ -609,7 +631,13 @@
         """!Change perspective"""
         wheel = event.GetWheelRotation()
         Debug.msg (5, "GLWindow.OnMouseMotion(): wheel = %d" % wheel)
-        self.DoZoom(zoomtype = wheel, pos = event.GetPositionTuple())
+        if self.timerFly.IsRunning() and self.fly['mouseControl']:
+            if wheel > 0:
+                self.ChangeFlySpeed(increase = True)
+            else:
+                self.ChangeFlySpeed(increase = False)
+        else:
+            self.DoZoom(zoomtype = wheel, pos = event.GetPositionTuple())
             
         # update statusbar
         ### self.parent.StatusbarUpdate()

Modified: grass/trunk/gui/wxpython/gui_modules/preferences.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/preferences.py	2011-11-16 20:32:18 UTC (rev 49279)
+++ grass/trunk/gui/wxpython/gui_modules/preferences.py	2011-11-16 20:39:53 UTC (rev 49280)
@@ -545,8 +545,8 @@
                     },
                 'fly' : {
                     'exag' : {
-                        'move' : 1,
-                        'turn' : 1,
+                        'move' : 5,
+                        'turn' : 5,
                         }
                     },
                 'animation' : {

Modified: grass/trunk/lib/nviz/change_view.c
===================================================================
--- grass/trunk/lib/nviz/change_view.c	2011-11-16 20:32:18 UTC (rev 49279)
+++ grass/trunk/lib/nviz/change_view.c	2011-11-16 20:39:53 UTC (rev 49280)
@@ -127,6 +127,25 @@
     return 1;
 }
 
+void Nviz_get_viewpoint_position(double *x_pos, double *y_pos)
+{
+    float from[3];
+    double xpos, ypos;
+
+    GS_get_from(from);
+    xpos = (from[X] + RANGE_OFFSET) / RANGE;
+    ypos = (from[Y] + RANGE_OFFSET) / RANGE;
+    *x_pos = xpos;
+    *x_pos = (*x_pos < 0) ? 0 : (*x_pos > 1.0) ? 1.0 : *x_pos;
+    *y_pos = 1.0 - ypos;
+    *y_pos = (*y_pos < 0) ? 0 : (*y_pos > 1.0) ? 1.0 : *y_pos;
+
+    if (xpos < 0.0 || xpos > 1.0 || ypos < 0.0 || ypos > 1.0) {
+	G_debug(3, "Invalid view position coordinates, using %f,%f",
+		  *x_pos, 1.0 - *y_pos);
+    }
+}
+
 /*!
    \brief Change viewpoint height
 
@@ -159,6 +178,16 @@
     return 1;
 }
 
+void Nviz_get_viewpoint_height(double *height)
+{
+    float from[3];
+
+    G_debug(1, "Nviz_get_viewpoint_height():");
+
+    GS_get_from_real(from);
+
+    *height = from[Z];
+}
 /*!
    \brief Change viewpoint perspective (field of view)
 
@@ -292,7 +321,7 @@
 */
 void Nviz_flythrough(nv_data *data, float *fly_info, int *scale, int lateral)
 {
-    float dir[3], from[4], cur_from[4], cur_dir[4], cur[3];
+    float dir[3], from[4], cur_from[4], cur_dir[4];
     float speed, h, p, sh, ch, sp, cp;
     float diff_x, diff_y, diff_z;
     float quasi_zero;
@@ -308,8 +337,8 @@
     speed = scale[0] * fly_info[0];
 
     h += scale[1] * fly_info[1]; /* change heading */
-    //if (!lateral)   /* in case of "lateral" doesn't change pitch */
-        //p -= scale * fly_info[2];
+    if (!lateral)   /* in case of "lateral" doesn't change pitch */
+        p -= scale[1] * fly_info[2];
 
     h = fmod(h + M_PI, 2 * M_PI) - M_PI;
 



More information about the grass-commit mailing list