Further work osgViewer::Viewer and related classes.

This commit is contained in:
Robert Osfield
2006-12-20 21:13:29 +00:00
parent 32821ebe4e
commit 2255771b74
18 changed files with 580 additions and 36 deletions

View File

@@ -28,11 +28,26 @@
#include <osgViewer/GraphicsWindowX11>
#include <osgViewer/Viewer>
#include <osgGA/TrackballManipulator>
void renderCamera(osg::Camera* camera)
{
osg::GraphicsContext* gc = camera->getGraphicsContext();
if (!gc) return;
#if 0
osgViewer::GraphicsWindowX11* gwX11 = dynamic_cast<osgViewer::GraphicsWindowX11*>(gc);
if (gwX11)
{
gwX11->checkEvents();
osgGA::EventQueue::Events events;
if (gwX11->getEventQueue()->takeEvents(events))
{
}
}
#endif
osgUtil::SceneView* sceneView = dynamic_cast<osgUtil::SceneView*>(camera->getRenderingCache(0));
if (!sceneView) return;
@@ -77,6 +92,8 @@ int main( int argc, char **argv )
viewMatrix.makeLookAt(bs.center()-osg::Vec3(0.0,2.0f*bs.radius(),0.0),bs.center(),osg::Vec3(0.0f,0.0f,1.0f));
osg::ref_ptr<osgViewer::Viewer> viewer = new osgViewer::Viewer;
viewer->setSceneData(loadedModel.get());
viewer->setCameraManipulator(new osgGA::TrackballManipulator());
viewer->setUpViewAcrossAllScreens();
viewer->realize();
@@ -113,10 +130,12 @@ int main( int argc, char **argv )
// do the update traversal.
loadedModel->accept(updateVisitor);
viewer->frameAdvance();
viewer->frameEventTraversal();
viewer->frameUpdateTraversal();
viewer->getCamera()->setViewMatrix(viewMatrix);
// viewer->getCamera()->setViewMatrix(viewMatrix);
viewer->updateSlaves();
if (viewer->getCamera() && viewer->getCamera()->getGraphicsContext()) renderCamera(viewer->getCamera());

View File

@@ -163,6 +163,10 @@ public:
{
_mx = ea.getX();
_my = ea.getY();
osg::notify(osg::NOTICE)<<"_mx="<<_mx<<" _my="<<_my<<std::endl;
osg::notify(osg::NOTICE)<<" range ="<<ea.getXmin()<<", "<<ea.getXmax()<<std::endl;
return false;
}
case(osgGA::GUIEventAdapter::RELEASE):
@@ -190,7 +194,7 @@ public:
osg::Node* node = 0;
osg::Group* parent = 0;
bool usePolytopePicking = true;
bool usePolytopePicking = false;
if (usePolytopePicking)
{
@@ -358,11 +362,13 @@ int main( int argc, char **argv )
// set the mouse input range.
// Producer defaults to using non-dimensional units, so we pass this onto osgGA, most windowing toolkits use pixel coords so use the window size instead.
viewer.getEventQueue()->getCurrentEventState()->setInputRange(-1.0, -1.0, 1.0, 1.0);
viewer.getEventQueue()->setUseFixedMouseInputRange(true);
viewer.getEventQueue()->setMouseInputRange(-1.0, -1.0, 1.0, 1.0);
// Producer has the y axis increase upwards, like OpenGL, and contary to most Windowing toolkits.
// we need to construct the event queue so that it knows about this convention.
viewer.getEventQueue()->getCurrentEventState()->setMouseYOrientation(osgGA::GUIEventAdapter::Y_INCREASING_UPWARDS);
viewer.init();
@@ -370,7 +376,7 @@ int main( int argc, char **argv )
while( renderSurface->isRealized() && !kbmcb->done())
{
// update the window dimensions, in case the window has been resized.
viewer.getEventQueue()->windowResize(0,0,renderSurface->getWindowWidth(),renderSurface->getWindowHeight(), false);
viewer.getEventQueue()->windowResize(0,0,renderSurface->getWindowWidth(),renderSurface->getWindowHeight());
// pass any keyboard mouse events onto the local keyboard mouse callback.
kbm->update( *kbmcb );

View File

@@ -96,7 +96,8 @@ class GraphicsWindowProducer : public virtual osgViewer::GraphicsWindow, public
// set the mouse input range.
// Producer defaults to using non-dimensional units, so we pass this onto osgGA, most windowing toolkits use pixel coords so use the window size instead.
getEventQueue()->getCurrentEventState()->setInputRange(-1.0, -1.0, 1.0, 1.0);
getEventQueue()->setUseFixedMouseInputRange(true);
getEventQueue()->setMouseInputRange(-1.0, -1.0, 1.0, 1.0);
// Producer has the y axis increase upwards, like OpenGL, and contary to most Windowing toolkits.
// we need to construct the event queue so that it knows about this convention.
@@ -107,7 +108,7 @@ class GraphicsWindowProducer : public virtual osgViewer::GraphicsWindow, public
void setWindowRectangle(int x, int y, unsigned int width, unsigned int height, bool resize = true)
{
Producer::RenderSurface::setWindowRectangle(x, y, width, height, resize);
getEventQueue()->windowResize(x,y,width,height, false);
getEventQueue()->windowResize(x,y,width,height);
}
void realize() { Producer::RenderSurface::realize(); _kbm->startThread(); }
@@ -159,7 +160,7 @@ int main( int argc, char **argv )
while( viewer.isRealized() )
{
// update the window dimensions, in case the window has been resized.
viewer.getEventQueue()->windowResize(0,0,viewer.getWindowWidth(),viewer.getWindowHeight(), false);
viewer.getEventQueue()->windowResize(0,0,viewer.getWindowWidth(),viewer.getWindowHeight());
viewer.frame();
@@ -215,7 +216,8 @@ int main( int argc, char **argv )
// set the mouse input range.
// Producer defaults to using non-dimensional units, so we pass this onto osgGA, most windowing toolkits use pixel coords so use the window size instead.
viewer.getEventQueue()->getCurrentEventState()->setInputRange(-1.0, -1.0, 1.0, 1.0);
viewer.getEventQueue()->setUseFixedMouseInputRange(true);
viewer.getEventQueue()->setMouseInputRange(-1.0, -1.0, 1.0, 1.0);
// Producer has the y axis increase upwards, like OpenGL, and contary to most Windowing toolkits.
// we need to construct the event queue so that it knows about this convention.

View File

@@ -50,9 +50,18 @@ class OSGGA_EXPORT EventQueue : public osg::Referenced
/** Add an event to the end of the event queue.*/
void addEvent(GUIEventAdapter* event);
/** Specify if mouse coordinates should be transformed into a pre defined input range, or whether they
* should be simply based on as local coordinates to the window that generated the mouse events.*/
void setUseFixedMouseInputRange(bool useFixedMouseInputRange) { _useFixedMouseInputRange = useFixedMouseInputRange; }
/** Get whether the mouse coordinates should be transformed into a pre defined input range.*/
bool getUseFixedMouseInputRange() { return _useFixedMouseInputRange; }
/** Set the mouse input range.*/
void setMouseInputRange(float xMin, float yMin, float xMax, float yMax) { getCurrentEventState()->setInputRange(xMin, yMin, xMax, yMax); }
/** Method for adapting window resize event, placing this event on the back of the event queue. */
void windowResize(int x, int y, unsigned int width, unsigned int height, bool updateMouseRange = true);
void windowResize(int x, int y, unsigned int width, unsigned int height);
/** Method for adapting mouse scroll wheel events, placing this event on the back of the event queue. */
void mouseScroll(GUIEventAdapter::ScrollingMotion sm);
@@ -84,11 +93,11 @@ class OSGGA_EXPORT EventQueue : public osg::Referenced
* Button numbering is 1 for left mouse button, 2 for middle, 3 for right. */
void mouseButtonRelease(float x, float y, unsigned int button);
/** Method for adapting keyboard press events.*/
void keyPress(GUIEventAdapter::KeySymbol key);
/** Method for adapting keyboard press events. Note, special keys such as Ctrl/Function keys should be adapted to GUIEventAdapter::KeySymbol mappings.*/
void keyPress(int key);
/** Method for adapting keyboard press events.*/
void keyRelease(GUIEventAdapter::KeySymbol key);
/** Method for adapting keyboard press events. Note, special keys such as Ctrl/Function keys should be adapted to GUIEventAdapter::KeySymbol mappings.*/
void keyRelease(int key);
/** Method for adapting frame events.*/
void frame(double t);
@@ -114,6 +123,8 @@ class OSGGA_EXPORT EventQueue : public osg::Referenced
osg::ref_ptr<GUIEventAdapter> _accumulateEventState;
bool _useFixedMouseInputRange;
osg::Timer_t _startTick;
mutable OpenThreads::Mutex _eventQueueMutex;
Events _eventQueue;

View File

@@ -271,6 +271,7 @@ public:
/** deprecated function for getting time of event. */
double time() const { return _time; }
/** set window rectangle. */
void setWindowRectangle(int x, int y, unsigned int width, unsigned int height, bool updateMouseRange = true);

View File

@@ -40,6 +40,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() {}
public:
/** Realise the GraphicsContext implementation,

View File

@@ -16,6 +16,9 @@
* These elements are license under OSGPL as above, with Copyright (C) 2001-2004 Don Burns.
*/
#ifndef OSGVIEWER_GRAPHICSWINDOWX11
#define OSGVIEWER_GRAPHICSWINDOWX11 1
#include <osgViewer/Viewer>
#include <X11/X.h>
@@ -23,11 +26,16 @@
#include <X11/Xutil.h>
#include <X11/Xmd.h>
#include <X11/keysym.h>
#include <X11/Xmu/WinUtil.h>
#include <X11/cursorfont.h>
#define GLX_GLXEXT_PROTOTYPES 1
#include <GL/glx.h>
namespace osgViewer
{
class GraphicsContextX11 : public osg::GraphicsContext
{
public:
@@ -110,14 +118,20 @@ class GraphicsWindowX11 : public osgViewer::GraphicsWindow
/** Make this graphics context current.*/
virtual void makeCurrentImplementation();
/** swap the front and back buffers.*/
/** Swap the front and back buffers.*/
virtual void swapBuffersImplementation();
/** Check to see if any events have been generated.*/
virtual void checkEvents();
protected:
bool createVisualInfo();
void setBorder(bool flag);
void init();
void transformMouseXY(float& x, float& y);
void adaptKey(XKeyEvent& keyevent, int& keySymbol, unsigned int& modifierMask);
Display* _display;
Window _parent;
@@ -280,6 +294,7 @@ void GraphicsWindowX11::init()
XWindowAttributes watt;
XGetWindowAttributes( _display, _parent, &watt );
// unsigned int parentWindowHeight = watt.height;
osg::notify(osg::NOTICE)<<"First watt.x = "<<watt.x<<" watt.y="<<watt.y<<std::endl;
XSetWindowAttributes swatt;
swatt.colormap = XCreateColormap( _display, _parent, _visualInfo->visual, AllocNone);
@@ -322,8 +337,11 @@ void GraphicsWindowX11::init()
sh.height = _traits->_height;
XSetStandardProperties( _display, _window, _traits->_windowName.c_str(), _traits->_windowName.c_str(), None, 0, 0, &sh);
#if 1
setBorder(_traits->_windowDecoration);
#else
setBorder(true);
#endif
// Create default Cursor
_defaultCursor = XCreateFontCursor( _display, XC_left_ptr );
@@ -349,6 +367,13 @@ void GraphicsWindowX11::init()
XSync(_display,0);
}
XSelectInput( _display, _window, ExposureMask | StructureNotifyMask |
KeyPressMask | KeyReleaseMask |
PointerMotionMask | ButtonPressMask | ButtonReleaseMask);
XFlush( _display );
XSync( _display, 0 );
_initialized = true;
}
@@ -403,9 +428,236 @@ void GraphicsWindowX11::swapBuffersImplementation()
glXSwapBuffers(_display, _window);
}
void GraphicsWindowX11::checkEvents()
{
// osg::notify(osg::NOTICE)<<"Check events"<<std::endl;
while( XPending(_display) )
{
XEvent ev;
XNextEvent( _display, &ev );
switch( ev.type )
{
case Expose :
osg::notify(osg::NOTICE)<<"Expose"<<std::endl;
break;
case GravityNotify :
osg::notify(osg::NOTICE)<<"GravityNotify"<<std::endl;
break;
case UnmapNotify :
osg::notify(osg::NOTICE)<<"UnmapNotify"<<std::endl;
break;
case ReparentNotify:
osg::notify(osg::NOTICE)<<"ReparentNotify"<<std::endl;
break;
case DestroyNotify :
osg::notify(osg::NOTICE)<<"DestroyNotify"<<std::endl;
_realized = false;
break;
case ConfigureNotify :
{
osg::notify(osg::NOTICE)<<"ConfigureNotify x="<<ev.xconfigure.x<<" y="<<ev.xconfigure.y<<" width="<<ev.xconfigure.width<<", height="<<ev.xconfigure.height<<std::endl;
_traits->_x = ev.xconfigure.x;
_traits->_y = ev.xconfigure.y;
_traits->_width = ev.xconfigure.width;
_traits->_height = ev.xconfigure.height;
// need to dispatch resize event.
break;
}
case MapNotify :
{
osg::notify(osg::NOTICE)<<"MapNotify"<<std::endl;
XWindowAttributes watt;
do
XGetWindowAttributes(_display, _window, &watt );
while( watt.map_state != IsViewable );
XSetInputFocus( _display, _window, RevertToNone, CurrentTime );
XFlush(_display); XSync(_display,0);
break;
}
case MotionNotify :
{
int wx, wy;
Window win = 0L;
if( ev.xmotion.same_screen )
{
wx = ev.xmotion.x;
wy = ev.xmotion.y;
}
else
{
// the mouse in on another screen so need to compute the
// coordinates of the mouse position relative to an absolute position
// then take away the position of the original window/screen to get
// the coordinates relative to the original position.
Window root;
int rx, ry;
unsigned int buttons;
int screenOrigin_x = 0;
int screenOrigin_y = 0;
int i;
for(i= 0; i < ScreenCount(_display); i++ )
{
if( XQueryPointer( _display, RootWindow(_display, i),
&root, &win, &rx, &ry, &wx, &wy, &buttons) )
{
break;
}
screenOrigin_x += DisplayWidth(_display, i);
}
for(i= 0; i < static_cast<int>(_traits->_screenNum); i++ )
{
screenOrigin_x -= DisplayWidth(_display, i);
}
wx += (screenOrigin_x - _traits->_x);
wy += (screenOrigin_y - _traits->_y);
}
float mx = wx;
float my = wy;
transformMouseXY(mx, my);
getEventQueue()->mouseMotion(mx, my);
break;
}
case ButtonPress :
{
if( ev.xbutton.button == Button4 )
{
getEventQueue()->mouseScroll(osgGA::GUIEventAdapter::SCROLL_UP);
}
else if( ev.xbutton.button == Button5)
{
getEventQueue()->mouseScroll(osgGA::GUIEventAdapter::SCROLL_DOWN);
}
else
{
float mx = ev.xbutton.x;
float my = ev.xmotion.y;
transformMouseXY(mx, my);
getEventQueue()->mouseButtonPress(mx, my, ev.xbutton.button);
}
break;
}
case ButtonRelease :
{
if( ev.xbutton.button == Button4 )
{
getEventQueue()->mouseScroll(osgGA::GUIEventAdapter::SCROLL_UP);
}
else if( ev.xbutton.button == Button5)
{
getEventQueue()->mouseScroll(osgGA::GUIEventAdapter::SCROLL_DOWN);
}
else
{
float mx = ev.xbutton.x;
float my = ev.xmotion.y;
transformMouseXY(mx, my);
getEventQueue()->mouseButtonRelease(mx, my, ev.xbutton.button);
}
break;
}
case KeyPress:
{
int keySymbol = 0;
unsigned int modifierMask = 0;
adaptKey(ev.xkey, keySymbol, modifierMask);
getEventQueue()->keyPress(keySymbol);
getEventQueue()->getCurrentEventState()->setModKeyMask(modifierMask);
break;
}
case KeyRelease:
{
int keySymbol = 0;
unsigned int modifierMask = 0;
adaptKey(ev.xkey, keySymbol, modifierMask);
getEventQueue()->keyRelease(keySymbol);
getEventQueue()->getCurrentEventState()->setModKeyMask(modifierMask);
break;
}
default:
osg::notify(osg::NOTICE)<<"Other event"<<std::endl;
break;
}
}
}
void GraphicsWindowX11::transformMouseXY(float& x, float& y)
{
if (getEventQueue()->getUseFixedMouseInputRange())
{
osgGA::GUIEventAdapter* eventState = getEventQueue()->getCurrentEventState();
x = eventState->getXmin() + (eventState->getXmax()-eventState->getXmin())*x/float(_traits->_width);
y = eventState->getYmin() + (eventState->getYmax()-eventState->getYmin())*y/float(_traits->_height);
}
}
void GraphicsWindowX11::adaptKey(XKeyEvent& keyevent, int& keySymbol, unsigned int& modifierMask)
{
// KeySym ks = XKeycodeToKeysym( _display, keyevent.keycode, 0 );
static XComposeStatus state;
unsigned char keybuf[32];
XLookupString( &keyevent, (char *)keybuf, sizeof(keybuf), NULL, &state );
modifierMask = 0;
if( keyevent.state & ShiftMask )
{
modifierMask |= osgGA::GUIEventAdapter::MODKEY_SHIFT;
}
if( keyevent.state & LockMask )
{
modifierMask |= osgGA::GUIEventAdapter::MODKEY_CAPS_LOCK;
}
if( keyevent.state & ControlMask )
{
modifierMask |= osgGA::GUIEventAdapter::MODKEY_CTRL;
}
if( keyevent.state & Mod1Mask )
{
modifierMask |= osgGA::GUIEventAdapter::MODKEY_ALT;
}
if( keyevent.state & Mod2Mask )
{
modifierMask |= osgGA::GUIEventAdapter::MODKEY_NUM_LOCK;
}
if( keyevent.state & Mod4Mask )
{
modifierMask |= osgGA::GUIEventAdapter::MODKEY_META;
}
keySymbol = keybuf[0];
}
struct X11WindowingSystemInterface : public osg::GraphicsContext::WindowingSystemInterface
{
X11WindowingSystemInterface()
{
}
virtual unsigned int getNumScreens(const osg::GraphicsContext::ScreenIdentifier& si)
{
const char* displayString = si._hostName.c_str();
@@ -453,6 +705,7 @@ struct X11WindowingSystemInterface : public osg::GraphicsContext::WindowingSyste
return new GraphicsWindowX11(traits);
}
}
};
struct RegisterWindowingSystemInterfaceProxy
@@ -469,3 +722,7 @@ struct RegisterWindowingSystemInterfaceProxy
};
RegisterWindowingSystemInterfaceProxy createWindowingSystemInterfaceProxy;
}
#endif

