Added osgGA::Device class for integration of both physical and virtual devices.

Added template readFile(..) function to make it more convinient to cast to a specific object type.

Added support for osgGA::Device to osgViewer.

Added sdl plugin to provides very basic joystick osgGA::Device integration.
This commit is contained in:
Robert Osfield
2012-10-23 16:15:03 +00:00
parent f9ad1e5673
commit 1591fe09f3
14 changed files with 491 additions and 2 deletions

View File

@@ -43,9 +43,25 @@ extern OSGDB_EXPORT osg::Object* readObjectFile(const std::string& filename,cons
* to read the specified file.*/
inline osg::Object* readObjectFile(const std::string& filename)
{
return readObjectFile(filename,Registry::instance()->getOptions());
return readObjectFile(filename, Registry::instance()->getOptions());
}
template<typename T>
inline T* readFile(const std::string& filename, const Options* options)
{
osg::ref_ptr<osg::Object> object = readObjectFile(filename, options);
osg::ref_ptr<T> t = dynamic_cast<T*>(object.get());
object = 0;
return t.release();
}
template<typename T>
inline T* readFile(const std::string& filename)
{
return readFile<T>(filename, Registry::instance()->getOptions());
}
/** Read an osg::Image from file.
* Return valid osg::Image on success,
* return NULL on failure.

52
include/osgGA/Device Normal file
View File

@@ -0,0 +1,52 @@
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
*
* This library is open source and may be redistributed and/or modified under
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
* (at your option) any later version. The full license is in LICENSE file
* included with this distribution, and on the openscenegraph.org website.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* OpenSceneGraph Public License for more details.
*/
#ifndef OSGGA_EVENTSOURCE
#define OSGGA_EVENTSOURCE 1
#include <osgGA/EventQueue>
namespace osgGA {
/**
* Device base class from abstracting away from devices/windows that can generate events.
*/
class OSGGA_EXPORT Device : public osg::Object
{
public:
Device();
Device(const Device& es, const osg::CopyOp& copyop);
META_Object(osgGA,Device);
virtual void checkEvents() {};
void setEventQueue(osgGA::EventQueue* eventQueue) { _eventQueue = eventQueue; }
osgGA::EventQueue* getEventQueue() { return _eventQueue.get(); }
const osgGA::EventQueue* getEventQueue() const { return _eventQueue.get(); }
protected:
virtual ~Device();
/** Prevent unwanted copy operator.*/
Device& operator = (const Device&) { return *this; }
osg::ref_ptr<osgGA::EventQueue> _eventQueue;
};
}
#endif

View File

@@ -24,6 +24,7 @@
#include <osgGA/CameraManipulator>
#include <osgGA/EventVisitor>
#include <osgGA/EventQueue>
#include <osgGA/Device>
#include <osgViewer/Scene>
#include <osgViewer/ViewerBase>
@@ -108,6 +109,19 @@ class OSGVIEWER_EXPORT View : public osg::View, public osgGA::GUIActionAdapter
/** Get the const View's image pager.*/
const osgDB::ImagePager* getImagePager() const;
/** Add a Device.
* The Device is polled on each new frame via it's Device::checkEvents() method and any events generated then collected via Device::getEventQueue()*/
void addDevice(osgGA::Device* eventSource);
/** Remove a Device. /*/
void removeDevice(osgGA::Device* eventSource);
typedef std::vector< osg::ref_ptr<osgGA::Device> > Devices;
Devices& getDevices() { return _eventSources; }
const Devices& getDevices() const { return _eventSources; }
/* Set the EventQueue that the View uses to integrate external non window related events.*/
void setEventQueue(osgGA::EventQueue* eventQueue) { _eventQueue = eventQueue; }
@@ -250,6 +264,8 @@ class OSGVIEWER_EXPORT View : public osg::View, public osgGA::GUIActionAdapter
osg::Timer_t _startTick;
Devices _eventSources;
osg::ref_ptr<osgViewer::Scene> _scene;
osg::ref_ptr<osgGA::EventQueue> _eventQueue;
osg::ref_ptr<osgGA::CameraManipulator> _cameraManipulator;

View File

@@ -117,7 +117,6 @@ class OSGVIEWER_EXPORT ViewerBase : public virtual osg::Object
osg::BarrierOperation::PreBlockOp getEndBarrierOperation() const { return _endBarrierOperation; }
/** Set the done flag to signal the viewer's work is done and should exit the frame loop.*/
void setDone(bool done) { _done = done; }