Added a render order sort to the list of Cameras being tested by the *Viewer::generatePointerData(..) method to ensure that the highest Camera gets focus.

git-svn-id: http://svn.openscenegraph.org/osg/OpenSceneGraph/trunk@14309 16af8721-9629-0410-8352-f15c8da7e697
This commit is contained in:
Robert Osfield 2014-06-27 15:30:56 +00:00
parent d994e84288
commit 8d6bee6da9
4 changed files with 60 additions and 33 deletions

View File

@ -680,6 +680,19 @@ class OSG_EXPORT Camera : public Transform, public CullSettings
ref_ptr<DrawCallback> _finalDrawCallback;
};
/** Functor to assist with ordering camers in the order they should be rendered in.*/
struct CameraRenderOrderSortOp
{
inline bool operator() (const Camera* lhs,const Camera* rhs) const
{
if (lhs->getRenderOrder()<rhs->getRenderOrder()) return true;
if (rhs->getRenderOrder()<lhs->getRenderOrder()) return false;
return lhs->getRenderOrderNum()<rhs->getRenderOrderNum();
}
};
}
#endif

View File

@ -754,18 +754,6 @@ void GraphicsContext::removeAllOperations()
_operationsBlock->set(false);
}
struct CameraRenderOrderSortOp
{
inline bool operator() (const Camera* lhs,const Camera* rhs) const
{
if (lhs->getRenderOrder()<rhs->getRenderOrder()) return true;
if (rhs->getRenderOrder()<lhs->getRenderOrder()) return false;
return lhs->getRenderOrderNum()<rhs->getRenderOrderNum();
}
};
void GraphicsContext::runOperations()
{
// sort the cameras into order

View File

@ -837,7 +837,6 @@ void CompositeViewer::generateSlavePointerData(osg::Camera* camera, osgGA::GUIEv
}
}
void CompositeViewer::generatePointerData(osgGA::GUIEventAdapter& event)
{
osgViewer::GraphicsWindow* gw = dynamic_cast<osgViewer::GraphicsWindow*>(event.getGraphicsContext());
@ -852,6 +851,9 @@ void CompositeViewer::generatePointerData(osgGA::GUIEventAdapter& event)
event.addPointerData(new osgGA::PointerData(gw, x, 0, gw->getTraits()->width,
y, 0, gw->getTraits()->height));
typedef std::vector<osg::Camera*> CameraVector;
CameraVector activeCameras;
osg::GraphicsContext::Cameras& cameras = gw->getCameras();
for(osg::GraphicsContext::Cameras::iterator citr = cameras.begin();
citr != cameras.end();
@ -866,6 +868,19 @@ void CompositeViewer::generatePointerData(osgGA::GUIEventAdapter& event)
x >= viewport->x() && y >= viewport->y() &&
x <= (viewport->x()+viewport->width()) && y <= (viewport->y()+viewport->height()) )
{
activeCameras.push_back(camera);
}
}
}
std::sort(activeCameras.begin(), activeCameras.end(), osg::CameraRenderOrderSortOp());
osg::Camera* camera = activeCameras.empty() ? 0 : activeCameras.back();
if (camera)
{
osg::Viewport* viewport = camera ? camera->getViewport() : 0;
event.addPointerData(new osgGA::PointerData(camera, (x-viewport->x())/viewport->width()*2.0f-1.0f, -1.0, 1.0,
(y-viewport->y())/viewport->height()*2.0f-1.0f, -1.0, 1.0));
@ -879,8 +894,6 @@ void CompositeViewer::generatePointerData(osgGA::GUIEventAdapter& event)
}
}
}
}
}
void CompositeViewer::reprojectPointerData(osgGA::GUIEventAdapter& source_event, osgGA::GUIEventAdapter& dest_event)
{

View File

@ -784,7 +784,9 @@ void Viewer::generatePointerData(osgGA::GUIEventAdapter& event)
event.addPointerData(new osgGA::PointerData(gw, x, 0, gw->getTraits()->width,
y, 0, gw->getTraits()->height));
// new code for populating the PointerData
typedef std::vector<osg::Camera*> CameraVector;
CameraVector activeCameras;
osgViewer::View* this_view = dynamic_cast<osgViewer::View*>(this);
osg::GraphicsContext::Cameras& cameras = gw->getCameras();
for(osg::GraphicsContext::Cameras::iterator citr = cameras.begin();
@ -801,6 +803,19 @@ void Viewer::generatePointerData(osgGA::GUIEventAdapter& event)
x >= viewport->x() && y >= viewport->y() &&
x <= (viewport->x()+viewport->width()) && y <= (viewport->y()+viewport->height()) )
{
activeCameras.push_back(camera);
}
}
}
std::sort(activeCameras.begin(), activeCameras.end(), osg::CameraRenderOrderSortOp());
osg::Camera* camera = activeCameras.empty() ? 0 : activeCameras.back();
if (camera)
{
osg::Viewport* viewport = camera ? camera->getViewport() : 0;
event.addPointerData(new osgGA::PointerData(camera, (x-viewport->x())/viewport->width()*2.0f-1.0f, -1.0, 1.0,
(y-viewport->y())/viewport->height()*2.0f-1.0f, -1.0, 1.0));
@ -811,8 +826,6 @@ void Viewer::generatePointerData(osgGA::GUIEventAdapter& event)
}
}
}
}
}
void Viewer::reprojectPointerData(osgGA::GUIEventAdapter& source_event, osgGA::GUIEventAdapter& dest_event)
{