Revision: 7184
          http://playerstage.svn.sourceforge.net/playerstage/?rev=7184&view=rev
Author:   rtv
Date:     2008-12-02 01:45:44 +0000 (Tue, 02 Dec 2008)

Log Message:
-----------
geometry & graphics fixes. added normalization of blocks to fit inside model 
geometry

Modified Paths:
--------------
    code/stage/trunk/libstage/block.cc
    code/stage/trunk/libstage/blockgroup.cc
    code/stage/trunk/libstage/canvas.cc
    code/stage/trunk/libstage/gl.cc
    code/stage/trunk/libstage/model.cc
    code/stage/trunk/libstage/model_position.cc
    code/stage/trunk/libstage/stage.hh
    code/stage/trunk/libstage/world.cc
    code/stage/trunk/worlds/simple.world
    code/stage/trunk/worlds/walle.inc

Modified: code/stage/trunk/libstage/block.cc
===================================================================
--- code/stage/trunk/libstage/block.cc  2008-12-01 21:30:59 UTC (rev 7183)
+++ code/stage/trunk/libstage/block.cc  2008-12-02 01:45:44 UTC (rev 7184)
@@ -186,9 +186,11 @@
   g_ptr_array_set_size( candidate_cells, 0 );
   
   // compute the global location of the first point
-  stg_pose_t local( pts[0].x * scale.x, 
-                                                 pts[0].y * scale.y, 
-                                                 0, 0 );               
+  stg_pose_t local( (pts[0].x - mod->blockgroup.offset.x) * scale.x ,
+                                                 (pts[0].y - 
mod->blockgroup.offset.y) * scale.y, 
+                                                 -mod->blockgroup.offset.z, 
+                                                 0 );
+
   stg_pose_t first_gpose, last_gpose;
   first_gpose = last_gpose = pose_sum( gpose, local );
   
@@ -199,9 +201,10 @@
   // now loop from the the second to the last
   for( int p=1; p<pt_count; p++ )
         {
-               stg_pose_t local( pts[p].x * scale.x, 
-                                                               pts[p].y * 
scale.y, 
-                                                               0, 0 );         
+               stg_pose_t local( (pts[p].x - mod->blockgroup.offset.x) * 
scale.x ,
+                                                               (pts[p].y - 
mod->blockgroup.offset.y) * scale.y, 
+                                                               
-mod->blockgroup.offset.z, 
+                                                               0 );            
                
                stg_pose_t gpose2 = pose_sum( gpose, local );
                
@@ -325,6 +328,8 @@
                color = stg_lookup_color( colorstr );
                inherit_color = false;
         }
+  else
+        inherit_color = true;
 }
 
        

Modified: code/stage/trunk/libstage/blockgroup.cc
===================================================================
--- code/stage/trunk/libstage/blockgroup.cc     2008-12-01 21:30:59 UTC (rev 
7183)
+++ code/stage/trunk/libstage/blockgroup.cc     2008-12-02 01:45:44 UTC (rev 
7184)
@@ -91,9 +91,17 @@
                size.z = MAX( block->local_z.max, size.z );
         }
   
-  // store these bounds for scaling purposes
+  // store these bounds for normalization purposes
   size.x = maxx-minx;
   size.y = maxy-miny;
+  
+  offset.x = minx + size.x/2.0;
+  offset.y = miny + size.y/2.0;
+  offset.z = 0; // todo?
+
+  // normalize blocks
+  //  for( GList* it = blocks; itl it=it->next )
+  //((StgBlock*)it->data)->Normalize( size.x, size.y, size.z, offset.x
 }
 
 
@@ -107,14 +115,36 @@
   LISTMETHOD( blocks, StgBlock*, UnMap );
 }
 
-void BlockGroup::DrawSolid()
+void BlockGroup::DrawSolid( const stg_geom_t & geom )
 {
+  glPushMatrix();
+
+  gl_pose_shift( geom.pose );
+
+  glScalef( geom.size.x / size.x,
+                               geom.size.y / size.y,                           
+                               geom.size.z / size.z );
+  
+  glTranslatef( -offset.x, -offset.y, -offset.z );
+
   LISTMETHOD( blocks, StgBlock*, DrawSolid );
+
+  glPopMatrix();
 }
 
