Revision: 6787
          http://playerstage.svn.sourceforge.net/playerstage/?rev=6787&view=rev
Author:   jeremy_asher
Date:     2008-07-07 14:18:14 -0700 (Mon, 07 Jul 2008)

Log Message:
-----------
Fixed crash on loading empty worldfile, Added loading/saving of perspective 
camera (example in fasr.world)

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
    code/stage/trunk/libstage/worldgui.cc
    code/stage/trunk/worlds/fasr.world

Modified: code/stage/trunk/libstage/camera.cc
===================================================================
--- code/stage/trunk/libstage/camera.cc 2008-07-07 20:36:07 UTC (rev 6786)
+++ code/stage/trunk/libstage/camera.cc 2008-07-07 21:18:14 UTC (rev 6787)
@@ -11,12 +11,14 @@
 
 #include <iostream>
 
-//perspective camera
-//perspective camera
+// Perspective Camera
 StgPerspectiveCamera::StgPerspectiveCamera( void ) : 
-               _z_near( 0.2 ), _z_far( 40.0 ), _vert_fov( 40 ), _horiz_fov( 60 
), _aspect( 1.0 )
+       StgCamera(),
+       _z_near( 0.2 ), _z_far( 40.0 ),
+       _vert_fov( 70 ), _horiz_fov( 70 ),
+       _aspect( 1.0 )
 {
-       setYaw( 90 );
+       setPitch( 70.0 );
 }
 
 void StgPerspectiveCamera::move( float x, float y, float z )
@@ -84,7 +86,22 @@
        _y += cos( dtor( _yaw ) ) * amount;
 }
 
+void StgPerspectiveCamera::Load( Worldfile* wf, int sec ) {
+       float x = wf->ReadTupleFloat(sec, "pcam_loc", 0, 0 );
+       float y = wf->ReadTupleFloat(sec, "pcam_loc", 1, 0 );
+       float z = wf->ReadTupleFloat(sec, "pcam_loc", 2, 0 );
+       setPose( x, y, z );
+       setPitch( wf->ReadTupleFloat( sec, "pcam_angle", 0, 0 ) );
+       setYaw( wf->ReadTupleFloat( sec, "pcam_angle", 1, 0 ) );
+}
 
+void StgPerspectiveCamera::Save( Worldfile* wf, int sec ) {
+       wf->WriteTupleFloat( sec, "pcam_loc", 0, x() );
+       wf->WriteTupleFloat( sec, "pcam_loc", 1, y() );
+       wf->WriteTupleFloat( sec, "pcam_loc", 2, z() );
+       wf->WriteTupleFloat( sec, "pcam_angle", 0, pitch()  );
+       wf->WriteTupleFloat( sec, "pcam_angle", 1, yaw()  );
+}
 
 
 
@@ -126,6 +143,28 @@
        SetProjection();
 }
 
+void StgOrthoCamera::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 ) );
+       
+       //don't allow huge values
+       if( y > 100 ) 
+               y = 100;
+       else if( y < -100 ) 
+               y = -100;
+       
+       //adjust for yaw angle
+       _x += cos( dtor( _yaw ) ) * x;
+       _y += -sin( dtor( _yaw ) ) * x;
+       
+       _x += sin( dtor( _yaw ) ) * y;
+       _y += cos( dtor( _yaw ) ) * y;
+}
+
 //TODO re-evaluate the way the camera is shifted when the mouse zooms - it 
might be possible to simplify
 void StgOrthoCamera::scale( float scale, float shift_x, float w, float 
shift_y, float h )
 {
@@ -165,3 +204,21 @@
                }
        }
 }
+
+void StgOrthoCamera::Load( Worldfile* wf, int sec ) {
+       float x = wf->ReadTupleFloat(sec, "center", 0, 0 );
+       float y = wf->ReadTupleFloat(sec, "center", 1, 0 );
+       setPose( x, y );
+       setPitch( wf->ReadTupleFloat( sec, "rotate", 0, 0 ) );
+       setYaw( wf->ReadTupleFloat( sec, "rotate", 1, 0 ) );
+       setScale( wf->ReadFloat(sec, "scale", scale() ) );
+}
+
+void StgOrthoCamera::Save( Worldfile* wf, int sec ) {
+       wf->WriteTupleFloat( sec, "center", 0, x() );
+       wf->WriteTupleFloat( sec, "center", 1, y() );
+       wf->WriteTupleFloat( sec, "rotate", 0, pitch() );
+       wf->WriteTupleFloat( sec, "rotate", 1, yaw() );
+       wf->WriteFloat(sec, "scale", scale() );
+}
+

