Revision: 6595
          http://playerstage.svn.sourceforge.net/playerstage/?rev=6595&view=rev
Author:   rtv
Date:     2008-06-16 16:09:03 -0700 (Mon, 16 Jun 2008)

Log Message:
-----------
fixed picker

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

Modified: code/stage/trunk/libstage/canvas.cc
===================================================================
--- code/stage/trunk/libstage/canvas.cc 2008-06-16 22:59:12 UTC (rev 6594)
+++ code/stage/trunk/libstage/canvas.cc 2008-06-16 23:09:03 UTC (rev 6595)
@@ -75,26 +75,31 @@
 StgModel* StgCanvas::Select( int x, int y )
 {
   // TODO XX
-  return NULL;
+  //return NULL;
 
        // render all models in a unique color
        make_current(); // make sure the GL context is current
-       glClearColor ( 0,0,0,1 );
+       glClearColor ( 1,1,1,1 ); // white
        glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
+
        glDisable(GL_DITHER);
+       glDisable(GL_BLEND); // turns off alpha blending, so we read back
+                                                               // exactly what 
we write to a pixel
 
        // render all top-level, draggable models in a color that is their
-       // id + a 100% alpha value
+       // id 
        for( GList* it=world->children; it; it=it->next )
        {
                StgModel* mod = (StgModel*)it->data;
+               
+               if( mod->GuiMask() & (STG_MOVE_TRANS | STG_MOVE_ROT ))
+                 {
+                        glColor4ubv( (GLubyte*)&mod->id );
 
-               if( mod->GuiMask() & (STG_MOVE_TRANS | STG_MOVE_ROT ))
-               {
-                 // TODO XX
-                 uint32_t col = (uint32_t)mod; //(mod->Id() | 0xFF000000);
-                       glColor4ubv( (GLubyte*)&col );
-                       mod->DrawPicker();
+                        //                      printf( "model %d color %d 
%x\n",
+                        //             mod->id, mod->id, mod->id );
+
+                        mod->DrawPicker();
                }
        }
 
@@ -106,17 +111,15 @@
        uint32_t id;
        glReadPixels( x,viewport[3]-y,1,1,
                        GL_RGBA,GL_UNSIGNED_BYTE,(void*)&id );
+       
+       StgModel* mod = (StgModel*)g_hash_table_lookup( StgModel::modelsbyid, 
(void*)id );
 
-       // strip off the alpha channel byte to retrieve the model id
-       //id &= 0x00FFFFFF;
+       //printf("%p %s %d %x\n", mod, mod ? mod->Token() : "(none)", id, id );
 
-       StgModel* mod = (StgModel*)id;//world->GetModel( id );
-
-       //printf("%p %s %d\n", mod, mod ? mod->Token() : "", id );
-
+       // put things back the way we found them
        glEnable(GL_DITHER);
+       glEnable(GL_BLEND);
        glClearColor ( 0.7, 0.7, 0.8, 1.0);
-       //glClearColor ( 1,1,1,1 );
 
        if( mod ) // we clicked on a root model
        {

Modified: code/stage/trunk/libstage/model.cc
===================================================================
--- code/stage/trunk/libstage/model.cc  2008-06-16 22:59:12 UTC (rev 6594)
+++ code/stage/trunk/libstage/model.cc  2008-06-16 23:09:03 UTC (rev 6595)
@@ -108,7 +108,8 @@
 #include "texture_manager.hh"
 #include <limits.h> 
 
-       // basic model
+
+//static const members
 const bool StgModel::DEFAULT_BLOBRETURN = true;
 const bool StgModel::DEFAULT_BOUNDARY = false;
 const stg_color_t StgModel::DEFAULT_COLOR = (0xFFFF0000); // solid red
@@ -131,18 +132,23 @@
 const bool StgModel::DEFAULT_OUTLINE = true;
 const bool StgModel::DEFAULT_RANGERRETURN = true;
 
-
 // speech bubble colors
 const stg_color_t StgModel::BUBBLE_FILL = 0xFFC8C8FF; // light blue/grey
 const stg_color_t StgModel::BUBBLE_BORDER = 0xFF000000; // black
 const stg_color_t StgModel::BUBBLE_TEXT = 0xFF000000; // black
 
+// static members
+uint32_t StgModel::count = 0;
+
+GHashTable* StgModel::modelsbyid = g_hash_table_new( NULL, NULL );
+
 // constructor
 StgModel::StgModel( StgWorld* world,
                                                  StgModel* parent,
                                                  const stg_model_type_t type )
 : StgAncestor()
-{      
+{
+  assert( modelsbyid );
   assert( world );
   
   PRINT_DEBUG3( "Constructing model world: %s parent: %s type: %d ",
@@ -154,8 +160,12 @@
   this->world = world;  
   this->debug = false;
   this->type = type;
+  this->id = StgModel::count++; // assign a unique ID and increment
+                                                                               
  // the global model counter
   
-  // Adding this model to its ancestor also gives this model a
+  g_hash_table_insert( modelsbyid, (void*)this->id, this );
+
+ // Adding this model to its ancestor also gives this model a
   // sensible default name
 
   StgAncestor* anc =  parent ? (StgAncestor*)parent : (StgAncestor*)world;

Modified: code/stage/trunk/libstage/stage.hh
===================================================================
--- code/stage/trunk/libstage/stage.hh  2008-06-16 22:59:12 UTC (rev 6594)
+++ code/stage/trunk/libstage/stage.hh  2008-06-16 23:09:03 UTC (rev 6595)
@@ -1170,7 +1170,16 @@
        friend class StgWorld;
        friend class StgWorldGui;
        friend class StgCanvas;
+  
+private:
+  /** the number of models instatiated - used to assign unique IDs */
+  static uint32_t count;
+  static GHashTable*  modelsbyid;
 
+public:
+  /** unique process-wide identifier for this model */
+  uint32_t id;
+
 protected:
 
   // basic model


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