Revision: 6491
          http://playerstage.svn.sourceforge.net/playerstage/?rev=6491&view=rev
Author:   alexcb
Date:     2008-06-09 11:34:44 -0700 (Mon, 09 Jun 2008)

Log Message:
-----------
fixed scale issue with recent camera changes

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

Modified: code/stage/trunk/libstage/camera.cc
===================================================================
--- code/stage/trunk/libstage/camera.cc 2008-06-09 15:24:07 UTC (rev 6490)
+++ code/stage/trunk/libstage/camera.cc 2008-06-09 18:34:44 UTC (rev 6491)
@@ -12,28 +12,27 @@
 
 #include <iostream>
 
-void StgCamera::Draw( void )
+void StgCamera::Draw( void ) const
 {      
-       static float i = 0;
-       i += 1;
-//     glRotatef( rtod(-_stheta), fabs(cos(_sphi)), 0, 0 );
-//     glRotatef( rtod(_sphi), 0,0,1 );   // rotate about z - yaw
-//     
-//     glTranslatef(  -_panx, -_pany, 0 );
-//     glScalef( _scale, _scale, _scale ); 
-
+       glMatrixMode (GL_MODELVIEW);
+       glLoadIdentity ();
        
        glRotatef( _pitch, 1.0, 0.0, 0.0 );
        glRotatef( _yaw, 0.0, 0.0, 1.0 );
        
-       //both of these are handled in the glOrtho call
-//     glScalef( _scale, _scale, _scale );
-       glTranslatef( - _x * _scale, - _y * _scale, 0.0 );
-       glScalef( _scale, _scale, _scale );
-               
-//     glRotatef( 60.0, 1.0, 0.0, 0.0 );
+       glTranslatef( - _x, - _y, 0.0 );
+       //zooming needs to happen in the Projection code (don't use glScale for 
zoom)
+       
+}
 
-       //glRotatef( 60, 0.0, 1.0, 0.0 );
-//     glRotatef( i, 0.0, 0.0, 1.0 );
+void StgCamera::SetProjection( float pixels_width, float pixels_height, float 
y_min, float y_max ) const
+{
+       glMatrixMode (GL_PROJECTION);
+       glLoadIdentity ();
        
+       glOrtho( -pixels_width/2.0 / _scale, pixels_width/2.0 / _scale,
+                       -pixels_height/2.0 / _scale, pixels_height/2.0 / _scale,
+                       y_min * _scale * 2, y_max * _scale * 2 );       
+       
+       glMatrixMode (GL_MODELVIEW);
 }

Modified: code/stage/trunk/libstage/canvas.cc
===================================================================
--- code/stage/trunk/libstage/canvas.cc 2008-06-09 15:24:07 UTC (rev 6490)
+++ code/stage/trunk/libstage/canvas.cc 2008-06-09 18:34:44 UTC (rev 6491)
@@ -169,7 +169,7 @@
        }
       else
        {
-               camera.scale( Fl::event_dy() );
+               camera.scale( Fl::event_dy(), Fl::event_x() - w() / 2, - ( 
Fl::event_y() - h() / 2 ) );
          invalidate();
        }
       return 1;
@@ -374,70 +374,23 @@
       // install a font
       gl_font( FL_HELVETICA, 12 );
       
-      //double zclip = 20 * scale; //hypot(world->Width(), world->Height()) * 
scale;
-      double pixels_width =  w();
-      double pixels_height = h();
+               stg_bounds3d_t extent = world->GetExtent();
+               camera.SetProjection( w(), h(), extent.y.min, extent.y.max );
+               camera.Draw();
       
-      // map the viewport to pixel units by scaling it the same as the window
-      glMatrixMode (GL_PROJECTION);
-      glLoadIdentity ();      
-      
 
-      stg_bounds3d_t extent = world->GetExtent();
       
-//             glFrustum( -pixels_width/2.0, pixels_width/2.0,
-//                             -pixels_height/2.0, pixels_height/2.0,
-//                             extent.y.min, extent.y.max );
-//             glOrtho( -pixels_width/2.0, pixels_width/2.0,
-//                             -pixels_height/2.0, pixels_height/2.0,
-//                             extent.y.min*scale, extent.y.max*scale );
-            
-      // set the modelview matrix
-      glMatrixMode (GL_MODELVIEW);      
-      glLoadIdentity ();
-      
-               //TODO insert a camera class here
 
