Re: [osg-users] Trouble Understanding osgPick (pick example QSG)

2011-03-04 Thread Sanat Talmaki
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_castosg::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
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] Trouble Understanding osgPick (pick example QSG)

2011-03-04 Thread Tom Pearce
Hi Sanat,


Code:
const osg::NodePath nodePath = picker-getFirstIntersection().nodePath;


is only giving you the first intersection, which may not be either of your 
models (it could be terrain, for example).  I'm guessing you need to search the 
entire set rather than just trying the first intersection.


Code:

Intersections osgUtil::PolytopeIntersector::getIntersections   ()
typedef std::setIntersection osgUtil::PolytopeIntersector::Intersections





Cheers,
Tom

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





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] Trouble Understanding osgPick (pick example QSG)

2011-03-04 Thread Sanat Talmaki
Thanks Tom. I will try that out.

Cheers,
Sanat.

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





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


[osg-users] Trouble Understanding osgPick (pick example QSG)

2011-03-03 Thread Sanat Talmaki
Hi,

I have read through the example in the QSG (quick start guide) as well as 
example programs for the Picking behavior.

I know how the eventAdapter, handle(), etc works. My problem is:

In my ctor for picking class I set the two nodes for which I want to check if 
any of them have been picked. 

Given that I have the nodePath from the intersector, how can I check if the 
node I am interested in is in the nodePath ? (I tried using getName and setName 
but that didn't help)

Any help in this matter would be great! (If my explanation has not been clear, 
I would be happy to re-post)

Thanks in advance.

Sincerely,
Sanat

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





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] Trouble Understanding osgPick (pick example QSG)

2011-03-03 Thread Tom Pearce
osg::NodePath is:
typedef std::vector Node*  osg::NodePath

Since you have two Node*s that you're looking for, you can iterate through the 
NodePath just like any other vector and compare your pointer to the pointers in 
the vector.

You could also apply your intersection visitor to the nodes you're interested 
in rather than the scene root and just check if it intersects with anything in 
that case.

I haven't worked with intersectors in a while though so I may be wrong.

Cheers,
Tom

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





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org