[osg-users] multiple window pick incorrect
Robert Osfield
robert.osfield at gmail.com
Mon Aug 14 11:54:14 PDT 2017
Hi Caishanli,
I'm not in a position to test code right away so a quick answer and
question as this might help Which version of the OSG are you using? In
OSG-3.4.x there is code that should re-project coordinates into the
appropriate windows, the most reliable way to leverage is to pass in the
event itself to the computeIntersections() rather than just the x,y so the
OSG doesn't have to guess where the event came from.
Robert.
R
On 11 August 2017 at 09:56, Shanli Cai <goesmaster at hotmail.com> wrote:
> 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
>
>
> _______________________________________________
> osg-users mailing list
> osg-users at lists.openscenegraph.org
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openscenegraph.org/pipermail/osg-users-openscenegraph.org/attachments/20170814/2e97475c/attachment.htm>
More information about the osg-users
mailing list