Modified: code/stage/trunk/libstage/canvas.cc
===================================================================
--- code/stage/trunk/libstage/canvas.cc 2008-07-07 20:36:07 UTC (rev 6786)
+++ code/stage/trunk/libstage/canvas.cc 2008-07-07 21:18:14 UTC (rev 6787)
@@ -65,8 +65,7 @@
   selected_models = NULL;
   last_selection = NULL;
 
-  perspective_camera.setPose( -3.0, 0.0, 1.0 );
-  perspective_camera.setPitch( 70.0 ); //look down
+  perspective_camera.setPose( 0.0, -4.0, 3.0 );
   current_camera = &camera;
   setDirtyBuffer();
        
@@ -266,8 +265,8 @@
                                perspective_camera.addPitch( -dy );
                        } 
                        else {
-                               camera.pitch( 0.5 * static_cast<double>( dy ) );
-                               camera.yaw( 0.5 * static_cast<double>( dx ) );
+                               camera.setPitch( 0.5 * static_cast<double>( dy 
) );
+                               camera.setYaw( 0.5 * static_cast<double>( dx ) 
);
                        }
                        invalidate();
                        redraw();
@@ -556,9 +555,9 @@
 void StgCanvas::renderFrame()
 {
        //before drawing, order all models based on distance from camera
-       float x = camera.getX();
-       float y = camera.getY();
-       float sphi = dtor( camera.getYaw() );
+       float x = camera.x();
+       float y = camera.y();
+       float sphi = dtor( camera.yaw() );
        
        //estimate point of camera location - hard to do with orthogonal mode
        x += -sin( sphi ) * 100;
@@ -681,7 +680,7 @@
                glPushMatrix();
                for( std::multimap< float, StgModel* >::reverse_iterator i = 
ordered.rbegin(); i != ordered.rend(); i++ ) {
                        //ensure two icons can't be in the exact same plane
-                       if( camera.getPitch() == 0 )
+                       if( camera.pitch() == 0 )
                                glTranslatef( 0, 0, 0.1 );
                        i->second->DrawStatusTree( this );
                }
@@ -846,14 +845,9 @@
 
 void StgCanvas::Load( Worldfile* wf, int sec )
 {
-  float x = wf->ReadTupleFloat(sec, "center", 0, 0 );
-  float y = wf->ReadTupleFloat(sec, "center", 1, 0 );
-  camera.setPose( x, y );
-  
-  camera.setPitch( wf->ReadTupleFloat( sec, "rotate", 0, 0 ) );
-  camera.setYaw( wf->ReadTupleFloat( sec, "rotate", 1, 0 ) );
-
-  camera.setScale( wf->ReadFloat(sec, "scale", camera.getScale() ) );
+  camera.Load( wf, sec );
+  perspective_camera.Load( wf, sec );          
+       
   interval = wf->ReadInt(sec, "interval", interval );
   
   showData.Load( wf, sec );
@@ -875,15 +869,9 @@
 
 void StgCanvas::Save( Worldfile* wf, int sec )
 {
-  wf->WriteFloat( sec, "scale", camera.getScale() );
-  
-  wf->WriteTupleFloat( sec, "center", 0, camera.getX() );
-  wf->WriteTupleFloat( sec, "center", 1, camera.getY() );
-  
-  wf->WriteTupleFloat( sec, "rotate", 0, camera.getPitch()  );
-  wf->WriteTupleFloat( sec, "rotate", 1, camera.getYaw()  );
-  
-  wf->WriteFloat(sec, "scale", camera.getScale() );
+  camera.Save( wf, sec );
+  perspective_camera.Save( wf, sec );  
+       
   wf->WriteInt(sec, "interval", interval );
 
   showData.Save( wf, sec );

Modified: code/stage/trunk/libstage/model.cc
===================================================================
--- code/stage/trunk/libstage/model.cc  2008-07-07 20:36:07 UTC (rev 6786)
+++ code/stage/trunk/libstage/model.cc  2008-07-07 21:18:14 UTC (rev 6787)
@@ -961,7 +961,7 @@
                else {
                  pitch = canvas->current_camera->pitch();
                  yaw = canvas->current_camera->yaw();                  
-                 scale = canvas->camera.getScale();
+                 scale = canvas->camera.scale();
                }
        
                float robotAngle = -rtod(pose.a);

Modified: code/stage/trunk/libstage/stage.hh
===================================================================
--- code/stage/trunk/libstage/stage.hh  2008-07-07 20:36:07 UTC (rev 6786)
+++ code/stage/trunk/libstage/stage.hh  2008-07-07 21:18:14 UTC (rev 6787)
@@ -1805,7 +1805,6 @@
 class StgPerspectiveCamera : public StgCamera
 {
        private:
-
                float _z_near;
                float _z_far;
                float _vert_fov;
@@ -1849,6 +1848,9 @@
                inline float nearClip( void ) const { return _z_near; }
                inline float farClip( void ) const { return _z_far; }
                inline void setClip( float near, float far ) { _z_far = far; 
_z_near = near; }
+       
+               void Load( Worldfile* wf, int sec );
+               void Save( Worldfile* wf, int sec );
 };
 
 class StgOrthoCamera : public StgCamera
@@ -1867,33 +1869,9 @@
                virtual void SetProjection( float pixels_width, float 
pixels_height, float y_min, float y_max );
                virtual void SetProjection( void ) const;
 
-               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 ) );
-
-                       //don't allow huge values
-                       if( y > 100 ) 
-                               y = 100;
-                       else if( y < -100 ) 
-                               y = -100;
-
-                       //adjust for yaw angle
-                       _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 ) {
+               void move( float x, float y );
+               inline void setYaw( float yaw ) { _yaw += yaw;  }
+               inline void setPitch( float pitch ) {
                        _pitch += pitch;
                        if( _pitch < -90 )
                                _pitch = -90;
@@ -1901,22 +1879,16 @@
                                _pitch = 0;
                }
 
-               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; }
                inline void setScale( float scale ) { _scale = scale; }
                inline void setPose( float x, float y) { _x = x; _y = y; }
 
