Revision: 6493
          http://playerstage.svn.sourceforge.net/playerstage/?rev=6493&view=rev
Author:   alexcb
Date:     2008-06-09 14:49:25 -0700 (Mon, 09 Jun 2008)

Log Message:
-----------
more camera improvements for zooming and moving when pitch is set

Modified Paths:
--------------
    code/stage/trunk/libstage/camera.cc
    code/stage/trunk/libstage/canvas.cc
    code/stage/trunk/libstage/stage.hh

Modified: code/stage/trunk/libstage/camera.cc
===================================================================
--- code/stage/trunk/libstage/camera.cc 2008-06-09 18:36:48 UTC (rev 6492)
+++ code/stage/trunk/libstage/camera.cc 2008-06-09 21:49:25 UTC (rev 6493)
@@ -36,3 +36,43 @@
        
        glMatrixMode (GL_MODELVIEW);
 }
+
+//TODO re-evaluate the way the camera is shifted when the mouse zooms - it 
might be possible to simplify
+void StgCamera::scale( float scale, float shift_x, float w, float shift_y, 
float h )
+{
+       float to_scale = -scale;
+       const float old_scale = _scale;
+       
+       //TODO setting up the factor can use some work
+       float factor = 1.0 + fabs( to_scale ) / 25;
+       if( factor < 1.1 )
+               factor = 1.1; //this must be greater than 1.
+       else if( factor > 2.5 )
+               factor = 2.5;
+       
+       //convert the shift distance to the range [-0.5, 0.5]
+       shift_x = shift_x / w - 0.5;
+       shift_y = shift_y / h - 0.5;
+       
+       //adjust the shift values based on the factor (this represents how much 
the positions grows/shrinks)
+       shift_x *= factor - 1.0;
+       shift_y *= factor - 1.0;
+       
+       if( to_scale > 0 ) {
+               //zoom in
+               _scale *= factor;
+               move( shift_x * w / _scale * _scale, 
+                       - shift_y * h / _scale * _scale );
+       }
+       else {
+               //zoom out
+               _scale /= factor;
+               if( _scale < 1 ) {
+                       _scale = 1;
+               } else {
+                       //shift camera to follow where mouse zoomed out
+                       move( - shift_x * w / old_scale * _scale, 
+                               shift_y * h / old_scale * _scale );
+               }
+       }
+}
\ No newline at end of file

Modified: code/stage/trunk/libstage/canvas.cc
===================================================================
--- code/stage/trunk/libstage/canvas.cc 2008-06-09 18:36:48 UTC (rev 6492)
+++ code/stage/trunk/libstage/canvas.cc 2008-06-09 21:49:25 UTC (rev 6493)
@@ -169,7 +169,7 @@
        }
       else
        {
-               camera.scale( Fl::event_dy(), Fl::event_x() - w() / 2, - ( 
Fl::event_y() - h() / 2 ) );
+               camera.scale( Fl::event_dy(),  Fl::event_x(), w(), 
Fl::event_y(), h() );
          invalidate();
        }
       return 1;

Modified: code/stage/trunk/libstage/stage.hh
===================================================================
--- code/stage/trunk/libstage/stage.hh  2008-06-09 18:36:48 UTC (rev 6492)
+++ code/stage/trunk/libstage/stage.hh  2008-06-09 21:49:25 UTC (rev 6493)
@@ -1711,19 +1711,26 @@
        void SetProjection( float pixels_width, float pixels_height, float 
y_min, float y_max ) const;
 
        
-       inline void move( float x, float y ) { 
+       inline void move( float x, float y ) {
+               //convert screen points into world points
                x = x / ( _scale );
                y = y / ( _scale );
                
+               //adjust for pitch angle
+               y = y / cos( dtor( _pitch ) );
+               
+               //adjust for yaw andle
                _x += cos( dtor( _yaw ) ) * x;
                _y += -sin( dtor( _yaw ) ) * x;
 
                _x += sin( dtor( _yaw ) ) * y;
                _y += cos( dtor( _yaw ) ) * y;
        }
+       
        inline void yaw( float yaw ) { 
                _yaw += yaw;
        }
+       
        inline void pitch( float pitch ) {
                _pitch += pitch;
                if( _pitch < -90 )
@@ -1731,6 +1738,7 @@
                else if( _pitch > 0 )
                        _pitch = 0;
        }
+       
        inline float getYaw( void ) const { return _yaw; }
        inline float getPitch( void ) const { return _pitch; }
        
@@ -1741,12 +1749,7 @@
        
        
        
-       inline void scale( float scale, float center_x = 0, float center_y = 0 
) { 
-               //TODO figure out how to zoom in centered on the given points 
(rather than just center of screen)
-               _scale -= 0.25 * scale * sqrt( _scale );
-               if( _scale < 1 ) _scale = 1;
-       }
-       
+       void scale( float scale, float shift_x = 0, float h = 0, float shift_y 
= 0, float w = 0 );      
        inline void resetAngle( void ) { _pitch = _yaw = 0; }
        
        inline float getScale() const { return _scale; }


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php
_______________________________________________
Playerstage-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/playerstage-commit

Reply via email to