-void BlockGroup::DrawFootPrint()
+void BlockGroup::DrawFootPrint( const stg_geom_t & geom )
 {
+  glPushMatrix();
+  
+  glScalef( geom.size.x / size.x,
+                               geom.size.y / size.y,                           
+                               geom.size.z / size.z );
+  
+  glTranslatef( -offset.x, -offset.y, -offset.z );
+
   LISTMETHOD( blocks, StgBlock*, DrawFootPrint);
+
+  glPopMatrix();
 }
 
 void BlockGroup::BuildDisplayList( StgModel* mod )
@@ -126,11 +156,17 @@
   
   glNewList( displaylist, GL_COMPILE );        
     
+
   stg_geom_t geom = mod->GetGeom();
+
+  gl_pose_shift( geom.pose );
+
   glScalef( geom.size.x / size.x,
                                geom.size.y / size.y,                           
                                geom.size.z / size.z );
   
+  glTranslatef( -offset.x, -offset.y, -offset.z );
+  
   glPolygonMode( GL_FRONT_AND_BACK, GL_FILL );
   glEnable(GL_POLYGON_OFFSET_FILL);
   glPolygonOffset(1.0, 1.0);

Modified: code/stage/trunk/libstage/canvas.cc
===================================================================
--- code/stage/trunk/libstage/canvas.cc 2008-12-01 21:30:59 UTC (rev 7183)
+++ code/stage/trunk/libstage/canvas.cc 2008-12-02 01:45:44 UTC (rev 7184)
@@ -176,6 +176,7 @@
   current_camera->SetProjection();
   current_camera->Draw();
 
+  glPolygonMode( GL_FRONT_AND_BACK, GL_FILL );
   glDisable(GL_DITHER);
   glDisable(GL_BLEND); // turns off alpha blending, so we read back
   // exactly what we write to a pixel
@@ -502,6 +503,9 @@
                                  Fl::remove_timeout( 
(Fl_Timeout_Handler)StgCanvas::TimerCallback );
                                }
 
+                        redraw(); // in case something happened that will 
never be
+                                                 // drawn 'cos we cancelled 
the timeout
+
                         break;
                  case ' ': // space bar
                  

Modified: code/stage/trunk/libstage/gl.cc
===================================================================
--- code/stage/trunk/libstage/gl.cc     2008-12-01 21:30:59 UTC (rev 7183)
+++ code/stage/trunk/libstage/gl.cc     2008-12-02 01:45:44 UTC (rev 7184)
@@ -24,11 +24,8 @@
 // TODO - this could be faster, but we don't draw a lot of text
 void Stg::gl_draw_string( float x, float y, float z, const char *str ) 
 {  
-       //const char *c;
        glRasterPos3f( x, y, z );
        gl_draw(str);
-//     for (c=str; *c != '\0'; c++) 
-//             glutBitmapCharacter( GLUT_BITMAP_HELVETICA_12, *c);
 }
 
 void Stg::gl_speech_bubble( float x, float y, float z, const char* str )

Modified: code/stage/trunk/libstage/model.cc
===================================================================
--- code/stage/trunk/libstage/model.cc  2008-12-01 21:30:59 UTC (rev 7183)
+++ code/stage/trunk/libstage/model.cc  2008-12-02 01:45:44 UTC (rev 7184)
@@ -764,12 +764,12 @@
       stg_color_unpack( checkpoint->color, &r, &g, &b, &a );
       PushColor( r, g, b, 0.1 );
 
-               blockgroup.DrawFootPrint();
+               blockgroup.DrawFootPrint( geom );
 
       glPolygonMode( GL_FRONT_AND_BACK, GL_LINE );
       PushColor( r/2, g/2, b/2, 0.1 );
 
-               blockgroup.DrawFootPrint();
+               blockgroup.DrawFootPrint( geom );
 
       PopColor();
       PopColor();
@@ -880,7 +880,6 @@
 
 void StgModel::DrawBlocks( )
 { 
-  gl_pose_shift( geom.pose );
   blockgroup.CallDisplayList( this );
 }
 
@@ -1176,7 +1175,7 @@
   PushLocalCoords();
 
   // draw the boxes
-  blockgroup.DrawSolid();
+  blockgroup.DrawSolid( geom );
 
   // recursively draw the tree below this model 
   LISTMETHOD( this->children, StgModel*, DrawPicker );

