Revision: 6577
          http://playerstage.svn.sourceforge.net/playerstage/?rev=6577&view=rev
Author:   rtv
Date:     2008-06-13 22:37:08 -0700 (Fri, 13 Jun 2008)

Log Message:
-----------
cleaning and expanding API, adding tests

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

Modified: code/stage/trunk/libstage/canvas.cc
===================================================================
--- code/stage/trunk/libstage/canvas.cc 2008-06-14 03:06:19 UTC (rev 6576)
+++ code/stage/trunk/libstage/canvas.cc 2008-06-14 05:37:08 UTC (rev 6577)
@@ -445,11 +445,11 @@
                                StgModel* mod = ((StgModel*)it->data);
 
                                if( mod->displaylist == 0 )
-                               {
-                                       mod->displaylist = glGenLists(1);
-                                       mod->BuildDisplayList( showflags ); // 
ready to be rendered
-                               }
+                                 mod->displaylist = glGenLists(1);
 
+                               if( mod->body_dirty )
+                                 mod->BuildDisplayList( showflags ); // ready 
to be rendered
+                       
                                // move into this model's local coordinate frame
                                glPushMatrix();
                                gl_pose_shift( &mod->pose );
@@ -534,7 +534,7 @@
 //     if( loaded_texture == true && use_perspective_camera == true )
 //             return;
 
-       if (!valid()) 
+       if (!valid() || world->dirty ) 
        { 
                valid(1);
                FixViewport(w(), h());

Modified: code/stage/trunk/libstage/model.cc
===================================================================
--- code/stage/trunk/libstage/model.cc  2008-06-14 03:06:19 UTC (rev 6576)
+++ code/stage/trunk/libstage/model.cc  2008-06-14 05:37:08 UTC (rev 6577)
@@ -328,7 +328,7 @@
                                        col, inherit_color ));
 
        // force recreation of display lists before drawing
-       body_dirty = true;
+       NeedRedraw();
 }
 
 
@@ -336,7 +336,7 @@
 {
        stg_block_list_destroy( blocks );
        blocks = NULL;
-       body_dirty = true;
+       NeedRedraw();
 }
 
 void StgModel::AddBlockRect( double x, double y, 
@@ -1191,7 +1191,8 @@
 
 void StgModel::NeedRedraw( void )
 {
-       this->world->dirty = true;
+  this->body_dirty = true;
+  //this->world->dirty = true;
 }
 
 void StgModel::GPoseDirtyTree( void )
@@ -1259,7 +1260,7 @@
 
        StgBlock::ScaleList( blocks, &geom.size );
 
-       body_dirty = true;
+       NeedRedraw();
 
        Map();
 
@@ -1269,7 +1270,7 @@
 void StgModel::SetColor( stg_color_t col )
 {
        this->color = col;
-       body_dirty = true;
+       NeedRedraw();
        CallCallbacks( &this->color );
 }
 
@@ -1413,13 +1414,22 @@
 }      
 
 
-// Check to see if the given change in pose will yield a collision
-// with obstacles.  Returns a pointer to the first entity we are in
-// collision with, and stores the location of the hit in hitx,hity (if
-// non-null) Returns NULL if no collision. 
+void StgModel::PlaceInFreeSpace( stg_meters_t xmin, stg_meters_t xmax, 
+                                                                               
        stg_meters_t ymin, stg_meters_t ymax )
+{
+  while( TestCollision( NULL, NULL ) )
+        SetPose( random_pose( xmin,xmax, ymin, ymax ));                
+}
 
