[osg-users] multiple window pick incorrect

Shanli Cai goesmaster at hotmail.com
Fri Aug 11 01:56:20 PDT 2017


Hi,All

I create 2x2 windows, like a powerwall, add four slave cameras to viewer, and load cow.osg, the cow show in the center of four windows. And I add a GUIEventHandler to the viewer, use osgUtil::LineSegmentIntersector::Intersections to find mouse intersected node. When mouse move on to the cow, change the cow to red.

Code:

   void Pick(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa)
    {
        float x = ea.getX(), y = ea.getY();
        osgViewer::Viewer* view = dynamic_cast<osgViewer::Viewer*>(aa.asView());
        osgUtil::LineSegmentIntersector::Intersections intersections;
        if (view->computeIntersections(x, y, intersections))
        {
            for (osgUtil::LineSegmentIntersector::Intersections::iterator it = intersections.begin();
                it != intersections.end(); it++)
            {
                const osg::NodePath& np = it->nodePath;
                for (int i = np.size() - 1; i >= 0; i--)
                {
                    osg::Node* node = dynamic_cast<osg::Node*>(np[i]);
                    if (node->getName() == "cow.osg")
                    {
                        osg::StateSet* state = node->getOrCreateStateSet();
                        state->setMode(GL_BLEND, osg::StateAttribute::ON);
                        osg::Material* mtrl = dynamic_cast<osg::Material*>(state->getAttribute(osg::StateAttribute::MATERIAL));
                        if (!mtrl) mtrl = new osg::Material;
                        mtrl->setDiffuse(osg::Material::FRONT_AND_BACK, osg::Vec4(1.0, 0.0, 0.0, 0.8));
                        mtrl->setAmbient(osg::Material::FRONT_AND_BACK, osg::Vec4(1.0, 0.0, 0.0, 0.8));
                        mtrl->setTransparency(osg::Material::FRONT_AND_BACK, 0.2);
                        state->setAttributeAndModes(mtrl, osg::StateAttribute::OVERRIDE | osg::StateAttribute::ON);
                        state->setRenderingHint(osg::StateSet::TRANSPARENT_BIN);

                        _lastSelect = node;

                        return;
                    }
                }
            }
        }
    }




The problem is that when I move the mouse on the cow, the cow not change to red(I tested with one window, it's ok), but when I move the mouse to a window's center(center is blank, no cow's hand or leg), the cow change to red, all the four windows are the same.

I set viewer's master camera's viewport to total width and height, and set viewer's event queue's mouse input range to total width and height, all is not work.

The question is, am I need to set viewer's master camera's viewport? viewer's event queue's mouse input range? If need, how to set? 

Code:

viewer->getCamera()->setViewport(0, 0, w, h);
viewer->getEventQueue()->setMouseInputRange(0, 0, w, h);




And for the test file, every window tile is 960x540, the total 2x2 windows resolution is 1920x1080, but when I create the powerwall with every tile 1920x1080, and total is 3840x2160, so I can see more details of the scene, benefit from high resolution, how to do? Set master camera's projection matrix? Or how?


The full souce code is in file

Thank you!

Cheers,
caishanli

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




Attachments: 
http://forum.openscenegraph.org//files/1_106.jpg
http://forum.openscenegraph.org//files/testpowerwall_166.cpp




More information about the osg-users mailing list