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:
@@ -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,9 +361,9 @@ 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;
|
||||
if (_requestContinousUpdate) 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,8 +826,12 @@ 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());
|
||||
|
||||
// OSG_NOTICE<<"Viewer::frameEventTraversal()."<<std::endl;
|
||||
|
||||
Reference in New Issue
Block a user