[osg-users] Custom CompositeViewer Events
Hi, I have a program which is using a custom viewer derived from osgViewer::View. In this custom view's scene may be some custom types derived from osg::Geode. I'll call these MyView and MyGeode for the sake of the post. MyView's are put inside a osgViewer::CompositeViewer. All this works great. Now, I want to send custom events to MyView and MyGeode. My original hope was that I could just register a handler on MyView and MyGeode and do something like "compositeViewer->accept(new MyEvent)", but it doesn't seem that easy. I ended up creating a "MyCompositeViewer" that has an "accept" function on it that takes MyOsgGaEventVisitor and then create a MyGUIEventHandler which attempts to dynamic_cast osgGA::GUIEventAdapter to MyEventAdapter. MyGUIEventHandler is created with a pointer to its owning MyView and then can make calls into MyView based on the event. I haven't started working on getting the event into MyView's scene and onto MyGeode's yet because this design is challenging my sanity. This approach works, but seems like a mess. Before I get too far down this rabbit hole, what is the RIGHT way to get a custom event sent from a top-level CompositeViewer to its subordinate views and then onto the view's scene nodes? The examples in OSG seem to address parts of this problem, but I can't see a solution to the entire scope of the problem. Another way to phrase the question might be: "How do I create a custom OSG-wide event that can be responded to by all osgViewer::View's and osg::Geode's alike?" Thank you! Cheers, John -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=62866#62866 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Custom CompositeViewer Events
Hi John, To add custom event handling there isn't normally a need to subclass from CompositeViewer and Geode. In snv/trunk and the OSG-3.3.x dev series there is now an osgGA::Event base class that you can subclass from. You can add your own events then inject them in the the View's EventQueue, these events will then be passed on to the EventHandlers attached to the View(er) and Event callbacks placed in the scene graph. In the EventHandler/Calback you get the pointer to the Event base class and then cast it to your custom type. In OSG-3.2 and before you can subclass from osgGA::GUIEventAdapter. It's not quite as clean as the new osgGA::Event but should work just fine. Robert. On 28 February 2015 at 17:09, John Farrier wrote: > Hi, > > I have a program which is using a custom viewer derived from > osgViewer::View. In this custom view's scene may be some custom types > derived from osg::Geode. I'll call these MyView and MyGeode for the sake > of the post. MyView's are put inside a osgViewer::CompositeViewer. All > this works great. Now, I want to send custom events to MyView and MyGeode. > > My original hope was that I could just register a handler on MyView and > MyGeode and do something like "compositeViewer->accept(new MyEvent)", but > it doesn't seem that easy. > > I ended up creating a "MyCompositeViewer" that has an "accept" function on > it that takes MyOsgGaEventVisitor and then create a MyGUIEventHandler which > attempts to dynamic_cast osgGA::GUIEventAdapter to MyEventAdapter. > MyGUIEventHandler is created with a pointer to its owning MyView and then > can make calls into MyView based on the event. I haven't started working > on getting the event into MyView's scene and onto MyGeode's yet because > this design is challenging my sanity. > > This approach works, but seems like a mess. Before I get too far down > this rabbit hole, what is the RIGHT way to get a custom event sent from a > top-level CompositeViewer to its subordinate views and then onto the view's > scene nodes? The examples in OSG seem to address parts of this problem, > but I can't see a solution to the entire scope of the problem. Another way > to phrase the question might be: > > "How do I create a custom OSG-wide event that can be responded to by all > osgViewer::View's and osg::Geode's alike?" > > Thank you! > > Cheers, > John > > -- > Read this topic online here: > http://forum.openscenegraph.org/viewtopic.php?p=62866#62866 > > > > > > ___ > osg-users mailing list > osg-users@lists.openscenegraph.org > http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org > ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Custom CompositeViewer Events
robertosfield wrote: > Hi John, > To add custom event handling there isn't normally a need to subclass from > CompositeViewer and Geode. > Robert, thanks for the tips. I've changed my solution as you have you suggested. However, the reason to subclass from Composite Viewer is because I see no other way to send an event to all views contained within the composite viewer otherwise. (I could get a list externally and send events, but that is a chunk of code that would need repeated every place a custom event needs sent.) Is there a way to pass an event into the composite viewer that I've overlooked? Thanks. - John -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=62889#62889 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Custom CompositeViewer Events
Hi John, On 2 March 2015 at 01:21, John Farrier wrote: > > Robert, thanks for the tips. I've changed my solution as you have you > suggested. However, the reason to subclass from Composite Viewer is > because I see no other way to send an event to all views contained within > the composite viewer otherwise. (I could get a list externally and send > events, but that is a chunk of code that would need repeated every place a > custom event needs sent.) Is there a way to pass an event into the > composite viewer that I've overlooked? > I don't know what you have overlooked so trying to guess what is or what is not something you've looked at and understand is impossible to say. The osgcluster example gets and send events between the master and slave instances over UDP packets, the slaves unpack the UDP and pass the events onto the viewer by injecting events the via the EventQueue. So have a look at this example. In OSG-3.3.x and svn/trunk there is also an osgDB::Device base class that allows you to create custom Device objects that can be attached to the View and have it provide the events. Robert. ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org