Revision: 6746
          http://playerstage.svn.sourceforge.net/playerstage/?rev=6746&view=rev
Author:   alexcb
Date:     2008-07-02 17:27:06 -0700 (Wed, 02 Jul 2008)

Log Message:
-----------
reset camera now centers world and scales to display everything

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

Modified: code/stage/trunk/libstage/canvas.cc
===================================================================
--- code/stage/trunk/libstage/canvas.cc 2008-07-03 00:02:27 UTC (rev 6745)
+++ code/stage/trunk/libstage/canvas.cc 2008-07-03 00:27:06 UTC (rev 6746)
@@ -365,9 +365,7 @@
          camera.resetAngle();
          //invalidate();
          if( Fl::event_state( FL_CTRL ) ) {
-           //do a complete reset
-           camera.setPose( 0.0, 0.0 );
-           camera.setScale( 10.0 );
+                 resetCamera();
          }
          redraw();
          break;
@@ -478,6 +476,36 @@
   LISTMETHOD( world->StgWorld::children, StgModel*, DrawBlocksTree );
 }
 
+void StgCanvas::resetCamera()
+{
+       float max_x = 0, max_y = 0, min_x = 0, min_y = 0;
+       
+       //TODO take orrientation ( `a' ) and geom.pose offset into consideration
+       for( GList* it=world->StgWorld::children; it; it=it->next ) {
+               StgModel* ptr = (StgModel*) it->data;
+               stg_pose_t pose = ptr->GetPose();
+               stg_geom_t geom = ptr->GetGeom();
+               
+               float tmp_min_x = pose.x - geom.size.x / 2.0;
+               float tmp_max_x = pose.x + geom.size.x / 2.0;
+               float tmp_min_y = pose.y - geom.size.y / 2.0;
+               float tmp_max_y = pose.y + geom.size.y / 2.0;
+               
+               if( tmp_min_x < min_x ) min_x = tmp_min_x;
+               if( tmp_max_x > max_x ) max_x = tmp_max_x;
+               if( tmp_min_y < min_y ) min_y = tmp_min_y;
+               if( tmp_max_y > max_y ) max_y = tmp_max_y;
+       }
+       
+       //do a complete reset
+       float x = ( min_x + max_x ) / 2.0;
+       float y = ( min_y + max_y ) / 2.0;
+       camera.setPose( x, y );
+       float scale_x = w() / (max_x - min_x) * 0.9;
+       float scale_y = h() / (max_y - min_y) * 0.9;
+       camera.setScale( scale_x < scale_y ? scale_x : scale_y );
+}
+
 void StgCanvas::renderFrame()
 {
        //before drawing, order all models based on distance from camera

Modified: code/stage/trunk/libstage/stage.hh
===================================================================
--- code/stage/trunk/libstage/stage.hh  2008-07-03 00:02:27 UTC (rev 6745)
+++ code/stage/trunk/libstage/stage.hh  2008-07-03 00:27:06 UTC (rev 6746)
@@ -1966,6 +1966,7 @@
        void FixViewport(int W,int H);
        void DrawFloor(); //simpler floor compared to grid
        void DrawBlocks();
+       void resetCamera();
        virtual void renderFrame();
        virtual void draw();
        virtual int handle( int event );


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