Permalink
Browse files

From Stephan Huber, added event sending support into osgGA::Device al…

…ong with implementation on this into the osc plugin. Added osgoscdevice example to demonstate this in action.
  • Loading branch information...
1 parent 8fb0830 commit 614a2efc8f5c8633813ad76078a18af50dc32a18 @osg-training-guest osg-training-guest committed Nov 28, 2012
@@ -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"))
View
@@ -78,6 +78,7 @@ IF(DYNAMIC_OPENSCENEGRAPH)
ADD_SUBDIRECTORY(osgoccluder)
ADD_SUBDIRECTORY(osgocclusionquery)
ADD_SUBDIRECTORY(osgoit)
+ ADD_SUBDIRECTORY(osgoscdevice)
ADD_SUBDIRECTORY(osgpackeddepthstencil)
ADD_SUBDIRECTORY(osgpagedlod)
ADD_SUBDIRECTORY(osgparametric)
@@ -0,0 +1,6 @@
+#this file is automatically generated
+
+
+SET(TARGET_SRC osgoscdevice.cpp )
+#### end var setup ###
+SETUP_EXAMPLE(osgoscdevice)
Oops, something went wrong.

0 comments on commit 614a2ef

Please sign in to comment.