Added ability to discount Camera's that arn't appropriate for event focus

This commit is contained in:
Robert Osfield 2007-02-21 19:41:53 +00:00
parent 9a1ce56ce5
commit 987fe5d93b
2 changed files with 32 additions and 7 deletions

View File

@ -340,7 +340,7 @@ 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; // osg::notify(osg::NOTICE)<<"View::getCameraContainingPosition("<<x<<","<<y<<",..,..) view_invert_y="<<view_invert_y<<std::endl;
double epsilon = 0.5; double epsilon = 0.5;
@ -360,6 +360,8 @@ const osg::Camera* View::getCameraContainingPosition(float x, float y, float& lo
local_x = new_x; local_x = new_x;
local_y = new_y; local_y = new_y;
osg::notify(osg::NOTICE)<<"Returning master camera"<<std::endl;
return _camera.get(); return _camera.get();
} }
} }
@ -371,11 +373,15 @@ const osg::Camera* View::getCameraContainingPosition(float x, float y, float& lo
if (view_invert_y) y = - y; if (view_invert_y) y = - y;
for(unsigned i=0; i<getNumSlaves(); ++i) for(int i=getNumSlaves()-1; i>=0; --i)
{ {
const Slave& slave = getSlave(i); const Slave& slave = getSlave(i);
if (slave._camera.valid()) if (slave._camera.valid() &&
slave._camera->getAllowEventFocus() &&
slave._camera->getRenderTargetImplementation()==osg::Camera::FRAME_BUFFER)
{ {
osg::notify(osg::NOTICE)<<"Testing slave camera "<<slave._camera->getName()<<std::endl;
const osg::Camera* camera = slave._camera.get(); const osg::Camera* camera = slave._camera.get();
const osg::Viewport* viewport = camera ? camera->getViewport() : 0; const osg::Viewport* viewport = camera ? camera->getViewport() : 0;
@ -386,13 +392,15 @@ const osg::Camera* View::getCameraContainingPosition(float x, float y, float& lo
osg::Vec3d new_coord = osg::Vec3d(x,y,0.0) * matrix; osg::Vec3d new_coord = osg::Vec3d(x,y,0.0) * matrix;
// osg::notify(osg::NOTICE)<<" new_coord "<<new_coord<<std::endl;; osg::notify(osg::NOTICE)<<" x="<<x<<" y="<<y<<std::endl;;
osg::notify(osg::NOTICE)<<" eventState->getXmin()="<<eventState->getXmin()<<" eventState->getXmax()="<<eventState->getXmax()<<std::endl;;
osg::notify(osg::NOTICE)<<" new_coord "<<new_coord<<std::endl;;
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) )
{ {
// osg::notify(osg::NOTICE)<<" in viewport "<<std::endl;; osg::notify(osg::NOTICE)<<" in viewport "<<std::endl;;
local_x = new_coord.x(); local_x = new_coord.x();
local_y = new_coord.y(); local_y = new_coord.y();
@ -401,7 +409,7 @@ const osg::Camera* View::getCameraContainingPosition(float x, float y, float& lo
} }
else else
{ {
// osg::notify(osg::NOTICE)<<" not in viewport "<<viewport->x()<<" "<<(viewport->x()+viewport->width())<<std::endl;; osg::notify(osg::NOTICE)<<" not in viewport "<<viewport->x()<<" "<<(viewport->x()+viewport->width())<<std::endl;;
} }
} }

View File

@ -1764,13 +1764,16 @@ void Viewer::eventTraversal()
++citr) ++citr)
{ {
osg::Camera* camera = *citr; osg::Camera* camera = *citr;
if (camera->getView()==this) if (camera->getView()==this &&
camera->getAllowEventFocus() &&
camera->getRenderTargetImplementation()==osg::Camera::FRAME_BUFFER)
{ {
osg::Viewport* viewport = camera ? camera->getViewport() : 0; osg::Viewport* viewport = camera ? camera->getViewport() : 0;
if (viewport && if (viewport &&
x >= viewport->x() && y >= viewport->y() && x >= viewport->x() && y >= viewport->y() &&
x <= (viewport->x()+viewport->width()) && y <= (viewport->y()+viewport->height()) ) x <= (viewport->x()+viewport->width()) && y <= (viewport->y()+viewport->height()) )
{ {
// osg::notify(osg::NOTICE)<<"setCamera with focus "<<camera->getName()<<" x="<<x<<" y="<<y<<std::endl;
setCameraWithFocus(camera); setCameraWithFocus(camera);
} }
} }
@ -1798,12 +1801,26 @@ void Viewer::eventTraversal()
x = new_coord.x(); x = new_coord.x();
y = new_coord.y(); y = new_coord.y();
// osg::notify(osg::NOTICE)<<"pointer event new_coord.x()="<<new_coord.x()<<" new_coord.y()="<<new_coord.y()<<std::endl;
event->setInputRange(eventState->getXmin(), eventState->getYmin(), eventState->getXmax(), eventState->getYmax()); event->setInputRange(eventState->getXmin(), eventState->getYmin(), eventState->getXmax(), eventState->getYmax());
event->setX(x); event->setX(x);
event->setY(y); event->setY(y);
event->setMouseYOrientation(osgGA::GUIEventAdapter::Y_INCREASING_UPWARDS); event->setMouseYOrientation(osgGA::GUIEventAdapter::Y_INCREASING_UPWARDS);
} }
else
{
x = eventState->getXmin() + (x/double(gw->getTraits()->width))*(eventState->getXmax() - eventState->getXmin());
y = eventState->getYmin() + (y/double(gw->getTraits()->height))*(eventState->getYmax() - eventState->getYmin());
// osg::notify(osg::NOTICE)<<"new x = "<<x<<" new y = "<<y<<std::endl;
event->setInputRange(eventState->getXmin(), eventState->getYmin(), eventState->getXmax(), eventState->getYmax());
event->setX(x);
event->setY(y);
event->setMouseYOrientation(osgGA::GUIEventAdapter::Y_INCREASING_UPWARDS);
}
// pass along the new pointer events details to the eventState of the viewer // pass along the new pointer events details to the eventState of the viewer
eventState->setX(x); eventState->setX(x);
eventState->setY(y); eventState->setY(y);