[osg-users] Update node color on demand
Eran Cohen
ceranco at gmail.com
Sat Nov 24 14:13:17 PST 2018
Hi,
To respond to user events you can either inherit from osg::Callback and install it on your node as an EventCallback:
Code:
class ColorCallback : public osg::Callback
{
public:
virtual bool run(osg::Object* object, osg::Object* data) override
{
auto nv = dynamic_cast<osg::NodeVisitor*>(data);
if (nv != nullptr && nv->getVisitorType() == nv->EVENT_VISITOR)
{
auto events = nv->asEventVisitor()->getEvents();
for (auto event : events)
{
// handle events
}
}
return traverse(object, data);
}
};
_lines->addEventCallback(new ColorCallback);
or use a global EventHandler and install it on your Viewer:
Code:
class ColorHandler : public osgGA::GUIEventHandler
{
virtual bool handle(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa) override
{
if (ea.getEventType() == ea.KEYDOWN)
{
// handle event
}
}
};
....
viewer->addEventHandler(new ColorHandler);
Cheers,
Eran
------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=75239#75239
More information about the osg-users
mailing list