From Stephan Huber, added event sending support into osgGA::Device along with implementation on this into the osc plugin. Added osgoscdevice example to demonstate this in action.

This commit is contained in:
Robert Osfield
2012-11-28 10:43:58 +00:00
parent 694e603d15
commit 8b231ba8e3
13 changed files with 574 additions and 950 deletions

View File

@@ -28,6 +28,7 @@
#include <OpenThreads/Thread>
#include <osgGA/GUIEventHandler>
#include <osgGA/TrackballManipulator>
#include <osgGA/FlightManipulator>
#include <osgGA/DriveManipulator>
@@ -129,6 +130,21 @@ void setViewer(osgViewer::Viewer& viewer, float width, float height, float dista
viewer.getCamera()->setProjectionMatrixAsPerspective( vfov, width/height, 0.1, 1000.0);
}
class ForwardToDeviceEventHandler : public osgGA::GUIEventHandler {
public:
ForwardToDeviceEventHandler(osgGA::Device* device) : osgGA::GUIEventHandler(), _device(device) {}
virtual bool handle (const osgGA::GUIEventAdapter &ea, osgGA::GUIActionAdapter &aa, osg::Object *, osg::NodeVisitor *)
{
_device->sendEvent(ea);
return false;
}
private:
osg::ref_ptr<osgGA::Device> _device;
};
class FollowMouseCallback: public osgGA::GUIEventHandler
{
public:
@@ -428,23 +444,17 @@ int main( int argc, char **argv )
std::string device;
while (arguments.read("--device", device))
{
osg::ref_ptr<osg::Object> obj = osgDB::readObjectFile(device);
osg::ref_ptr<osgGA::Device> dev = dynamic_cast<osgGA::Device*>(obj.get());
osg::ref_ptr<osgGA::Device> dev = osgDB::readFile<osgGA::Device>(device);
if (dev.valid())
{
OSG_NOTICE<<"Adding Device : "<<device<<std::endl;
viewer.addDevice(dev.get());
}
else
{
osgGA::GUIEventHandler* handler = dynamic_cast<osgGA::GUIEventHandler*>(obj.get());
if (handler)
{
OSG_NOTICE<<"Adding Device event handler : "<<device<<std::endl;
viewer.getEventHandlers().push_front(handler);
}
if (dev->getCapabilities() & osgGA::Device::RECEIVE_EVENTS)
viewer.addDevice(dev.get());
if (dev->getCapabilities() & osgGA::Device::SEND_EVENTS)
viewer.getEventHandlers().push_front(new ForwardToDeviceEventHandler(dev.get()));
}
}
if (arguments.read("--http-control"))