View File

@@ -39,6 +39,7 @@ class OSGVIEWER_EXPORT Scene : public virtual osg::Referenced
osg::Node* getSceneData();
const osg::Node* getSceneData() const;
osg::FrameStamp* getFrameStamp() { return _frameStamp.get(); }
void setEventQueue(osgGA::EventQueue* eventQueue) { _eventQueue = eventQueue; }
osgGA::EventQueue* getEventQueue() { return _eventQueue.get(); }

View File

@@ -31,6 +31,10 @@ class OSGVIEWER_EXPORT View : public osg::View
osg::Node* getSceneData() { return _scene.valid() ? _scene->getSceneData() : 0; }
const osg::Node* getSceneData() const { return _scene.valid() ? _scene->getSceneData() : 0; }
void setEventQueue(osgGA::EventQueue* eventQueue) { _eventQueue = eventQueue; }
osgGA::EventQueue* getEventQueue() { return _eventQueue.get(); }
const osgGA::EventQueue* getEventQueue() const { return _eventQueue.get(); }
void setCameraManipulator(osgGA::MatrixManipulator* manipulator);
osgGA::MatrixManipulator* getCameraManipulator() { return _cameraManipulator.get(); }
const osgGA::MatrixManipulator* getCameraManipulator() const { return _cameraManipulator.get(); }
@@ -56,6 +60,7 @@ class OSGVIEWER_EXPORT View : public osg::View
virtual ~View();
osg::ref_ptr<osgViewer::Scene> _scene;
osg::ref_ptr<osgGA::EventQueue> _eventQueue;
osg::ref_ptr<osgGA::MatrixManipulator> _cameraManipulator;
EventHandlers _eventHandlers;

