OpenSceneGraph Forum Forum Index OpenSceneGraph Forum
Official forum which mirrors the existent OSG mailing lists. Messages posted here are forwarded to the mailing list and vice versa.
 
   FAQFAQ    SearchSearch    MemberlistMemberlist    RulesRules    UsergroupsUsergroups    RegisterRegister 
 Mail2Forum SettingsMail2Forum Settings  ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
   AlbumAlbum  OpenSceneGraph IRC ChatOpenSceneGraph IRC Chat   SmartFeedSmartFeed 

multiple window pick incorrect


 
Post new topic   Reply to topic    OpenSceneGraph Forum Forum Index -> General
View previous topic :: View next topic  
Author Message
caishanli
Newbie


Joined: 11 Aug 2017
Posts: 1

PostPosted: Fri Aug 11, 2017 6:45 am    Post subject:
multiple window pick incorrect
Reply with quote

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
Back to top
View user's profile Send private message
robertosfield
OSG Project Lead


Joined: 18 Mar 2009
Posts: 11275

PostPosted: Mon Aug 14, 2017 6:55 pm    Post subject:
multiple window pick incorrect
Reply with quote

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 < (
Only registered users can see emails on this board!
Get registred or enter the forums!
)> wrote:
Quote:
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:ShockedN);
                        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.Cool);
                        mtrl->setAmbient(osg::Material::FRONT_AND_BACK, osg::Vec4(1.0, 0.0, 0.0, 0.Cool);
                        mtrl->setTransparency(osg::Material::FRONT_AND_BACK, 0.2);
                        state->setAttributeAndModes(mtrl, osg::StateAttribute::OVERRIDE | osg::StateAttribute:ShockedN);
                        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
(
Only registered users can see emails on this board!
Get registred or enter the forums!
)
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


------------------
Post generated by Mail2Forum
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    OpenSceneGraph Forum Forum Index -> General All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum

Similar Topics
Topic Author Forum Replies Posted
No new posts multiple views + instancing d_a_heitbrink General 2 Wed Nov 15, 2017 7:06 pm View latest post
No new posts Multiple video textures using ffmpeg ... mmaurus Plugins [osgPlugins] 6 Thu Oct 05, 2017 10:02 am View latest post
No new posts Executing subtree multiple times / re... antiro42 General 2 Thu Sep 14, 2017 10:10 am View latest post
No new posts Problem blending multiple render passes antiro42 General 5 Sat Sep 09, 2017 9:44 am View latest post
No new posts Multiple pointlights deferred renderi... antiro42 General 0 Fri Sep 08, 2017 2:39 pm View latest post


Board Security Anti Bot Question MOD - phpBB MOD against Spam Bots
Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP