2006-11-27 22:52:07 +08:00
|
|
|
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
|
|
|
|
*
|
|
|
|
* This library is open source and may be redistributed and/or modified under
|
|
|
|
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
|
|
|
|
* (at your option) any later version. The full license is in LICENSE file
|
|
|
|
* included with this distribution, and on the openscenegraph.org website.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* OpenSceneGraph Public License for more details.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <osgViewer/View>
|
2006-12-20 00:00:51 +08:00
|
|
|
#include <osgViewer/GraphicsWindow>
|
|
|
|
|
2007-01-02 02:20:10 +08:00
|
|
|
#include <osg/io_utils>
|
2006-11-27 22:52:07 +08:00
|
|
|
|
2007-01-10 01:35:46 +08:00
|
|
|
#include <osgUtil/IntersectionVisitor>
|
|
|
|
|
2006-11-27 22:52:07 +08:00
|
|
|
using namespace osgViewer;
|
|
|
|
|
|
|
|
View::View()
|
|
|
|
{
|
2006-12-20 00:00:51 +08:00
|
|
|
// osg::notify(osg::NOTICE)<<"Constructing osgViewer::View"<<std::endl;
|
2007-01-05 00:49:58 +08:00
|
|
|
|
|
|
|
// make sure View is safe to reference multi-threaded.
|
|
|
|
setThreadSafeRefUnref(true);
|
|
|
|
|
|
|
|
setEventQueue(new osgGA::EventQueue);
|
2006-11-27 22:52:07 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
View::~View()
|
|
|
|
{
|
2006-12-20 00:00:51 +08:00
|
|
|
// osg::notify(osg::NOTICE)<<"Destructing osgViewer::View"<<std::endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
void View::setSceneData(osg::Node* node)
|
|
|
|
{
|
|
|
|
_scene = new osgViewer::Scene;
|
|
|
|
_scene->setSceneData(node);
|
|
|
|
|
|
|
|
assignSceneDataToCameras();
|
|
|
|
}
|
|
|
|
|
2006-12-21 05:13:29 +08:00
|
|
|
void View::setCameraManipulator(osgGA::MatrixManipulator* manipulator)
|
|
|
|
{
|
|
|
|
_cameraManipulator = manipulator;
|
|
|
|
if (_cameraManipulator.valid() && getSceneData())
|
|
|
|
{
|
|
|
|
_cameraManipulator->setNode(getSceneData());
|
|
|
|
|
|
|
|
osg::ref_ptr<osgGA::GUIEventAdapter> dummyEvent = _eventQueue->createEvent();
|
|
|
|
|
2007-01-02 02:20:10 +08:00
|
|
|
_cameraManipulator->home(*dummyEvent, *this);
|
2006-12-21 05:13:29 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-12-27 01:38:47 +08:00
|
|
|
void View::addEventHandler(osgGA::GUIEventHandler* eventHandler)
|
|
|
|
{
|
|
|
|
_eventHandlers.push_back(eventHandler);
|
|
|
|
}
|
|
|
|
|
2006-12-20 00:00:51 +08:00
|
|
|
void View::setUpViewAcrossAllScreens()
|
|
|
|
{
|
2006-12-21 17:01:56 +08:00
|
|
|
osg::GraphicsContext::WindowingSystemInterface* wsi = osg::GraphicsContext::getWindowingSystemInterface();
|
2006-12-20 00:00:51 +08:00
|
|
|
if (!wsi)
|
|
|
|
{
|
|
|
|
osg::notify(osg::NOTICE)<<"View::setUpViewAcrossAllScreens() : Error, no WindowSystemInterface available, cannot create windows."<<std::endl;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2007-01-11 20:06:24 +08:00
|
|
|
osg::DisplaySettings* ds = _displaySettings.valid() ? _displaySettings.get() : osg::DisplaySettings::instance();
|
|
|
|
|
2006-12-20 00:00:51 +08:00
|
|
|
double fovy, aspectRatio, zNear, zFar;
|
|
|
|
_camera->getProjectionMatrixAsPerspective(fovy, aspectRatio, zNear, zFar);
|
|
|
|
|
|
|
|
double fovx = atan(tan(osg::DegreesToRadians(fovy*0.5)) * aspectRatio) * 2.0;
|
|
|
|
|
|
|
|
unsigned int numScreens = wsi->getNumScreens();
|
|
|
|
if (numScreens==1)
|
|
|
|
{
|
|
|
|
unsigned int width, height;
|
|
|
|
wsi->getScreenResolution(osg::GraphicsContext::ScreenIdentifier(0), width, height);
|
|
|
|
|
|
|
|
osg::ref_ptr<osg::GraphicsContext::Traits> traits = new osg::GraphicsContext::Traits;
|
2006-12-23 05:53:44 +08:00
|
|
|
traits->x = 0;
|
|
|
|
traits->y = 0;
|
|
|
|
traits->width = width;
|
|
|
|
traits->height = height;
|
2007-01-11 20:06:24 +08:00
|
|
|
traits->alpha = ds->getMinimumNumAlphaBits();
|
|
|
|
traits->stencil = ds->getMinimumNumStencilBits();
|
2006-12-23 05:53:44 +08:00
|
|
|
traits->windowDecoration = false;
|
|
|
|
traits->doubleBuffer = true;
|
|
|
|
traits->sharedContext = 0;
|
2006-12-20 00:00:51 +08:00
|
|
|
|
|
|
|
osg::ref_ptr<osg::GraphicsContext> gc = osg::GraphicsContext::createGraphicsContext(traits.get());
|
|
|
|
|
|
|
|
_camera->setGraphicsContext(gc.get());
|
|
|
|
|
|
|
|
osgViewer::GraphicsWindow* gw = dynamic_cast<osgViewer::GraphicsWindow*>(gc.get());
|
|
|
|
if (gw)
|
|
|
|
{
|
2006-12-22 00:56:20 +08:00
|
|
|
osg::notify(osg::INFO)<<" GraphicsWindow has been created successfully."<<std::endl;
|
2006-12-28 04:23:34 +08:00
|
|
|
gw->getEventQueue()->getCurrentEventState()->setWindowRectangle(0, 0, width, height );
|
2006-12-20 00:00:51 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
osg::notify(osg::NOTICE)<<" GraphicsWindow has not been created successfully."<<std::endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
_camera->setViewport(new osg::Viewport(0, 0, width, height));
|
2007-01-02 02:20:10 +08:00
|
|
|
|
|
|
|
GLenum buffer = traits->doubleBuffer ? GL_BACK : GL_FRONT;
|
|
|
|
|
|
|
|
_camera->setDrawBuffer(buffer);
|
|
|
|
_camera->setReadBuffer(buffer);
|
|
|
|
|
2006-12-20 00:00:51 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-01-02 20:03:48 +08:00
|
|
|
|
|
|
|
bool cylindericalScreen = false;
|
|
|
|
|
|
|
|
if (cylindericalScreen)
|
2006-12-20 00:00:51 +08:00
|
|
|
{
|
2007-01-02 20:03:48 +08:00
|
|
|
double rotate_x = - double(numScreens-1) * 0.5 * fovx;
|
2006-12-20 00:00:51 +08:00
|
|
|
|
2007-01-02 20:03:48 +08:00
|
|
|
for(unsigned int i=0; i<numScreens; ++i, rotate_x += fovx)
|
2006-12-20 00:00:51 +08:00
|
|
|
{
|
2007-01-02 20:03:48 +08:00
|
|
|
unsigned int width, height;
|
|
|
|
wsi->getScreenResolution(osg::GraphicsContext::ScreenIdentifier(i), width, height);
|
|
|
|
|
|
|
|
osg::ref_ptr<osg::GraphicsContext::Traits> traits = new osg::GraphicsContext::Traits;
|
|
|
|
traits->screenNum = i;
|
|
|
|
traits->x = 0;
|
|
|
|
traits->y = 0;
|
|
|
|
traits->width = width;
|
|
|
|
traits->height = height;
|
2007-01-11 20:06:24 +08:00
|
|
|
traits->alpha = ds->getMinimumNumAlphaBits();
|
|
|
|
traits->stencil = ds->getMinimumNumStencilBits();
|
2007-01-02 20:03:48 +08:00
|
|
|
traits->windowDecoration = false;
|
|
|
|
traits->doubleBuffer = true;
|
|
|
|
traits->sharedContext = 0;
|
|
|
|
|
|
|
|
osg::ref_ptr<osg::GraphicsContext> gc = osg::GraphicsContext::createGraphicsContext(traits.get());
|
|
|
|
|
|
|
|
osg::ref_ptr<osg::Camera> camera = new osg::Camera;
|
|
|
|
camera->setGraphicsContext(gc.get());
|
|
|
|
|
|
|
|
osgViewer::GraphicsWindow* gw = dynamic_cast<osgViewer::GraphicsWindow*>(gc.get());
|
|
|
|
if (gw)
|
|
|
|
{
|
|
|
|
osg::notify(osg::INFO)<<" GraphicsWindow has been created successfully."<<gw<<std::endl;
|
|
|
|
|
2007-01-03 01:39:31 +08:00
|
|
|
gw->getEventQueue()->getCurrentEventState()->setWindowRectangle(traits->x, traits->y, traits->width, traits->height );
|
2007-01-02 20:03:48 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
osg::notify(osg::NOTICE)<<" GraphicsWindow has not been created successfully."<<std::endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
camera->setViewport(new osg::Viewport(0, 0, width, height));
|
|
|
|
|
|
|
|
GLenum buffer = traits->doubleBuffer ? GL_BACK : GL_FRONT;
|
|
|
|
camera->setDrawBuffer(buffer);
|
|
|
|
camera->setReadBuffer(buffer);
|
|
|
|
|
|
|
|
addSlave(camera.get(), osg::Matrixd(), osg::Matrixd::rotate( rotate_x, 0.0, 1.0, 0.0));
|
|
|
|
|
2006-12-20 00:00:51 +08:00
|
|
|
}
|
2007-01-02 20:03:48 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
double translate_x = double(numScreens) - 1.0;
|
|
|
|
|
|
|
|
for(unsigned int i=0; i<numScreens; ++i, translate_x -= 2.0)
|
2006-12-20 00:00:51 +08:00
|
|
|
{
|
2007-01-02 20:03:48 +08:00
|
|
|
unsigned int width, height;
|
|
|
|
wsi->getScreenResolution(osg::GraphicsContext::ScreenIdentifier(i), width, height);
|
2007-01-02 02:20:10 +08:00
|
|
|
|
2007-01-02 20:03:48 +08:00
|
|
|
osg::ref_ptr<osg::GraphicsContext::Traits> traits = new osg::GraphicsContext::Traits;
|
|
|
|
traits->screenNum = i;
|
|
|
|
traits->x = 0;
|
|
|
|
traits->y = 0;
|
|
|
|
traits->width = width;
|
|
|
|
traits->height = height;
|
2007-01-11 20:06:24 +08:00
|
|
|
traits->alpha = ds->getMinimumNumAlphaBits();
|
|
|
|
traits->stencil = ds->getMinimumNumStencilBits();
|
2007-01-02 20:03:48 +08:00
|
|
|
traits->windowDecoration = false;
|
|
|
|
traits->doubleBuffer = true;
|
|
|
|
traits->sharedContext = 0;
|
|
|
|
|
|
|
|
osg::ref_ptr<osg::GraphicsContext> gc = osg::GraphicsContext::createGraphicsContext(traits.get());
|
|
|
|
|
|
|
|
osg::ref_ptr<osg::Camera> camera = new osg::Camera;
|
|
|
|
camera->setGraphicsContext(gc.get());
|
|
|
|
|
|
|
|
osgViewer::GraphicsWindow* gw = dynamic_cast<osgViewer::GraphicsWindow*>(gc.get());
|
|
|
|
if (gw)
|
|
|
|
{
|
|
|
|
osg::notify(osg::INFO)<<" GraphicsWindow has been created successfully."<<gw<<std::endl;
|
|
|
|
|
2007-01-03 01:39:31 +08:00
|
|
|
gw->getEventQueue()->getCurrentEventState()->setWindowRectangle(traits->x, traits->y, traits->width, traits->height );
|
2007-01-02 20:03:48 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
osg::notify(osg::NOTICE)<<" GraphicsWindow has not been created successfully."<<std::endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
camera->setViewport(new osg::Viewport(0, 0, width, height));
|
|
|
|
|
|
|
|
GLenum buffer = traits->doubleBuffer ? GL_BACK : GL_FRONT;
|
|
|
|
camera->setDrawBuffer(buffer);
|
|
|
|
camera->setReadBuffer(buffer);
|
|
|
|
|
|
|
|
addSlave(camera.get(), osg::Matrixd::translate( translate_x, 0.0, 0.0), osg::Matrixd() );
|
|
|
|
|
|
|
|
}
|
2006-12-20 00:00:51 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-01-05 05:49:02 +08:00
|
|
|
assignSceneDataToCameras();
|
2006-12-20 00:00:51 +08:00
|
|
|
}
|
|
|
|
|
2007-01-07 05:06:35 +08:00
|
|
|
void View::setUpViewOnSingleScreen(unsigned int screenNum)
|
|
|
|
{
|
|
|
|
osg::GraphicsContext::WindowingSystemInterface* wsi = osg::GraphicsContext::getWindowingSystemInterface();
|
|
|
|
if (!wsi)
|
|
|
|
{
|
2007-01-10 01:35:46 +08:00
|
|
|
osg::notify(osg::NOTICE)<<"View::setUpViewOnSingleScreen() : Error, no WindowSystemInterface available, cannot create windows."<<std::endl;
|
2007-01-07 05:06:35 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2007-01-11 20:06:24 +08:00
|
|
|
osg::DisplaySettings* ds = _displaySettings.valid() ? _displaySettings.get() : osg::DisplaySettings::instance();
|
|
|
|
|
2007-01-07 05:06:35 +08:00
|
|
|
unsigned int width, height;
|
|
|
|
wsi->getScreenResolution(osg::GraphicsContext::ScreenIdentifier(screenNum), width, height);
|
|
|
|
|
|
|
|
osg::ref_ptr<osg::GraphicsContext::Traits> traits = new osg::GraphicsContext::Traits;
|
|
|
|
traits->x = 0;
|
|
|
|
traits->y = 0;
|
|
|
|
traits->width = width;
|
|
|
|
traits->height = height;
|
2007-01-11 20:06:24 +08:00
|
|
|
traits->alpha = ds->getMinimumNumAlphaBits();
|
|
|
|
traits->stencil = ds->getMinimumNumStencilBits();
|
2007-01-07 05:06:35 +08:00
|
|
|
traits->windowDecoration = false;
|
|
|
|
traits->doubleBuffer = true;
|
|
|
|
traits->sharedContext = 0;
|
|
|
|
|
|
|
|
osg::ref_ptr<osg::GraphicsContext> gc = osg::GraphicsContext::createGraphicsContext(traits.get());
|
|
|
|
|
|
|
|
_camera->setGraphicsContext(gc.get());
|
|
|
|
|
|
|
|
osgViewer::GraphicsWindow* gw = dynamic_cast<osgViewer::GraphicsWindow*>(gc.get());
|
|
|
|
if (gw)
|
|
|
|
{
|
2007-01-10 01:35:46 +08:00
|
|
|
osg::notify(osg::INFO)<<"View::setUpViewOnSingleScreen - GraphicsWindow has been created successfully."<<std::endl;
|
2007-01-07 05:06:35 +08:00
|
|
|
gw->getEventQueue()->getCurrentEventState()->setWindowRectangle(0, 0, width, height );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
osg::notify(osg::NOTICE)<<" GraphicsWindow has not been created successfully."<<std::endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
_camera->setViewport(new osg::Viewport(0, 0, width, height));
|
|
|
|
|
|
|
|
GLenum buffer = traits->doubleBuffer ? GL_BACK : GL_FRONT;
|
|
|
|
|
|
|
|
_camera->setDrawBuffer(buffer);
|
|
|
|
_camera->setReadBuffer(buffer);
|
|
|
|
}
|
|
|
|
|
2006-12-20 00:00:51 +08:00
|
|
|
void View::assignSceneDataToCameras()
|
|
|
|
{
|
|
|
|
osg::Node* sceneData = _scene.valid() ? _scene->getSceneData() : 0;
|
|
|
|
|
2006-12-21 05:13:29 +08:00
|
|
|
if (_cameraManipulator.valid())
|
|
|
|
{
|
|
|
|
_cameraManipulator->setNode(sceneData);
|
|
|
|
|
|
|
|
osg::ref_ptr<osgGA::GUIEventAdapter> dummyEvent = _eventQueue->createEvent();
|
|
|
|
|
2007-01-02 02:20:10 +08:00
|
|
|
_cameraManipulator->home(*dummyEvent, *this);
|
2006-12-21 05:13:29 +08:00
|
|
|
}
|
|
|
|
|
2006-12-20 00:00:51 +08:00
|
|
|
if (_camera.valid())
|
|
|
|
{
|
|
|
|
_camera->removeChildren(0,_camera->getNumChildren());
|
|
|
|
if (sceneData) _camera->addChild(sceneData);
|
|
|
|
}
|
|
|
|
|
|
|
|
for(unsigned i=0; i<getNumSlaves(); ++i)
|
|
|
|
{
|
|
|
|
Slave& slave = getSlave(i);
|
|
|
|
if (slave._camera.valid())
|
|
|
|
{
|
|
|
|
slave._camera->removeChildren(0,slave._camera->getNumChildren());
|
|
|
|
if (sceneData) slave._camera->addChild(sceneData);
|
|
|
|
}
|
|
|
|
}
|
2006-11-27 22:52:07 +08:00
|
|
|
}
|
2007-01-02 02:20:10 +08:00
|
|
|
|
|
|
|
void View::requestRedraw()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void View::requestContinuousUpdate(bool)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void View::requestWarpPointer(float x,float y)
|
|
|
|
{
|
2007-01-02 20:03:48 +08:00
|
|
|
// osg::notify(osg::NOTICE)<<"View::requestWarpPointer("<<x<<","<<y<<")"<<std::endl;
|
|
|
|
|
2007-01-02 02:20:10 +08:00
|
|
|
osgGA::GUIEventAdapter* eventState = getEventQueue()->getCurrentEventState();
|
|
|
|
bool view_invert_y = eventState->getMouseYOrientation()==osgGA::GUIEventAdapter::Y_INCREASING_DOWNWARDS;
|
|
|
|
|
2007-01-02 04:01:45 +08:00
|
|
|
getEventQueue()->mouseWarped(x,y);
|
|
|
|
|
2007-01-02 02:20:10 +08:00
|
|
|
osgViewer::GraphicsWindow* gw = dynamic_cast<osgViewer::GraphicsWindow*>(_camera->getGraphicsContext());
|
|
|
|
if (gw)
|
|
|
|
{
|
|
|
|
bool gw_invert_y = gw->getEventQueue()->getCurrentEventState()->getMouseYOrientation()==osgGA::GUIEventAdapter::Y_INCREASING_DOWNWARDS;
|
|
|
|
|
|
|
|
x = x * float(gw->getTraits()->width) / (eventState->getXmax()-eventState->getXmin());
|
|
|
|
y = y * float(gw->getTraits()->height) / (eventState->getYmax()-eventState->getYmin());
|
|
|
|
|
|
|
|
if (view_invert_y != gw_invert_y) y = gw->getTraits()->height - y;
|
|
|
|
|
|
|
|
gw->requestWarpPointer(x, y);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
osg::Matrix masterCameraVPW = getCamera()->getViewMatrix() * getCamera()->getProjectionMatrix();
|
|
|
|
|
|
|
|
x = (x - eventState->getXmin()) * 2.0 / (eventState->getXmax()-eventState->getXmin()) - 1.0;
|
|
|
|
y = (y - eventState->getYmin())* 2.0 / (eventState->getYmax()-eventState->getYmin()) - 1.0;
|
|
|
|
|
|
|
|
if (view_invert_y) y = - y;
|
|
|
|
|
2007-01-02 20:03:48 +08:00
|
|
|
// osg::notify(osg::NOTICE)<<" remapped ("<<x<<","<<y<<")"<<std::endl;;
|
|
|
|
// osg::notify(osg::NOTICE)<<" number of slaves = "<<getNumSlaves()<<std::endl;;
|
|
|
|
|
|
|
|
double epsilon = 0.5;
|
|
|
|
|
2007-01-02 02:20:10 +08:00
|
|
|
for(unsigned i=0; i<getNumSlaves(); ++i)
|
|
|
|
{
|
|
|
|
Slave& slave = getSlave(i);
|
|
|
|
if (slave._camera.valid())
|
|
|
|
{
|
|
|
|
osg::Camera* camera = slave._camera.get();
|
|
|
|
osg::Viewport* viewport = camera ? camera->getViewport() : 0;
|
|
|
|
|
|
|
|
osg::Matrix localCameraVPW = camera->getViewMatrix() * camera->getProjectionMatrix();
|
|
|
|
if (viewport) localCameraVPW *= viewport->computeWindowMatrix();
|
|
|
|
|
|
|
|
osg::Matrix matrix( osg::Matrix::inverse(masterCameraVPW) * localCameraVPW );
|
|
|
|
|
|
|
|
osg::Vec3d new_coord = osg::Vec3d(x,y,0.0) * matrix;
|
|
|
|
|
2007-01-02 20:03:48 +08:00
|
|
|
// osg::notify(osg::NOTICE)<<" new_coord "<<new_coord<<std::endl;;
|
|
|
|
|
2007-01-02 02:20:10 +08:00
|
|
|
if (viewport &&
|
2007-01-02 20:03:48 +08:00
|
|
|
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) )
|
2007-01-02 02:20:10 +08:00
|
|
|
{
|
2007-01-02 20:03:48 +08:00
|
|
|
// osg::notify(osg::NOTICE)<<" in viewport "<<std::endl;;
|
|
|
|
|
2007-01-02 02:20:10 +08:00
|
|
|
gw = dynamic_cast<osgViewer::GraphicsWindow*>(camera->getGraphicsContext());
|
|
|
|
if (gw)
|
|
|
|
{
|
|
|
|
x = new_coord.x();
|
|
|
|
y = new_coord.y();
|
|
|
|
|
|
|
|
bool gw_invert_y = gw->getEventQueue()->getCurrentEventState()->getMouseYOrientation()==osgGA::GUIEventAdapter::Y_INCREASING_DOWNWARDS;
|
|
|
|
|
|
|
|
if (gw_invert_y) y = gw->getTraits()->height - y;
|
|
|
|
|
|
|
|
gw->requestWarpPointer(x, y);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2007-01-02 20:03:48 +08:00
|
|
|
else
|
|
|
|
{
|
|
|
|
// osg::notify(osg::NOTICE)<<" not in viewport "<<viewport->x()<<" "<<(viewport->x()+viewport->width())<<std::endl;;
|
|
|
|
}
|
2007-01-02 02:20:10 +08:00
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-01-02 20:03:48 +08:00
|
|
|
// osg::notify(osg::NOTICE)<<" ** no warping applied. **"<<std::endl;
|
2007-01-02 02:20:10 +08:00
|
|
|
|
|
|
|
|
|
|
|
}
|
2007-01-10 01:35:46 +08:00
|
|
|
|
|
|
|
bool View::computeIntersections(float x,float y, osgUtil::LineSegmentIntersector::Intersections& intersections,osg::Node::NodeMask traversalMask)
|
|
|
|
{
|
|
|
|
if (!_camera.valid()) return false;
|
|
|
|
|
|
|
|
osgUtil::LineSegmentIntersector::CoordinateFrame cf = _camera->getViewport() ? osgUtil::Intersector::WINDOW : osgUtil::Intersector::PROJECTION;
|
|
|
|
osgUtil::LineSegmentIntersector* picker = new osgUtil::LineSegmentIntersector(cf, x, y);
|
|
|
|
|
|
|
|
osgUtil::IntersectionVisitor iv(picker);
|
|
|
|
iv.setTraversalMask(traversalMask);
|
|
|
|
_camera->accept(iv);
|
|
|
|
|
|
|
|
if (picker->containsIntersections())
|
|
|
|
{
|
|
|
|
intersections = picker->getIntersections();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
intersections.clear();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-01-10 18:09:05 +08:00
|
|
|
bool View::computeIntersections(float x,float y, osg::NodePath& nodePath, osgUtil::LineSegmentIntersector::Intersections& intersections,osg::Node::NodeMask traversalMask)
|
2007-01-10 01:35:46 +08:00
|
|
|
{
|
|
|
|
if (!_camera.valid()) return false;
|
|
|
|
|
2007-01-10 18:09:05 +08:00
|
|
|
osg::Matrix matrix = osg::computeWorldToLocal(nodePath) * _camera->getViewMatrix() * _camera->getProjectionMatrix();
|
|
|
|
|
|
|
|
double zNear = -1.0;
|
|
|
|
double zFar = 1.0;
|
|
|
|
if (_camera->getViewport())
|
|
|
|
{
|
|
|
|
matrix.postMult(_camera->getViewport()->computeWindowMatrix());
|
|
|
|
zNear = 0.0;
|
|
|
|
zFar = 1.0;
|
|
|
|
}
|
|
|
|
|
|
|
|
osg::Matrix inverse;
|
|
|
|
inverse.invert(matrix);
|
|
|
|
|
|
|
|
osg::Vec3d startVertex = osg::Vec3d(x,y,zNear) * inverse;
|
|
|
|
osg::Vec3d endVertex = osg::Vec3d(x,y,zFar) * inverse;
|
|
|
|
|
|
|
|
osgUtil::LineSegmentIntersector* picker = new osgUtil::LineSegmentIntersector(osgUtil::Intersector::MODEL, startVertex, endVertex);
|
|
|
|
|
|
|
|
osgUtil::IntersectionVisitor iv(picker);
|
|
|
|
iv.setTraversalMask(traversalMask);
|
|
|
|
nodePath.back()->accept(iv);
|
|
|
|
|
|
|
|
if (picker->containsIntersections())
|
|
|
|
{
|
|
|
|
intersections = picker->getIntersections();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
intersections.clear();
|
|
|
|
return false;
|
|
|
|
}
|
2007-01-10 01:35:46 +08:00
|
|
|
}
|