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:
parent
1cd73f0238
commit
fb3178106a
@ -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);
|
||||
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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();
|
||||
|
@ -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)
|
||||
|
@ -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;
|
||||
|
@ -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();
|
||||
|
@ -225,6 +225,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(). */
|
||||
virtual void frame(double simulationTime=USE_REFERENCE_TIME);
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -169,7 +169,7 @@ public:
|
||||
|
||||
|
||||
|
||||
virtual void checkEvents()
|
||||
virtual bool checkEvents()
|
||||
{
|
||||
if ((fabs(_currentMouseX - _targetMouseY) > 0.1f) || (fabs(_currentMouseY - _targetMouseY) > 0.1))
|
||||
{
|
||||
@ -178,6 +178,7 @@ public:
|
||||
_currentMouseY = (1.0f - scalar) * _currentMouseY + scalar * _targetMouseY;
|
||||
getEventQueue()->mouseMotion(_currentMouseX, _currentMouseY, getEventQueue()->getTime());
|
||||
}
|
||||
return !(getEventQueue()->empty());
|
||||
}
|
||||
|
||||
void setTargetMousePosition(float x, float y, bool force = false)
|
||||
|
@ -37,9 +37,10 @@ public:
|
||||
_autoDiscovery->registerService(type, port);
|
||||
}
|
||||
|
||||
virtual void checkEvents()
|
||||
virtual bool checkEvents()
|
||||
{
|
||||
_autoDiscovery->update();
|
||||
return !(getEventQueue()->empty());
|
||||
}
|
||||
|
||||
virtual void sendEvent(const osgGA::GUIEventAdapter& event)
|
||||
@ -72,9 +73,10 @@ class ZeroConfDiscoverDevice : public osgGA::Device {
|
||||
public:
|
||||
ZeroConfDiscoverDevice(const std::string& type);
|
||||
|
||||
virtual void checkEvents()
|
||||
virtual bool checkEvents()
|
||||
{
|
||||
_autoDiscovery->update();
|
||||
return !(getEventQueue()->empty());
|
||||
}
|
||||
|
||||
private:
|
||||
|
@ -71,7 +71,6 @@ public:
|
||||
~OscReceivingDevice();
|
||||
|
||||
|
||||
virtual void checkEvents() {}
|
||||
virtual void run();
|
||||
|
||||
|
||||
|
@ -103,7 +103,7 @@ void JoystickDevice::capture(ValueList& axisValues, ValueList& buttonValues) con
|
||||
}
|
||||
}
|
||||
|
||||
void JoystickDevice::checkEvents()
|
||||
bool JoystickDevice::checkEvents()
|
||||
{
|
||||
if (_joystick)
|
||||
{
|
||||
@ -180,6 +180,6 @@ void JoystickDevice::checkEvents()
|
||||
_buttonValues.swap(newButtonValues);
|
||||
|
||||
}
|
||||
|
||||
return !(getEventQueue()->empty());
|
||||
}
|
||||
|
||||
|
@ -31,7 +31,7 @@ class JoystickDevice : public osgGA::Device
|
||||
typedef std::vector<int> ValueList;
|
||||
typedef std::map<int, int> ButtonMap;
|
||||
|
||||
virtual void checkEvents();
|
||||
virtual bool checkEvents();
|
||||
|
||||
void addMouseButtonMapping(int joystickButton, int mouseButton)
|
||||
{
|
||||
|
@ -266,8 +266,8 @@ bool CompositeViewer::checkNeedToDoFrame()
|
||||
}
|
||||
}
|
||||
|
||||
// now do a eventTraversal to see if any events might require a new frame.
|
||||
eventTraversal();
|
||||
// check if events are available and need processing
|
||||
if (checkEvents()) return true;
|
||||
|
||||
if (_requestRedraw) return true;
|
||||
if (_requestContinousUpdate) return true;
|
||||
@ -275,6 +275,44 @@ bool CompositeViewer::checkNeedToDoFrame()
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool CompositeViewer::checkEvents()
|
||||
{
|
||||
for(RefViews::iterator itr = _views.begin();
|
||||
itr != _views.end();
|
||||
++itr)
|
||||
{
|
||||
osgViewer::View* view = itr->get();
|
||||
if (view)
|
||||
{
|
||||
// check events from any attached sources
|
||||
for(View::Devices::iterator eitr = view->getDevices().begin();
|
||||
eitr != view->getDevices().end();
|
||||
++eitr)
|
||||
{
|
||||
osgGA::Device* es = eitr->get();
|
||||
if (es->getCapabilities() & osgGA::Device::RECEIVE_EVENTS)
|
||||
{
|
||||
if (es->checkEvents()) return true;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// get events from all windows attached to Viewer.
|
||||
Windows windows;
|
||||
getWindows(windows);
|
||||
for(Windows::iterator witr = windows.begin();
|
||||
witr != windows.end();
|
||||
++witr)
|
||||
{
|
||||
if ((*witr)->checkEvents()) return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
int CompositeViewer::run()
|
||||
{
|
||||
for(RefViews::iterator itr = _views.begin();
|
||||
@ -874,7 +912,11 @@ void CompositeViewer::eventTraversal()
|
||||
|
||||
if (_views.empty()) return;
|
||||
|
||||
#if 1
|
||||
double cutOffTime = _frameStamp->getReferenceTime();
|
||||
#else
|
||||
double cutOffTime = (_runFrameScheme==ON_DEMAND) ? DBL_MAX : _frameStamp->getReferenceTime();
|
||||
#endif
|
||||
|
||||
double beginEventTraversal = osg::Timer::instance()->delta_s(_startTick, osg::Timer::instance()->tick());
|
||||
|
||||
|
@ -844,9 +844,9 @@ bool GraphicsWindowCarbon::handleModifierKeys(EventRef theEvent)
|
||||
|
||||
|
||||
|
||||
void GraphicsWindowCarbon::checkEvents()
|
||||
bool GraphicsWindowCarbon::checkEvents()
|
||||
{
|
||||
if (!_realized) return;
|
||||
if (!_realized) return false;
|
||||
|
||||
EventRef theEvent;
|
||||
EventTargetRef theTarget = GetEventDispatcherTarget();
|
||||
@ -869,7 +869,7 @@ void GraphicsWindowCarbon::checkEvents()
|
||||
if ((fwres == inMenuBar) && (mouseButton >= 1)) {
|
||||
MenuSelect(wheresMyMouse);
|
||||
HiliteMenu(0);
|
||||
return;
|
||||
return !(getEventQueue()->empty());
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -903,6 +903,7 @@ void GraphicsWindowCarbon::checkEvents()
|
||||
s_quit_requested = false;
|
||||
}
|
||||
|
||||
return !(getEventQueue()->empty());
|
||||
}
|
||||
|
||||
|
||||
|
@ -1327,10 +1327,10 @@ void GraphicsWindowCocoa::swapBuffersImplementation()
|
||||
// checkEvents
|
||||
// process all pending events
|
||||
// ----------------------------------------------------------------------------------------------------------
|
||||
void GraphicsWindowCocoa::checkEvents()
|
||||
bool GraphicsWindowCocoa::checkEvents()
|
||||
{
|
||||
if (!_checkForEvents)
|
||||
return;
|
||||
return false;
|
||||
|
||||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||
|
||||
@ -1362,6 +1362,8 @@ void GraphicsWindowCocoa::checkEvents()
|
||||
}
|
||||
|
||||
[pool release];
|
||||
|
||||
return !(getEventQueue()->empty());
|
||||
}
|
||||
|
||||
|
||||
|
@ -1069,10 +1069,10 @@ bool GraphicsWindowIOS::setWindowRectangleImplementation(int x, int y, int width
|
||||
}
|
||||
|
||||
|
||||
void GraphicsWindowIOS::checkEvents()
|
||||
bool GraphicsWindowIOS::checkEvents()
|
||||
{
|
||||
|
||||
|
||||
return !(getEventQueue()->empty());
|
||||
}
|
||||
|
||||
|
||||
|
@ -2054,9 +2054,9 @@ void GraphicsWindowWin32::swapBuffersImplementation()
|
||||
}
|
||||
}
|
||||
|
||||
void GraphicsWindowWin32::checkEvents()
|
||||
bool GraphicsWindowWin32::checkEvents()
|
||||
{
|
||||
if (!_realized) return;
|
||||
if (!_realized) return false;
|
||||
|
||||
MSG msg;
|
||||
while (::PeekMessage(&msg, _hwnd, 0, 0, PM_REMOVE))
|
||||
@ -2076,6 +2076,8 @@ void GraphicsWindowWin32::checkEvents()
|
||||
_destroyWindow = false;
|
||||
destroyWindow(false);
|
||||
}
|
||||
|
||||
return !(getEventQueue()->empty());
|
||||
}
|
||||
|
||||
void GraphicsWindowWin32::grabFocus()
|
||||
|
@ -1197,9 +1197,9 @@ void GraphicsWindowX11::swapBuffersImplementation()
|
||||
}
|
||||
}
|
||||
|
||||
void GraphicsWindowX11::checkEvents()
|
||||
bool GraphicsWindowX11::checkEvents()
|
||||
{
|
||||
if (!_realized) return;
|
||||
if (!_realized) return false;
|
||||
|
||||
Display* display = _eventDisplay;
|
||||
|
||||
@ -1564,6 +1564,8 @@ void GraphicsWindowX11::checkEvents()
|
||||
requestRedraw();
|
||||
}
|
||||
}
|
||||
|
||||
return !(getEventQueue()->empty());
|
||||
}
|
||||
|
||||
void GraphicsWindowX11::grabFocus()
|
||||
|
@ -361,8 +361,8 @@ bool Viewer::checkNeedToDoFrame()
|
||||
if (_camera->getUpdateCallback()) return true;
|
||||
if (getSceneData()!=0 && getSceneData()->getNumChildrenRequiringUpdateTraversal()>0) return true;
|
||||
|
||||
// now do a eventTraversal to see if any events might require a new frame.
|
||||
eventTraversal();
|
||||
// check if events are available and need processing
|
||||
if (checkEvents()) return true;
|
||||
|
||||
// now check if any of the event handles have prompted a redraw.
|
||||
if (_requestRedraw) return true;
|
||||
@ -371,6 +371,34 @@ bool Viewer::checkNeedToDoFrame()
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Viewer::checkEvents()
|
||||
{
|
||||
// check events from any attached sources
|
||||
for(Devices::iterator eitr = _eventSources.begin();
|
||||
eitr != _eventSources.end();
|
||||
++eitr)
|
||||
{
|
||||
osgGA::Device* es = eitr->get();
|
||||
if (es->getCapabilities() & osgGA::Device::RECEIVE_EVENTS)
|
||||
{
|
||||
if (es->checkEvents()) return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// get events from all windows attached to Viewer.
|
||||
Windows windows;
|
||||
getWindows(windows);
|
||||
for(Windows::iterator witr = windows.begin();
|
||||
witr != windows.end();
|
||||
++witr)
|
||||
{
|
||||
if ((*witr)->checkEvents()) return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
int Viewer::run()
|
||||
{
|
||||
if (!getCameraManipulator() && getCamera()->getAllowEventFocus())
|
||||
@ -798,7 +826,11 @@ void Viewer::eventTraversal()
|
||||
{
|
||||
if (_done) return;
|
||||
|
||||
#if 1
|
||||
double cutOffTime = _frameStamp->getReferenceTime();
|
||||
#else
|
||||
double cutOffTime = (_runFrameScheme==ON_DEMAND) ? DBL_MAX : _frameStamp->getReferenceTime();
|
||||
#endif
|
||||
|
||||
double beginEventTraversal = osg::Timer::instance()->delta_s(_startTick, osg::Timer::instance()->tick());
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user