Modified: code/stage/trunk/libstage/model_position.cc
===================================================================
--- code/stage/trunk/libstage/model_position.cc 2008-12-01 21:30:59 UTC (rev 
7183)
+++ code/stage/trunk/libstage/model_position.cc 2008-12-02 01:45:44 UTC (rev 
7184)
@@ -568,6 +568,27 @@
   gl_pose_shift( est_origin );
   PushColor( 1,0,0,1 ); // origin in red
   gl_draw_origin( 0.5 );
+
+  glEnable (GL_LINE_STIPPLE);
+  glLineStipple (3, 0xAAAA);
+
+  PushColor( 1,0,0,0.5 ); 
+  glBegin( GL_LINE_STRIP );
+  glVertex2f( 0,0 );
+  glVertex2f( est_pose.x, 0 );
+  glVertex2f( est_pose.x, est_pose.y );  
+  glEnd();
+  
+  glDisable(GL_LINE_STIPPLE);
+
+  char label[64];
+  snprintf( label, 64, "x:%.3f", est_pose.x );
+  gl_draw_string( est_pose.x / 2.0, -0.5, 0, label );
+
+  snprintf( label, 64, "y:%.3f", est_pose.y );
+  gl_draw_string( est_pose.x + 0.5 , est_pose.y / 2.0, 0, (const char*)label );
+
+
   PopColor();
 
   gl_pose_shift( est_pose );
@@ -585,7 +606,7 @@
   PushColor( r, g, b, 0.5 );
   
   glPolygonMode( GL_FRONT_AND_BACK, GL_LINE );
-  blockgroup.DrawFootPrint();
+  blockgroup.DrawFootPrint( geom );
   PopColor();
 
   glPopMatrix(); 

Modified: code/stage/trunk/libstage/stage.hh
===================================================================
--- code/stage/trunk/libstage/stage.hh  2008-12-01 21:30:59 UTC (rev 7183)
+++ code/stage/trunk/libstage/stage.hh  2008-12-02 01:45:44 UTC (rev 7184)
@@ -1182,7 +1182,8 @@
         GList* blocks;
         uint32_t count;
         stg_size_t size;
-  
+        stg_point3_t offset;
+
         BlockGroup();
         ~BlockGroup();
 
@@ -1198,11 +1199,14 @@
         StgModel* TestCollision();
     void SwitchToTestedCells();
         
-               void Map();
+        void Map();
         void UnMap();
-  
-        void DrawSolid(); // draw the block in OpenGL as a solid single color
-        void DrawFootPrint(); // draw the projection of the block onto the z=0 
plane
+        
+        void DrawSolid( const stg_geom_t &geom); // draw the block in OpenGL 
as a solid single color
+        void DrawFootPrint( const stg_geom_t &geom); // draw the
+                                                                               
                                                 // projection of the
+                                                                               
                                                 // block onto the z=0
+                                                                               
                                                 // plane
 
         void LoadBitmap( StgModel* mod, const char* bitmapfile, Worldfile *wf 
);
         void LoadBlock( StgModel* mod, Worldfile* wf, int entity );

Modified: code/stage/trunk/libstage/world.cc
===================================================================
--- code/stage/trunk/libstage/world.cc  2008-12-01 21:30:59 UTC (rev 7183)
+++ code/stage/trunk/libstage/world.cc  2008-12-02 01:45:44 UTC (rev 7184)
@@ -46,7 +46,6 @@
 #include <limits.h>
 #include <libgen.h> // for dirname(3)
 #include "stage_internal.hh"
-//#include "region.hh"
 #include "file_manager.hh"
 
 // static data members

Modified: code/stage/trunk/worlds/simple.world
===================================================================
--- code/stage/trunk/worlds/simple.world        2008-12-01 21:30:59 UTC (rev 
7183)
+++ code/stage/trunk/worlds/simple.world        2008-12-02 01:45:44 UTC (rev 
7184)
@@ -8,9 +8,9 @@
 include "walle.inc"
 
 interval_sim 100  # simulation timestep in milliseconds
-interval_real 0  # real-time interval between simulation updates in 
milliseconds 
+interval_real 10  # real-time interval between simulation updates in 
milliseconds 
 
-paused 1
+paused 0
 
 resolution 0.02
 
@@ -40,6 +40,8 @@
   # can refer to the robot by this name
   name "r0"
 