-
-
                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; }
-               inline float getX() const { return _x; }
-               inline float getY() const { return _y; }
+               inline float scale() const { return _scale; }
+
+               void Load( Worldfile* wf, int sec );
+               void Save( Worldfile* wf, int sec );
 };
 
 

Modified: code/stage/trunk/libstage/worldgui.cc
===================================================================
--- code/stage/trunk/libstage/worldgui.cc       2008-07-07 20:36:07 UTC (rev 
6786)
+++ code/stage/trunk/libstage/worldgui.cc       2008-07-07 21:18:14 UTC (rev 
6787)
@@ -141,7 +141,8 @@
   // improve the title bar to say "Stage: <worldfile name>"
   std::string title = PROJECT;
   title += ": ";
-  title += L;
+  if ( L )
+    title += L;
   label( title.c_str() );
 
   interval_real = (stg_usec_t)thousand * DEFAULT_INTERVAL_REAL;

Modified: code/stage/trunk/worlds/fasr.world
===================================================================
--- code/stage/trunk/worlds/fasr.world  2008-07-07 20:36:07 UTC (rev 6786)
+++ code/stage/trunk/worlds/fasr.world  2008-07-07 21:18:14 UTC (rev 6787)
@@ -22,9 +22,13 @@
 window
 ( 
   size [ 601.000 605.000 ] 
+
   center [ 0 0 ] 
   rotate [ 0 0 ]
   scale 32.344 
+
+  pcam_loc [ 0 -4 2 ]
+  pcam_angle [ 70.000 0 ]
   
   show_data 0
   show_flags 1


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

-------------------------------------------------------------------------
Sponsored by: SourceForge.net Community Choice Awards: VOTE NOW!
Studies have shown that voting for your favorite open source project,
along with a healthy diet, reduces your potential for chronic lameness
and boredom. Vote Now at http://www.sourceforge.net/community/cca08
_______________________________________________
Playerstage-commit mailing list
Playerstage-commit@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/playerstage-commit

Reply via email to