-StgModel* StgModel::TestCollision( stg_pose_t* posedelta, 
-               double* hitx, double* hity ) 
+
+StgModel* StgModel::TestCollision( stg_meters_t* hitx, stg_meters_t* hity )
+{
+  return TestCollision( new_pose(0,0,0,0), hitx, hity );
+}
+
+StgModel* StgModel::TestCollision( stg_pose_t posedelta, 
+                                                                               
          stg_meters_t* hitx,
+                                                                               
          stg_meters_t* hity ) 
 { 
        /*  stg_model_t* child_hit = NULL; */
 
@@ -1480,7 +1490,7 @@
 
                        // raytrace in local coordinates
                        stg_raytrace_sample_t sample;
-                       Raytrace( pose_sum( *posedelta, edgepose), 
+                       Raytrace( pose_sum( posedelta, edgepose), 
                                        range,
                                        
(stg_block_match_func_t)collision_match, 
                                        NULL, 
@@ -1529,7 +1539,7 @@
        p.a += velocity.a * interval;
 
        // test to see if this pose change would cause us to crash
-       StgModel* hitthing = this->TestCollision( &p, NULL, NULL );
+       StgModel* hitthing = this->TestCollision( p, NULL, NULL );
 
        //double hitx=0, hity=0;
        //StgModel* hitthing = this->TestCollision( &p, &hitx, &hity );

Modified: code/stage/trunk/libstage/stage.cc
===================================================================
--- code/stage/trunk/libstage/stage.cc  2008-06-14 03:06:19 UTC (rev 6576)
+++ code/stage/trunk/libstage/stage.cc  2008-06-14 05:37:08 UTC (rev 6577)
@@ -316,6 +316,16 @@
 };
 
 
+stg_pose_t Stg::random_pose( stg_meters_t xmin, stg_meters_t xmax, 
+                                                                         
stg_meters_t ymin, stg_meters_t ymax )
+{
+  return new_pose( xmin + drand48() * (xmax-xmin),
+                                                ymin + drand48() * (ymax-ymin),
+                                                0, 
+                                                normalize( drand48() * (2.0 * 
M_PI) ));
+}
+
+
 // sets [result] to the pose of [p2] in [p1]'s coordinate system
 void Stg::stg_pose_sum( stg_pose_t* result, stg_pose_t* p1, stg_pose_t* p2 )
 {

Modified: code/stage/trunk/libstage/stage.hh
===================================================================
--- code/stage/trunk/libstage/stage.hh  2008-06-14 03:06:19 UTC (rev 6576)
+++ code/stage/trunk/libstage/stage.hh  2008-06-14 05:37:08 UTC (rev 6577)
@@ -376,6 +376,11 @@
                parameters */
   stg_pose_t new_pose( stg_meters_t x, stg_meters_t y, stg_meters_t z, 
stg_radians_t a );
 
+  /** return a random pose within the bounding rectangle, with z=0 and
+               angle random */
+  stg_pose_t random_pose( stg_meters_t xmin, stg_meters_t xmax, 
+                                                                 stg_meters_t 
ymin, stg_meters_t ymax );
+  
        const uint32_t STG_MOVE_TRANS = (1 << 0);
        const uint32_t STG_MOVE_ROT   = (1 << 1);
        const uint32_t STG_MOVE_SCALE = (1 << 2);
@@ -1205,11 +1210,26 @@
        // worldfile section identifier
 
        StgWorld* world; // pointer to the world in which this model exists
-
-       StgModel* TestCollision( stg_pose_t* pose, 
-                       double* hitx, double* hity );
-
-
+  
+  /** Check to see if the given change in pose will yield a collision
+               with obstacles.  Returns a pointer to the first entity we are in
+               collision with, and stores the location of the hit in hitx,hity 
(if
+               non-null) Returns NULL if no collision. */
+  StgModel* TestCollision( stg_pose_t pose, 
+                                                                       
stg_meters_t* hitx,
+                                                                       
stg_meters_t* hity );
+  
+  /** Check to see if the current pose is in  a collision
+               with obstacles.  Returns a pointer to the first entity we are in
+               collision with, and stores the location of the hit in hitx,hity 
(if
+               non-null) Returns NULL if no collision. */
+  StgModel* TestCollision( stg_meters_t* hitx,
+                                                                       
stg_meters_t* hity );
+  
+public:  void PlaceInFreeSpace( stg_meters_t xmin, stg_meters_t xmax, 
+                                                                               
  stg_meters_t ymin, stg_meters_t ymax );
+  
+protected:
        void Map();
        void UnMap();
 

Modified: code/stage/trunk/libstage/test.cc
===================================================================
--- code/stage/trunk/libstage/test.cc   2008-06-14 03:06:19 UTC (rev 6576)
+++ code/stage/trunk/libstage/test.cc   2008-06-14 05:37:08 UTC (rev 6577)
@@ -44,7 +44,7 @@
   
   world.Start();
     
-  for( stg_meters_t x=0; x<5; x+=0.01 )         
+  for( stg_meters_t x=0; x<5; x+=0.1 )  
         {
                pose = new_pose( x, 0, 0, 0 );
                mod.SetPose( pose );            
@@ -52,7 +52,7 @@
                interact( &world );
         }
 
-  for( stg_meters_t y=0; y<5; y+=0.01 )         
+  for( stg_meters_t y=0; y<5; y+=0.1 )  
         {
                pose = new_pose( 0, y, 0, 0 );
                mod.SetPose( pose );            
@@ -60,7 +60,7 @@
                interact( &world );
         }
 
-  for( stg_meters_t z=0; z<5; z+=0.01 )         
+  for( stg_meters_t z=0; z<5; z+=0.1 )  
         {
                pose = new_pose( 0, 0, z, 0 );
                mod.SetPose( pose );            
@@ -68,7 +68,7 @@
                interact( &world );
         }
   
-  for( stg_radians_t a=0; a<dtor(360); a+=dtor(1) )     
+  for( stg_radians_t a=0; a<dtor(360); a+=dtor(2) )     
         {
                pose = new_pose( 0, 0, 0, a );
                mod.SetPose( pose );              
@@ -77,7 +77,7 @@
                interact( &world );
         }
 
-  for( stg_radians_t a=0; a<dtor(360); a+=dtor(1) )     
+  for( stg_radians_t a=0; a<dtor(360); a+=dtor(2) )     
         {
                pose = new_pose( cos(a), sin(a), 0, 0 );
                mod.SetPose( pose );            
@@ -85,20 +85,69 @@
                interact( &world );
         }
 
+  mod.SetPose( new_pose( 0,0,0,0 ));           
+
   stg_geom_t geom;
   bzero( &geom, sizeof(geom) );
 
   for( stg_meters_t x=0.01; x<5; x+=0.1 )       
-        for( stg_meters_t y=0.01; y<5; y+=0.1 )         
-               //for( stg_meters_t z=0.01; z<5; z+=0.01 )       
-                 {
-                        geom.size.x = x;
-                        geom.size.y = y;
-                        geom.size.z = 1.0;
-                        
-                        mod.SetGeom( geom );
-                        interact( &world );
-                 }
+        {
+               geom.size.x = x;
+               geom.size.y = 1.0;
+               geom.size.z = 1.0;
+               
+               mod.SetGeom( geom );
+               interact( &world );
+        }
   
+  for( stg_meters_t y=0.01; y<5; y+=0.1 )       
+        {
+               geom.size.x = 5;
+               geom.size.y = y;
+               geom.size.z = 1.0;
+               
+               mod.SetGeom( geom );
+               interact( &world );
+        }
+
+  for( stg_meters_t z=0.01; z<5; z+=0.1 )       
+        {
+               geom.size.x = 1;
+               geom.size.y = 1;
+               geom.size.z = z;
+               
+               mod.SetGeom( geom );
+               interact( &world );
+        }
+  
+  geom.size.x = 0.5;
+  geom.size.y = 0.5;
+  geom.size.z = 0.5;
+  
+  mod.SetGeom( geom );
+  
+
+#define POP 100
+  
+  StgModel* m[POP]; 
+  for( int i=0; i<POP; i++ )
+        {
+               m[i] = new StgModel( &world, NULL, 0, "model" );
+               m[i]->SetGeom( geom );
+               //m[i]->SetPose( random_pose( -10,10, -10,10 ) );               
+               m[i]->PlaceInFreeSpace( -10, 10, -10, 10 );
+               m[i]->SetColor( lrand48() | 0xFF000000 );
+               interact( &world );
+        }
+
+  
+//   for( int i=0; i<POP; i++ )
+//      {
+//             m[i]->PlaceInFreeSpace( -10, 10, -10, 10 );
+//             m[i]->SetColor( 0xFF00FF00 );
+//             interact( &world );
+//      }
+
+
   StgWorldGui::Run();
 }

Modified: code/stage/trunk/libstage/world.cc
===================================================================
--- code/stage/trunk/libstage/world.cc  2008-06-14 03:06:19 UTC (rev 6576)
+++ code/stage/trunk/libstage/world.cc  2008-06-14 05:37:08 UTC (rev 6577)
@@ -77,6 +77,8 @@
 {
        SuperRegion* sr = new SuperRegion( x, y );
        g_hash_table_insert( superregions, &sr->origin, sr );
+
+       dirty = true; // force redraw
        return sr;
 }
 


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