+  localization "odom"
+
   pose [ 0.892 0.800 0 56.500 ] 
   sicklaser( samples 180 ) 
 

Modified: code/stage/trunk/worlds/walle.inc
===================================================================
--- code/stage/trunk/worlds/walle.inc   2008-12-01 21:30:59 UTC (rev 7183)
+++ code/stage/trunk/worlds/walle.inc   2008-12-02 01:45:44 UTC (rev 7184)
@@ -7,7 +7,7 @@
 
 define walle position 
 (
-  color "yellow"
+  color "gray50"
   drive "diff"                 # Differential steering model.
 
   obstacle_return 1            # Can hit things.
@@ -18,8 +18,8 @@
 
   localization "gps"             
 
-  size [0.5 0.5 0.5]
-  origin [-0.25 -0.25 0 0 ]
+  size [0.35 0.5 0.5]
+  #origin [-0.25 -0.25 0 0 ]
 
   laser( pose [0.15 0 -0.27 0 ] size [0.01 0.01 0.01] alwayson 1 )
 
@@ -32,7 +32,7 @@
     point[2] [ 0.9 0.75 ] 
     point[3] [ 0.1 0.75 ] 
     z [ 0.2 0.6 ]
-    color "yellow"
+        #color "yellow"
   )
 
   # body top
@@ -44,7 +44,6 @@
     point[2] [ 0.9 0.75 ] 
     point[3] [ 0.1 0.75 ] 
     z [ 0.6 0.7 ]
-    color "gray20"
   )
 
   # right wheel 
@@ -56,7 +55,6 @@
     point[2] [ 0.0 0.25 ] 
     point[3] [ 0 0.0 ] 
     z [ 0.0 0.4 ]
-    color "gray23"
   )
 
   # right wheel 
@@ -68,7 +66,6 @@
     point[2] [ 0 1 ] 
     point[3] [ 0 0.75 ] 
     z [ 0.0 0.4 ]
-    color "gray23"
   )
 
   # right eye front
@@ -80,7 +77,6 @@
         point[2] [0.6 0.49]
         point[3] [0.6 0.30]
         z [0.8 0.95]
-    color "gray23"
   )
 
   # left eye front
@@ -92,7 +88,6 @@
         point[2] [0.6 0.7]
         point[3] [0.6 0.51]
         z [0.8 0.95]
-    color "gray23"
   )
 
   # right eye rear
@@ -104,7 +99,6 @@
         point[2] [0.25 0.49]
         point[3] [0.25 0.34]
         z [0.82 0.93]
-    color "gray28"
   )
 
   # neck
@@ -115,7 +109,6 @@
         point[1] [0.4 0.55]
         point[0] [0.4 0.45]
         z [0.7 0.9]
-    color "gray28"
   )   
 
   # right eye rear
@@ -127,7 +120,6 @@
         point[2] [0.25 0.66]
         point[3] [0.25 0.51]
         z [0.82 0.93]
-    color "gray28"
   )
 
   # right arm
@@ -139,7 +131,6 @@
         point[2] [0.35 0.25]
         point[3] [0.35 0.18]
         z [0.55 0.65]
-    color "gray28"
   )
 
   # left arm
@@ -151,7 +142,6 @@
         point[2] [1.1 0.75]
         point[3] [1.1 0.82]
         z [0.55 0.65]
-    color "gray28"
   )
 
   # left hand right finger
@@ -163,7 +153,6 @@
         point[2] [1.2 0.70]
         point[3] [1.2 0.78]
         z [0.5 0.65]
-    color "gray28"
   )
 
   # left hand left finger
@@ -175,7 +164,6 @@
         point[2] [1.2 0.79]
         point[3] [1.2 0.87]
         z [0.5 0.65]
-    color "gray28"
   )
 
   # right hand right finger
@@ -187,7 +175,6 @@
         point[2] [1.2 0.13]
         point[3] [1.2 0.21]
         z [0.5 0.65]
-    color "gray28"
   )
 
   # right hand left finger
@@ -199,7 +186,6 @@
         point[2] [1.2 0.22]
         point[3] [1.2 0.30]
         z [0.5 0.65]
-    color "gray28"
   )
 
 )


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

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Playerstage-commit mailing list
Playerstage-commit@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/playerstage-commit

Reply via email to