Further work on CompositeViewer

This commit is contained in:
Robert Osfield 2007-01-16 16:01:01 +00:00
parent 0b40a6fc82
commit 1ee2af9f41
6 changed files with 30 additions and 28 deletions

View File

@ -3,6 +3,7 @@
#include <osgDB/ReadFile> #include <osgDB/ReadFile>
#include <osgViewer/Viewer> #include <osgViewer/Viewer>
#include <osgGA/TrackballManipulator> #include <osgGA/TrackballManipulator>
#include <osgGA/FlightManipulator>
#include <osgGA/AnimationPathManipulator> #include <osgGA/AnimationPathManipulator>
#include <iostream> #include <iostream>
@ -251,9 +252,15 @@ int main( int argc, char **argv )
while (arguments.read("-1")) { singleWindowMultipleCameras(viewer); } while (arguments.read("-1")) { singleWindowMultipleCameras(viewer); }
while (arguments.read("-2")) { multipleWindowMultipleCameras(viewer); } while (arguments.read("-2")) { multipleWindowMultipleCameras(viewer); }
#if 0
if (apm.valid()) viewer.setCameraManipulator(apm.get()); if (apm.valid()) viewer.setCameraManipulator(apm.get());
else viewer.setCameraManipulator( new osgGA::TrackballManipulator() ); else viewer.setCameraManipulator( new osgGA::TrackballManipulator() );
#else
viewer.setCameraManipulator( new osgGA::FlightManipulator() );
#endif
#if 0 #if 0

View File

@ -98,9 +98,11 @@ class OSGVIEWER_EXPORT View : public osg::View, public osgGA::GUIActionAdapter
public: public:
void assignSceneDataToCameras(); void assignSceneDataToCameras();
void init();
protected: protected:
virtual ~View(); virtual ~View();
osg::ref_ptr<osgViewer::Scene> _scene; osg::ref_ptr<osgViewer::Scene> _scene;

View File

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

View File

@ -44,7 +44,7 @@ CompositeViewer::CompositeViewer():
CompositeViewer::~CompositeViewer() CompositeViewer::~CompositeViewer()
{ {
osg::notify(osg::NOTICE)<<"CompositeViewer::~CompositeViewer()"<<std::endl; osg::notify(osg::INFO)<<"CompositeViewer::~CompositeViewer()"<<std::endl;
stopThreading(); stopThreading();
@ -74,7 +74,7 @@ CompositeViewer::~CompositeViewer()
(*citr)->close(); (*citr)->close();
} }
osg::notify(osg::NOTICE)<<"finish CompositeViewer::~CompsiteViewer()"<<std::endl; osg::notify(osg::INFO)<<"finished CompositeViewer::~CompsiteViewer()"<<std::endl;
} }
@ -415,7 +415,7 @@ void CompositeViewer::init()
itr != _views.end(); itr != _views.end();
++itr) ++itr)
{ {
// (*itr)->init(); (*itr)->init();
} }
} }

View File

@ -35,6 +35,19 @@ View::~View()
// osg::notify(osg::NOTICE)<<"Destructing osgViewer::View"<<std::endl; // osg::notify(osg::NOTICE)<<"Destructing osgViewer::View"<<std::endl;
} }
void View::init()
{
osg::notify(osg::INFO)<<"View::init()"<<std::endl;
osg::ref_ptr<osgGA::GUIEventAdapter> initEvent = _eventQueue->createEvent();
initEvent->setEventType(osgGA::GUIEventAdapter::FRAME);
if (_cameraManipulator.valid())
{
_cameraManipulator->init(*initEvent, *this);
}
}
void View::setSceneData(osg::Node* node) void View::setSceneData(osg::Node* node)
{ {
_scene = new osgViewer::Scene; _scene = new osgViewer::Scene;
@ -312,8 +325,7 @@ void View::requestContinuousUpdate(bool)
void View::requestWarpPointer(float x,float y) void View::requestWarpPointer(float x,float y)
{ {
osg::notify(osg::NOTICE)<<"View::requestWarpPointer("<<x<<","<<y<<")"<<std::endl; osg::notify(osg::INFO)<<"View::requestWarpPointer("<<x<<","<<y<<")"<<std::endl;
float local_x, local_y; float local_x, local_y;
const osg::Camera* camera = getCameraContainingPosition(x, y, local_x, local_y); const osg::Camera* camera = getCameraContainingPosition(x, y, local_x, local_y);
@ -333,7 +345,7 @@ void View::requestWarpPointer(float x,float y)
} }
else else
{ {
osg::notify(osg::NOTICE)<<"View::requestWarpPointer failed no camera containing pointer"<<std::endl; osg::notify(osg::INFO)<<"View::requestWarpPointer failed no camera containing pointer"<<std::endl;
} }
} }
@ -353,6 +365,8 @@ const osg::Camera* View::getCameraContainingPosition(float x, float y, float& lo
{ {
const osgGA::GUIEventAdapter* eventState = getEventQueue()->getCurrentEventState(); const osgGA::GUIEventAdapter* eventState = getEventQueue()->getCurrentEventState();
bool view_invert_y = eventState->getMouseYOrientation()==osgGA::GUIEventAdapter::Y_INCREASING_DOWNWARDS; bool view_invert_y = eventState->getMouseYOrientation()==osgGA::GUIEventAdapter::Y_INCREASING_DOWNWARDS;
osg::notify(osg::INFO)<<"View::getCameraContainingPosition("<<x<<","<<y<<",..,..) view_invert_y="<<view_invert_y<<std::endl;
double epsilon = 0.5; double epsilon = 0.5;
@ -362,12 +376,6 @@ const osg::Camera* View::getCameraContainingPosition(float x, float y, float& lo
osg::Vec2d new_coord(x, y); osg::Vec2d new_coord(x, y);
osgViewer::GraphicsWindow* gw = dynamic_cast<osgViewer::GraphicsWindow*>(_camera->getGraphicsContext());
if (gw && gw->getEventQueue()->getCurrentEventState()->getMouseYOrientation()==osgGA::GUIEventAdapter::Y_INCREASING_DOWNWARDS)
{
new_coord.y() = gw->getTraits()->height - new_coord.y();
}
if (viewport && if (viewport &&
new_coord.x() >= (viewport->x()-epsilon) && new_coord.y() >= (viewport->y()-epsilon) && new_coord.x() >= (viewport->x()-epsilon) && new_coord.y() >= (viewport->y()-epsilon) &&
new_coord.x() < (viewport->x()+viewport->width()-1.0+epsilon) && new_coord.y() <= (viewport->y()+viewport->height()-1.0+epsilon) ) new_coord.x() < (viewport->x()+viewport->width()-1.0+epsilon) && new_coord.y() <= (viewport->y()+viewport->height()-1.0+epsilon) )

View File

@ -392,20 +392,6 @@ void Viewer::checkWindowStatus()
} }
void Viewer::init()
{
osg::notify(osg::INFO)<<"Viewer::init()"<<std::endl;
osg::ref_ptr<osgGA::GUIEventAdapter> initEvent = _eventQueue->createEvent();
initEvent->setEventType(osgGA::GUIEventAdapter::FRAME);
if (_cameraManipulator.valid())
{
_cameraManipulator->init(*initEvent, *this);
}
}
void Viewer::getContexts(Contexts& contexts, bool onlyValid) void Viewer::getContexts(Contexts& contexts, bool onlyValid)
{ {
typedef std::set<osg::GraphicsContext*> ContextSet; typedef std::set<osg::GraphicsContext*> ContextSet;