View File

@@ -52,6 +52,7 @@ class OSGVIEWER_EXPORT Viewer : public osgViewer::View
public:
void init();
bool _firstFrame;
protected:

View File

@@ -18,6 +18,7 @@ using namespace osgGA;
EventQueue::EventQueue(GUIEventAdapter::MouseYOrientation mouseYOrientation)
{
_useFixedMouseInputRange = false;
_startTick = osg::Timer::instance()->tick();
_accumulateEventState = new GUIEventAdapter();
_accumulateEventState->setMouseYOrientation(mouseYOrientation);
@@ -77,9 +78,9 @@ bool EventQueue::copyEvents(Events& events) const
}
void EventQueue::windowResize(int x, int y, unsigned int width, unsigned int height, bool updateMouseRange)
void EventQueue::windowResize(int x, int y, unsigned int width, unsigned int height)
{
_accumulateEventState->setWindowRectangle(x, y, width, height, updateMouseRange);
_accumulateEventState->setWindowRectangle(x, y, width, height, !_useFixedMouseInputRange);
GUIEventAdapter* event = new GUIEventAdapter(*_accumulateEventState);
event->setEventType(GUIEventAdapter::RESIZE);
@@ -252,7 +253,7 @@ void EventQueue::mouseButtonRelease(float x, float y, unsigned int button)
addEvent(event);
}
void EventQueue::keyPress(GUIEventAdapter::KeySymbol key)
void EventQueue::keyPress(int key)
{
switch(key)
{
@@ -290,7 +291,7 @@ void EventQueue::keyPress(GUIEventAdapter::KeySymbol key)
addEvent(event);
}
void EventQueue::keyRelease(GUIEventAdapter::KeySymbol key)
void EventQueue::keyRelease(int key)
{
switch(key)
{

View File

@@ -18,10 +18,21 @@
using namespace osgViewer;
class ActionAdapter : public osgGA::GUIActionAdapter
{
public:
virtual ~ActionAdapter() {}
virtual void requestRedraw() { /*osg::notify(osg::NOTICE)<<"requestRedraw()"<<std::endl;*/ }
virtual void requestContinuousUpdate(bool needed=true) { /*osg::notify(osg::NOTICE)<<"requestContinuousUpdate("<<needed<<")"<<std::endl;*/ }
virtual void requestWarpPointer(float x,float y) { osg::notify(osg::NOTICE)<<"requestWarpPointer("<<x<<","<<y<<")"<<std::endl; }
};
View::View()
{
// osg::notify(osg::NOTICE)<<"Constructing osgViewer::View"<<std::endl;
setEventQueue(new osgGA::EventQueue);
}
View::~View()
@@ -37,6 +48,20 @@ void View::setSceneData(osg::Node* node)
assignSceneDataToCameras();
}
void View::setCameraManipulator(osgGA::MatrixManipulator* manipulator)
{
_cameraManipulator = manipulator;
if (_cameraManipulator.valid() && getSceneData())
{
_cameraManipulator->setNode(getSceneData());
osg::ref_ptr<osgGA::GUIEventAdapter> dummyEvent = _eventQueue->createEvent();
ActionAdapter aa;
_cameraManipulator->home(*dummyEvent, aa);
}
}
void View::setUpViewAcrossAllScreens()
{
osg::GraphicsContext::GraphicsContext::WindowingSystemInterface* wsi = osg::GraphicsContext::getWindowingSystemInterface();
@@ -86,6 +111,11 @@ void View::setUpViewAcrossAllScreens()
else
{
double rotate_x = - double(numScreens-1) * 0.5 * fovx;
float inputRangeMinX = 0.0f;
float inputRangeMinY = 0.0f;
float maxHeight = 0.0f;
for(unsigned int i=0; i<numScreens; ++i, rotate_x += fovx)
{
@@ -111,6 +141,12 @@ void View::setUpViewAcrossAllScreens()
if (gw)
{
osg::notify(osg::NOTICE)<<" GraphicsWindow has been created successfully."<<gw<<std::endl;
gw->getEventQueue()->setUseFixedMouseInputRange(true);
gw->getEventQueue()->getCurrentEventState()->setInputRange(inputRangeMinX, inputRangeMinY, inputRangeMinX+float(width),inputRangeMinY+float(height) );
inputRangeMinX += float(width);
if (maxHeight < float(height)) maxHeight = float(height);
}
else
{
@@ -122,6 +158,9 @@ void View::setUpViewAcrossAllScreens()
addSlave(camera.get(), osg::Matrixd(), osg::Matrixd::rotate( rotate_x, 0.0, 1.0, 0.0));
}
getEventQueue()->setUseFixedMouseInputRange(true);
getEventQueue()->getCurrentEventState()->setInputRange(0.0f, 0.0, inputRangeMinX, maxHeight);
}
setUpRenderingSupport();
@@ -156,6 +195,16 @@ void View::assignSceneDataToCameras()
{
osg::Node* sceneData = _scene.valid() ? _scene->getSceneData() : 0;
if (_cameraManipulator.valid())
{
_cameraManipulator->setNode(sceneData);
osg::ref_ptr<osgGA::GUIEventAdapter> dummyEvent = _eventQueue->createEvent();
ActionAdapter aa;
_cameraManipulator->home(*dummyEvent, aa);
}
if (_camera.valid())
{
_camera->removeChildren(0,_camera->getNumChildren());

View File

@@ -18,7 +18,19 @@
using namespace osgViewer;
Viewer::Viewer()
class ActionAdapter : public osgGA::GUIActionAdapter
{
public:
virtual ~ActionAdapter() {}
virtual void requestRedraw() { /*osg::notify(osg::NOTICE)<<"requestRedraw()"<<std::endl;*/ }
virtual void requestContinuousUpdate(bool needed=true) { /*osg::notify(osg::NOTICE)<<"requestContinuousUpdate("<<needed<<")"<<std::endl;*/ }
virtual void requestWarpPointer(float x,float y) { osg::notify(osg::NOTICE)<<"requestWarpPointer("<<x<<","<<y<<")"<<std::endl; }
};
Viewer::Viewer():
_firstFrame(true)
{
}
@@ -26,6 +38,20 @@ Viewer::~Viewer()
{
}
void Viewer::init()
{
osg::notify(osg::NOTICE)<<"Viewer::init()"<<std::endl;
osg::ref_ptr<osgGA::GUIEventAdapter> initEvent = _eventQueue->createEvent();
initEvent->setEventType(osgGA::GUIEventAdapter::FRAME);
if (_cameraManipulator.valid())
{
ActionAdapter aa;
_cameraManipulator->init(*initEvent, aa);
}
}
void Viewer::realize()
{
osg::notify(osg::NOTICE)<<"Viewer::realize()"<<std::endl;
@@ -49,22 +75,141 @@ void Viewer::realize()
void Viewer::frame()
{
osg::notify(osg::NOTICE)<<"Viewer::frame() not implemented yet."<<std::endl;
if (_firstFrame)
{
init();
_firstFrame = false;
}
frameEventTraversal();
frameUpdateTraversal();
frameCullTraversal();
frameDrawTraversal();
}
void Viewer::frameAdvance()
{
osg::notify(osg::NOTICE)<<"Viewer::frameAdvance() not implemented yet."<<std::endl;
// osg::notify(osg::NOTICE)<<"Viewer::frameAdvance()."<<std::endl;
_scene->frameAdvance();
}
void Viewer::frameEventTraversal()
{
osg::notify(osg::NOTICE)<<"Viewer::frameEventTraversal() not implemented yet."<<std::endl;
// osg::notify(osg::NOTICE)<<"Viewer::frameEventTraversal()."<<std::endl;
// need to copy events from the GraphicsWindow's into local EventQueue;
osgGA::EventQueue::Events events;
if (_camera.valid() && _camera->getGraphicsContext())
{
osgViewer::GraphicsWindow* gw = dynamic_cast<osgViewer::GraphicsWindow*>(_camera->getGraphicsContext());
if (gw)
{
gw->checkEvents();
gw->getEventQueue()->takeEvents(events);
}
}
for(unsigned int i=0; i<getNumSlaves(); ++i)
{
Slave& slave = getSlave(i);
if (slave._camera.valid() && slave._camera->getGraphicsContext())
{
osgViewer::GraphicsWindow* gw = dynamic_cast<osgViewer::GraphicsWindow*>(slave._camera->getGraphicsContext());
if (gw)
{
gw->checkEvents();
gw->getEventQueue()->takeEvents(events);
}
}
}
_eventQueue->frame( _scene->getFrameStamp()->getReferenceTime() );
_eventQueue->takeEvents(events);
osgGA::GUIEventAdapter* eventState = getEventQueue()->getCurrentEventState();
for(osgGA::EventQueue::Events::iterator itr = events.begin();
itr != events.end();
++itr)
{
osgGA::GUIEventAdapter* event = itr->get();
event->setInputRange(eventState->getXmin(), eventState->getYmin(), eventState->getXmax(), eventState->getYmax());
}
#if 0
// osg::notify(osg::NOTICE)<<"Events "<<events.size()<<std::endl;
for(osgGA::EventQueue::Events::iterator itr = events.begin();
itr != events.end();
++itr)
{
osgGA::GUIEventAdapter* event = itr->get();
switch(event->getEventType())
{
case(osgGA::GUIEventAdapter::PUSH):
osg::notify(osg::NOTICE)<<" PUSH "<<event->getButton()<<" x="<<event->getX()<<" y="<<event->getY()<<std::endl;
break;
case(osgGA::GUIEventAdapter::RELEASE):
osg::notify(osg::NOTICE)<<" RELEASE "<<event->getButton()<<" x="<<event->getX()<<" y="<<event->getY()<<std::endl;
break;
case(osgGA::GUIEventAdapter::DRAG):
osg::notify(osg::NOTICE)<<" DRAG "<<event->getButtonMask()<<" x="<<event->getX()<<" y="<<event->getY()<<std::endl;
break;
case(osgGA::GUIEventAdapter::MOVE):
osg::notify(osg::NOTICE)<<" MOVE "<<event->getButtonMask()<<" x="<<event->getX()<<" y="<<event->getY()<<std::endl;
break;
case(osgGA::GUIEventAdapter::SCROLL):
osg::notify(osg::NOTICE)<<" SCROLL "<<event->getScrollingMotion()<<std::endl;
break;
case(osgGA::GUIEventAdapter::KEYDOWN):
osg::notify(osg::NOTICE)<<" KEYDOWN '"<<(char)event->getKey()<<"'"<<std::endl;
break;
case(osgGA::GUIEventAdapter::KEYUP):
osg::notify(osg::NOTICE)<<" KEYUP '"<<(char)event->getKey()<<"'"<<std::endl;
break;
case(osgGA::GUIEventAdapter::FRAME):
// osg::notify(osg::NOTICE)<<" FRAME "<<std::endl;
break;
default:
// osg::notify(osg::NOTICE)<<" Event not handled"<<std::endl;
break;
}
}
#endif
ActionAdapter aa;
for(osgGA::EventQueue::Events::iterator itr = events.begin();
itr != events.end();
++itr)
{
osgGA::GUIEventAdapter* event = itr->get();
bool handled = false;
if (_cameraManipulator.valid())
{
_cameraManipulator->handle( *event, aa);
}
for(EventHandlers::iterator hitr = _eventHandlers.begin();
hitr != _eventHandlers.end() && !handled;
++hitr)
{
handled = (*hitr)->handle( *event, aa, 0, 0);
}
}
}
void Viewer::frameUpdateTraversal()
{
osg::notify(osg::NOTICE)<<"Viewer::frameUpdateTraversal() not implemented yet."<<std::endl;
if (_cameraManipulator.valid())
{
_camera->setViewMatrix(_cameraManipulator->getInverseMatrix());
}
updateSlaves();
}
void Viewer::frameCullTraversal()

View File

@@ -50,10 +50,22 @@ BEGIN_OBJECT_REFLECTOR(osgGA::EventQueue)
__void__addEvent__GUIEventAdapter_P1,
"Add an event to the end of the event queue. ",
"");
I_MethodWithDefaults5(void, windowResize, IN, int, x, , IN, int, y, , IN, unsigned int, width, , IN, unsigned int, height, , IN, bool, updateMouseRange, true,
__void__windowResize__int__int__unsigned_int__unsigned_int__bool,
"Method for adapting window resize event, placing this event on the back of the event queue. ",
"");
I_Method1(void, setUseFixedMouseInputRange, IN, bool, useFixedMouseInputRange,
__void__setUseFixedMouseInputRange__bool,
"Specify if mouse coordinates should be transformed into a pre defined input range, or whether they should be simply based on as local coordinates to the window that generated the mouse events. ",
"");
I_Method0(bool, getUseFixedMouseInputRange,
__bool__getUseFixedMouseInputRange,
"Get whether the mouse coordinates should be transformed into a pre defined input range. ",
"");
I_Method4(void, setMouseInputRange, IN, float, xMin, IN, float, yMin, IN, float, xMax, IN, float, yMax,
__void__setMouseInputRange__float__float__float__float,
"Set the mouse input range. ",
"");
I_Method4(void, windowResize, IN, int, x, IN, int, y, IN, unsigned int, width, IN, unsigned int, height,
__void__windowResize__int__int__unsigned_int__unsigned_int,
"Method for adapting window resize event, placing this event on the back of the event queue. ",
"");
I_Method1(void, mouseScroll, IN, osgGA::GUIEventAdapter::ScrollingMotion, sm,
__void__mouseScroll__GUIEventAdapter_ScrollingMotion,
"Method for adapting mouse scroll wheel events, placing this event on the back of the event queue. ",
@@ -90,14 +102,14 @@ BEGIN_OBJECT_REFLECTOR(osgGA::EventQueue)
__void__mouseButtonRelease__float__float__unsigned_int,
"Method for adapting mouse button release events, placing this event on the back of the event queue. ",
"Button numbering is 1 for left mouse button, 2 for middle, 3 for right. ");
I_Method1(void, keyPress, IN, osgGA::GUIEventAdapter::KeySymbol, key,
__void__keyPress__GUIEventAdapter_KeySymbol,
I_Method1(void, keyPress, IN, int, key,
__void__keyPress__int,
"Method for adapting keyboard press events. ",
"");
I_Method1(void, keyRelease, IN, osgGA::GUIEventAdapter::KeySymbol, key,
__void__keyRelease__GUIEventAdapter_KeySymbol,
"Note, special keys such as Ctrl/Function keys should be adapted to GUIEventAdapter::KeySymbol mappings. ");
I_Method1(void, keyRelease, IN, int, key,
__void__keyRelease__int,
"Method for adapting keyboard press events. ",
"");
"Note, special keys such as Ctrl/Function keys should be adapted to GUIEventAdapter::KeySymbol mappings. ");
I_Method1(void, frame, IN, double, t,
__void__frame__double,
"Method for adapting frame events. ",
@@ -138,6 +150,9 @@ BEGIN_OBJECT_REFLECTOR(osgGA::EventQueue)
I_SimpleProperty(double, Time,
__double__getTime,
0);
I_SimpleProperty(bool, UseFixedMouseInputRange,
__bool__getUseFixedMouseInputRange,
__void__setUseFixedMouseInputRange__bool);
END_REFLECTOR
BEGIN_VALUE_REFLECTOR(osg::ref_ptr< osgGA::GUIEventAdapter >)

View File

@@ -40,6 +40,10 @@ BEGIN_OBJECT_REFLECTOR(osgViewer::GraphicsWindow)
__C5_osgGA_EventQueue_P1__getEventQueue,
"",
"");
I_Method0(void, checkEvents,
__void__checkEvents,
"",
"");
I_Method0(bool, realizeImplementation,
__bool__realizeImplementation,
"Realise the GraphicsContext implementation, Pure virtual - must be implemented by concrate implementations of GraphicsContext. ",

View File

@@ -10,6 +10,7 @@
#include <osgIntrospection/StaticMethodInfo>
#include <osgIntrospection/Attributes>
#include <osg/FrameStamp>
#include <osg/Node>
#include <osgDB/DatabasePager>
#include <osgGA/EventQueue>
@@ -43,6 +44,10 @@ BEGIN_OBJECT_REFLECTOR(osgViewer::Scene)
__C5_osg_Node_P1__getSceneData,
"",
"");
I_Method0(osg::FrameStamp *, getFrameStamp,
__osg_FrameStamp_P1__getFrameStamp,
"",
"");
I_Method1(void, setEventQueue, IN, osgGA::EventQueue *, eventQueue,
__void__setEventQueue__osgGA_EventQueue_P1,
"",
@@ -104,6 +109,9 @@ BEGIN_OBJECT_REFLECTOR(osgViewer::Scene)
I_SimpleProperty(osgGA::EventQueue *, EventQueue,
__osgGA_EventQueue_P1__getEventQueue,
__void__setEventQueue__osgGA_EventQueue_P1);
I_SimpleProperty(osg::FrameStamp *, FrameStamp,
__osg_FrameStamp_P1__getFrameStamp,
0);
I_SimpleProperty(osg::Node *, SceneData,
__osg_Node_P1__getSceneData,
__void__setSceneData__osg_Node_P1);

View File

@@ -11,6 +11,7 @@
#include <osgIntrospection/Attributes>
#include <osg/Node>
#include <osgGA/EventQueue>
#include <osgGA/GUIEventHandler>
#include <osgGA/MatrixManipulator>
#include <osgViewer/View>
@@ -42,6 +43,18 @@ BEGIN_OBJECT_REFLECTOR(osgViewer::View)
__C5_osg_Node_P1__getSceneData,
"",
"");
I_Method1(void, setEventQueue, IN, osgGA::EventQueue *, eventQueue,
__void__setEventQueue__osgGA_EventQueue_P1,
"",
"");
I_Method0(osgGA::EventQueue *, getEventQueue,
__osgGA_EventQueue_P1__getEventQueue,
"",
"");
I_Method0(const osgGA::EventQueue *, getEventQueue,
__C5_osgGA_EventQueue_P1__getEventQueue,
"",
"");
I_Method1(void, setCameraManipulator, IN, osgGA::MatrixManipulator *, manipulator,
__void__setCameraManipulator__osgGA_MatrixManipulator_P1,
"",
@@ -84,6 +97,9 @@ BEGIN_OBJECT_REFLECTOR(osgViewer::View)
I_SimpleProperty(osgViewer::View::EventHandlers &, EventHandlers,
__EventHandlers_R1__getEventHandlers,
0);
I_SimpleProperty(osgGA::EventQueue *, EventQueue,
__osgGA_EventQueue_P1__getEventQueue,
__void__setEventQueue__osgGA_EventQueue_P1);
I_SimpleProperty(osg::Node *, SceneData,
__osg_Node_P1__getSceneData,
__void__setSceneData__osg_Node_P1);

View File

@@ -65,5 +65,6 @@ BEGIN_OBJECT_REFLECTOR(osgViewer::Viewer)
__void__init,
"",
"");
I_PublicMemberProperty(bool, _firstFrame);
END_REFLECTOR