-               camera.Draw();
-               
-//      // move the next two lines...
-//      glTranslatef(  -panx, -pany, 0 );
-//      glScalef( scale, scale, scale ); 
-//      // .. from here
-//      
-//      glRotatef( rtod(-stheta), fabs(cos(sphi)), 0, 0 );
-//      glRotatef( rtod(sphi), 0,0,1 );   // rotate about z - yaw
-      
-      // ... to here to get rotation about the center of the window (but 
broken panning)
-
-      // enable vertex arrays
+               // enable vertex arrays
       glEnableClientState( GL_VERTEX_ARRAY );
       //glEnableClientState( GL_COLOR_ARRAY );
 
       glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
-    }      
-
-       glMatrixMode (GL_PROJECTION);
-       glLoadIdentity ();      
+    }            
        
        
-       stg_bounds3d_t extent = world->GetExtent();
-       double pixels_width =  w();
-       double pixels_height = h();
 
-//     gluPerspective( 60, pixels_width / pixels_height, 0.01, 1000 );
        
-       
-       
-       glOrtho( -pixels_width/2.0 / camera.getScale(), pixels_width/2.0 / 
camera.getScale(),
-                         -pixels_height/2.0 / camera.getScale(), 
pixels_height/2.0 / camera.getScale(),
-                         extent.y.min * camera.getScale() * 2, extent.y.max * 
camera.getScale() * 2 );
-       
-       //draw camera
-       glMatrixMode (GL_MODELVIEW);      
-       glLoadIdentity ();
-       camera.Draw();
-       
   if( ! (showflags & STG_SHOW_TRAILS) )
   glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
 

Modified: code/stage/trunk/libstage/model.cc
===================================================================
--- code/stage/trunk/libstage/model.cc  2008-06-09 15:24:07 UTC (rev 6490)
+++ code/stage/trunk/libstage/model.cc  2008-06-09 18:34:44 UTC (rev 6491)
@@ -971,7 +971,8 @@
   {
          float stheta = -dtor( canvas->camera.getPitch() );
          float sphi = dtor( canvas->camera.getYaw() );
-         float scale = canvas->camera.getScale(); //TODO FIX THIS
+         float scale = canvas->camera.getScale();
+
     glPushMatrix();
     
     // move above the robot

Modified: code/stage/trunk/libstage/stage.hh
===================================================================
--- code/stage/trunk/libstage/stage.hh  2008-06-09 15:24:07 UTC (rev 6490)
+++ code/stage/trunk/libstage/stage.hh  2008-06-09 18:34:44 UTC (rev 6491)
@@ -1707,32 +1707,32 @@
        
 public:
        StgCamera( void ) : _x( 0 ), _y( 0 ), _z( 0 ), _pitch( 0 ), _yaw( 0 ), 
_scale( 15 ) { }
-       void Draw();
+       void Draw() const;
+       void SetProjection( float pixels_width, float pixels_height, float 
y_min, float y_max ) const;
+
        
-       void move( float x, float y ) { 
-               x = x / ( _scale * _scale );
-               y = y / ( _scale * _scale );
+       inline void move( float x, float y ) { 
+               x = x / ( _scale );
+               y = y / ( _scale );
                
-               std::cout << _scale << std::endl;
-               
                _x += cos( dtor( _yaw ) ) * x;
                _y += -sin( dtor( _yaw ) ) * x;
 
                _x += sin( dtor( _yaw ) ) * y;
                _y += cos( dtor( _yaw ) ) * y;
        }
-       void yaw( float yaw ) { 
+       inline void yaw( float yaw ) { 
                _yaw += yaw;
        }
-       void pitch( float pitch ) {
+       inline void pitch( float pitch ) {
                _pitch += pitch;
                if( _pitch < -90 )
                        _pitch = -90;
                else if( _pitch > 0 )
                        _pitch = 0;
        }
-       inline float getYaw( void ) { return _yaw; }
-       inline float getPitch( void ) { return _pitch; }
+       inline float getYaw( void ) const { return _yaw; }
+       inline float getPitch( void ) const { return _pitch; }
        
        inline void setYaw( float yaw ) { _yaw = yaw; }
        inline void setPitch( float pitch ) { _pitch = pitch; }
@@ -1741,16 +1741,17 @@
        
        
        
-       void scale( float scale ) { _scale -= 0.5 * scale;
+       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;
-               
        }
        
        inline void resetAngle( void ) { _pitch = _yaw = 0; }
        
-       inline float getScale() { return _scale; }
-       inline float getX() { return _x; }
-       inline float getY() { return _y; }
+       inline float getScale() const { return _scale; }
+       inline float getX() const { return _x; }
+       inline float getY() const { return _y; }
 };
        
 class StgCanvas : public Fl_Gl_Window


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