Hi Tom,

My scene graph structure is:

Root-->Terrain

Root-->group1-->model1
                     -->autotransform1
                     -->shapefileNode1

Root-->group2-->model2
                     -->autotransform2
                     -->shapefileNode2

I am trying to pick for model1 and model2 in my graph. 

So I have modified the pick function as follows: (I changed the polytope to 
have width = 2.0 and height = 100.0)

The thing that puzzles me is when I pick the screen from far out (not zooming 
in), and output all the nodes in nodePath, the model1 and model2 are not even 
displayed when I cout the names.

I don't know what I am doing wrong here so thought I would post the pick() code 
as well my scene graph structure.

Thanks in advance.

Sincerely,
Sanat.



Code:
//perform the pick operation
    bool pick(const double x, double y, osgViewer::Viewer* viewer)
    {
      //colors the drawable in yellow
      ColorVisitor highlighter;
      highlighter.setColor(1.0, 1.0, 0.0, 1.0);
      //colors the drawable in red i.e. the normal un-picked color
      ColorVisitor redVisitor;
      highlighter.setColor(1.0, 0.0, 0.0, 1.0);

      if(!viewer->getSceneData())
      //nothing to pick
      {   
        return false;
      }
      double w(2.0);
      double h(100.0);
      osgUtil::PolytopeIntersector* picker = 
                   new 
osgUtil::PolytopeIntersector(osgUtil::Intersector::PROJECTION, x-w, y-h, x+w, 
y+h);
      osgUtil::IntersectionVisitor iv(picker);
      viewer->getCamera()->accept(iv);
      //pipe1Model->accept(iv);

      if(picker->containsIntersections())
      {
        const osg::NodePath& nodePath = picker->getFirstIntersection().nodePath;
        unsigned int idx = nodePath.size();
        std::cout << "-----------------\n";
        std::cout << "size of nodePath is = " << idx << std::endl;
        while(idx--)
        {
          std::cout << "node name: " << nodePath.at(idx)->getName() << 
std::endl;
          //Find the group in the node path
          //This will be the group to attach our visitor to
          osg::Node* modelNode = dynamic_cast<osg::Node*>(nodePath.at(idx));
          if(modelNode == NULL)
          {
            continue; 
          }            
          //if not NULL then a matrix transform was found in the nodePath
          if(_selectedNode != NULL)
          {
            if(_selectedNode->getName() == "Model1" || 
               _selectedNode->getName() == "Model2")          
            {
              //clear the previous selected node's callback to make it stop 
spinning
              //_selectedNode->setUpdateCallback(NULL);
              std::cout << _selectedNode->getName() << std::endl;
              _selectedNode->accept(redVisitor);
            }
          }
          _selectedNode = modelNode;
          if(_selectedNode->getName() == "Model1" || 
             _selectedNode->getName() == "Model2")
          {
            std::cout << _selectedNode->getName() << std::endl;
            _selectedNode->accept(highlighter);
          }
          break;
        }//while(...) 
        if(!_selectedNode.valid())
        {
          osg::notify() << "Pick failed." << std::endl;
        }
      }
      else if(_selectedNode.valid())
      {
        //_selectedNode->setUpdateCallback(NULL); 
        if(_selectedNode->getName() == "Model1" || 
           _selectedNode->getName() == "Model2")
        {
          std::cout << _selectedNode->getName() << std::endl;
          _selectedNode->accept(highlighter);
          _selectedNode = NULL;
        }
      }
      return _selectedNode.valid();
    }



Thank you!

Cheers,
Sanat

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=37328#37328





_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to