Fixed panning bug, when using RUN_ON_DEMAND, that resulted in the camera being thrown off towards infinity.

The solution for to refactor the way that events are checked so I add a bool return type to checkEvents() method across osgViewer::GraphcisWindow, osgGA::Devive and osgViewer::Viewer/CompositeViewer classes
This commit is contained in:
Robert Osfield
2013-05-24 09:35:58 +00:00
parent 1cd73f0238
commit fb3178106a
24 changed files with 132 additions and 33 deletions

View File

@@ -37,7 +37,7 @@ class OSGGA_EXPORT Device : public osg::Object
int getCapabilities() const { return _capabilities; }
virtual void checkEvents() {};
virtual bool checkEvents() { return _eventQueue.valid() ? !(getEventQueue()->empty()) : false; }
virtual void sendEvent(const GUIEventAdapter& ea);
virtual void sendEvents(const EventQueue::Events& events);

View File

@@ -35,6 +35,12 @@ class OSGGA_EXPORT EventQueue : public osg::Referenced
typedef std::list< osg::ref_ptr<GUIEventAdapter> > Events;
bool empty() const
{
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_eventQueueMutex);
return _eventQueue.empty();
}
/** Set events.*/
void setEvents(Events& events);

View File

@@ -87,6 +87,9 @@ class OSGVIEWER_EXPORT CompositeViewer : public ViewerBase
/** Check to see if the new frame is required, called by run() when FrameScheme is set to ON_DEMAND.*/
virtual bool checkNeedToDoFrame();
/** check to see if events have been received, return true if events are now available.*/
virtual bool checkEvents();
virtual void advance(double simulationTime=USE_REFERENCE_TIME);
virtual void eventTraversal();

View File

@@ -53,7 +53,8 @@ class OSGVIEWER_EXPORT GraphicsWindow : public osg::GraphicsContext, public osgG
osgGA::EventQueue* getEventQueue() { return _eventQueue.get(); }
const osgGA::EventQueue* getEventQueue() const { return _eventQueue.get(); }
virtual void checkEvents() {}
/** Check events, return true if events have been received.*/
virtual bool checkEvents() { return false; }
/** Set the window's position and size.*/
void setWindowRectangle(int x, int y, int width, int height)

View File

@@ -320,7 +320,7 @@ class OSGVIEWER_EXPORT View : public osg::View, public osgGA::GUIActionAdapter
osg::Timer_t _startTick;
Devices _eventSources;
Devices _eventSources;
osg::ref_ptr<osgViewer::Scene> _scene;
osg::ref_ptr<osgGA::EventQueue> _eventQueue;

View File

@@ -87,6 +87,9 @@ class OSGVIEWER_EXPORT Viewer : public ViewerBase, public osgViewer::View
/** check to see if the new frame is required, called by run(..) when FrameScheme is set to ON_DEMAND.*/
virtual bool checkNeedToDoFrame();
/** check to see if events have been received, return true if events are now available.*/
virtual bool checkEvents();
virtual void advance(double simulationTime=USE_REFERENCE_TIME);
virtual void eventTraversal();

View File

@@ -224,6 +224,9 @@ class OSGVIEWER_EXPORT ViewerBase : public virtual osg::Object
/** check to see if the new frame is required, called by run(..) when FrameScheme is set to ON_DEMAND.*/
virtual bool checkNeedToDoFrame() = 0;
/** check to see if events have been received, return true if events are now available.*/
virtual bool checkEvents() = 0;
/** Render a complete new frame.
* Calls advance(), eventTraversal(), updateTraversal(), renderingTraversals(). */

View File

@@ -85,7 +85,7 @@ class GraphicsWindowCarbon : public osgViewer::GraphicsWindow, public osgViewer:
virtual void swapBuffersImplementation();
/** Check to see if any events have been generated.*/
virtual void checkEvents();
virtual bool checkEvents();
/** Set the window's position and size.*/
virtual bool setWindowRectangleImplementation(int x, int y, int width, int height);

View File

@@ -113,7 +113,7 @@ class GraphicsWindowCocoa : public osgViewer::GraphicsWindow, public osgViewer::
virtual void swapBuffersImplementation();
/** Check to see if any events have been generated.*/
virtual void checkEvents();
virtual bool checkEvents();
/** Set Window decoration.*/
virtual bool setWindowDecorationImplementation(bool flag);

View File

@@ -109,7 +109,7 @@ class GraphicsWindowIOS : public osgViewer::GraphicsWindow
virtual void swapBuffersImplementation();
/** Check to see if any events have been generated.*/
virtual void checkEvents();
virtual bool checkEvents();
/** Set Window decoration.*/
virtual bool setWindowDecorationImplementation(bool flag);

View File

@@ -58,7 +58,7 @@ class OSGVIEWER_EXPORT GraphicsWindowWin32 : public osgViewer::GraphicsWindow, p
virtual void swapBuffersImplementation();
/** Check to see if any events have been generated.*/
virtual void checkEvents();
virtual bool checkEvents();
/** Set the window's position and size.*/
virtual bool setWindowRectangleImplementation(int x, int y, int width, int height);

View File

@@ -97,7 +97,7 @@ class OSGVIEWER_EXPORT GraphicsWindowX11 : public osgViewer::GraphicsWindow, pub
virtual void swapBuffersImplementation();
/** Check to see if any events have been generated.*/
virtual void checkEvents();
virtual bool checkEvents();
/** Set Window decoration.*/
virtual bool setWindowDecorationImplementation(bool flag);