Hello everyone,

I'm new here so hi all and thanks in advance to everyone willing to take a look 
on my issue. :)

I'm currently working on object selection in my scene, so I made something up 
based on the picking example from osgpick.cpp .


Code:

if (myview->computeIntersections(x, y, intersections))
{
    // *** for each intersection we found ***
    for(osgUtil::LineSegmentIntersector::Intersections::iterator hitr = 
intersections.begin();
    hitr != intersections.end();
    ++hitr)
    {
        // choose foremost selection in FoV
        if(hitr == intersections.begin()) {

            if (!hitr->nodePath.empty())
            {
                osg::NodePath nodePath = hitr->nodePath;
                node = (nodePath.size() >= 1) ? nodePath[nodePath.size()-1] : 0;

                pickedObjects.push_back(node);

                return true;
            }
        }
    }
}



If this function returns true, a callback on another class responsible for for 
further processing the object selection (adding it to list of selected objects, 
changing display mode to wireframe etc) is triggered.

That other class traverses the objects in my scene and checks whether the 
picked node is part of the currently scanned object:


Code:
// scan for objects to potentially add
for(nodeit = selectednodes.begin(); nodeit != selectednodes.end(); ++nodeit)
{
    // and try to verify their existance as drawobject
    for(drawit = drawObjects.begin(); drawit != drawObjects.end(); ++drawit)
    {
        /* In case we find the corresponding drawobject, we have to
        * add them to the list of selected objects. */
        if((*drawit)->getObject()->containsNode((*nodeit))) {
            (*drawit)->setSelected(true);
            selectedobjects.push_back((*drawit));



That piece of code works well, as long as the selected object is the only 
instance of itself. As soon as I have the picked object instanced multiple 
times in my scene, trying to pick any of these will result in always the same 
object being selected (the first match in the list, obviously). 

So, when performing the pick itself (code snippet #1) I need to gather 
additional info like the position of the selected object in order to be able to 
make the correct match when trying to mark the object as selected. However, 
when I have the same mesh with, say, 30 instances and therefore 31 parental 
nodes, how would I find out which one is the node corresponding to the instance 
I click on in the scene?

Best regards,

-Alex

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





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

Reply via email to