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.