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.
|
|
|
|
*/
|
|
|
|
|
2007-08-02 19:02:47 +08:00
|
|
|
#include <osgViewer/Renderer>
|
2006-11-27 22:52:07 +08:00
|
|
|
#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>
|
2007-09-26 03:14:29 +08:00
|
|
|
|
2007-09-02 00:56:53 +08:00
|
|
|
#include <osg/TextureCubeMap>
|
2007-09-26 03:14:29 +08:00
|
|
|
#include <osg/TextureRectangle>
|
2008-05-07 22:17:15 +08:00
|
|
|
#include <osg/Texture1D>
|
2007-09-26 03:14:29 +08:00
|
|
|
#include <osg/TexMat>
|
2006-11-27 22:52:07 +08:00
|
|
|
|
2007-08-10 18:52:35 +08:00
|
|
|
#include <osgUtil/Optimizer>
|
2007-01-10 01:35:46 +08:00
|
|
|
#include <osgUtil/IntersectionVisitor>
|
|
|
|
|
2006-11-27 22:52:07 +08:00
|
|
|
using namespace osgViewer;
|
|
|
|
|
2007-05-18 18:33:56 +08:00
|
|
|
class CollectedCoordinateSystemNodesVisitor : public osg::NodeVisitor
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
CollectedCoordinateSystemNodesVisitor():
|
|
|
|
NodeVisitor(osg::NodeVisitor::TRAVERSE_ACTIVE_CHILDREN) {}
|
|
|
|
|
|
|
|
|
|
|
|
virtual void apply(osg::Node& node)
|
|
|
|
{
|
|
|
|
traverse(node);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void apply(osg::CoordinateSystemNode& node)
|
|
|
|
{
|
|
|
|
if (_pathToCoordinateSystemNode.empty())
|
|
|
|
{
|
|
|
|
osg::notify(osg::INFO)<<"Found CoordianteSystemNode node"<<std::endl;
|
|
|
|
osg::notify(osg::INFO)<<" CoordinateSystem = "<<node.getCoordinateSystem()<<std::endl;
|
|
|
|
_pathToCoordinateSystemNode = getNodePath();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
osg::notify(osg::INFO)<<"Found additional CoordianteSystemNode node, but ignoring"<<std::endl;
|
|
|
|
osg::notify(osg::INFO)<<" CoordinateSystem = "<<node.getCoordinateSystem()<<std::endl;
|
|
|
|
}
|
|
|
|
traverse(node);
|
|
|
|
}
|
|
|
|
|
|
|
|
osg::NodePath _pathToCoordinateSystemNode;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2007-12-11 01:30:18 +08:00
|
|
|
/** callback class to use to allow matrix manipulators to query the application for the local coordinate frame.*/
|
2007-05-18 18:33:56 +08:00
|
|
|
class ViewerCoordinateFrameCallback : public osgGA::MatrixManipulator::CoordinateFrameCallback
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
ViewerCoordinateFrameCallback(osgViewer::View* view):
|
|
|
|
_view(view) {}
|
|
|
|
|
|
|
|
virtual osg::CoordinateFrame getCoordinateFrame(const osg::Vec3d& position) const
|
|
|
|
{
|
|
|
|
osg::notify(osg::INFO)<<"getCoordinateFrame("<<position<<")"<<std::endl;
|
|
|
|
|
|
|
|
osg::NodePath tmpPath = _view->getCoordinateSystemNodePath();
|
|
|
|
|
|
|
|
if (!tmpPath.empty())
|
|
|
|
{
|
|
|
|
osg::Matrixd coordinateFrame;
|
|
|
|
|
|
|
|
osg::CoordinateSystemNode* csn = dynamic_cast<osg::CoordinateSystemNode*>(tmpPath.back());
|
|
|
|
if (csn)
|
|
|
|
{
|
|
|
|
osg::Vec3 local_position = position*osg::computeWorldToLocal(tmpPath);
|
|
|
|
|
|
|
|
// get the coordinate frame in world coords.
|
|
|
|
coordinateFrame = csn->computeLocalCoordinateFrame(local_position)* osg::computeLocalToWorld(tmpPath);
|
|
|
|
|
|
|
|
// keep the position of the coordinate frame to reapply after rescale.
|
|
|
|
osg::Vec3d pos = coordinateFrame.getTrans();
|
|
|
|
|
|
|
|
// compensate for any scaling, so that the coordinate frame is a unit size
|
|
|
|
osg::Vec3d x(1.0,0.0,0.0);
|
|
|
|
osg::Vec3d y(0.0,1.0,0.0);
|
|
|
|
osg::Vec3d z(0.0,0.0,1.0);
|
|
|
|
x = osg::Matrixd::transform3x3(x,coordinateFrame);
|
|
|
|
y = osg::Matrixd::transform3x3(y,coordinateFrame);
|
|
|
|
z = osg::Matrixd::transform3x3(z,coordinateFrame);
|
|
|
|
coordinateFrame.preMult(osg::Matrixd::scale(1.0/x.length(),1.0/y.length(),1.0/z.length()));
|
|
|
|
|
|
|
|
// reapply the position.
|
|
|
|
coordinateFrame.setTrans(pos);
|
|
|
|
|
|
|
|
osg::notify(osg::INFO)<<"csn->computeLocalCoordinateFrame(position)* osg::computeLocalToWorld(tmpPath)"<<coordinateFrame<<std::endl;
|
|
|
|
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
osg::notify(osg::INFO)<<"osg::computeLocalToWorld(tmpPath)"<<std::endl;
|
|
|
|
coordinateFrame = osg::computeLocalToWorld(tmpPath);
|
|
|
|
}
|
|
|
|
return coordinateFrame;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
osg::notify(osg::INFO)<<" no coordinate system found, using default orientation"<<std::endl;
|
|
|
|
return osg::Matrixd::translate(position);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual ~ViewerCoordinateFrameCallback() {}
|
|
|
|
|
|
|
|
osg::observer_ptr<osgViewer::View> _view;
|
|
|
|
};
|
|
|
|
|
2007-09-30 00:46:08 +08:00
|
|
|
|
2007-05-18 03:58:57 +08:00
|
|
|
View::View():
|
|
|
|
_fusionDistanceMode(osgUtil::SceneView::PROPORTIONAL_TO_SCREEN_DISTANCE),
|
|
|
|
_fusionDistanceValue(1.0f)
|
2006-11-27 22:52:07 +08:00
|
|
|
{
|
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
|
|
|
|
2007-08-10 18:52:35 +08:00
|
|
|
_startTick = 0;
|
|
|
|
|
|
|
|
_frameStamp = new osg::FrameStamp;
|
|
|
|
_frameStamp->setFrameNumber(0);
|
|
|
|
_frameStamp->setReferenceTime(0);
|
|
|
|
_frameStamp->setSimulationTime(0);
|
|
|
|
|
|
|
|
_scene = new Scene;
|
|
|
|
|
2007-01-05 00:49:58 +08:00
|
|
|
// make sure View is safe to reference multi-threaded.
|
|
|
|
setThreadSafeRefUnref(true);
|
2007-08-02 19:02:47 +08:00
|
|
|
|
2007-12-11 01:30:18 +08:00
|
|
|
// need to attach a Renderer to the master camera which has been default constructed
|
2007-08-02 19:02:47 +08:00
|
|
|
getCamera()->setRenderer(createRenderer(getCamera()));
|
2007-01-05 00:49:58 +08:00
|
|
|
|
|
|
|
setEventQueue(new osgGA::EventQueue);
|
2006-11-27 22:52:07 +08:00
|
|
|
}
|
|
|
|
|
2007-02-26 04:05:23 +08:00
|
|
|
|
|
|
|
View::View(const osgViewer::View& view, const osg::CopyOp& copyop):
|
|
|
|
osg::View(view,copyop),
|
2007-05-18 03:58:57 +08:00
|
|
|
osgGA::GUIActionAdapter(),
|
|
|
|
_fusionDistanceMode(view._fusionDistanceMode),
|
|
|
|
_fusionDistanceValue(view._fusionDistanceValue)
|
2007-02-26 04:05:23 +08:00
|
|
|
{
|
2007-08-10 18:52:35 +08:00
|
|
|
_scene = new Scene;
|
|
|
|
|
2007-12-11 01:30:18 +08:00
|
|
|
// need to attach a Renderer to the master camera which has been default constructed
|
2007-08-10 18:52:35 +08:00
|
|
|
getCamera()->setRenderer(createRenderer(getCamera()));
|
|
|
|
|
|
|
|
setEventQueue(new osgGA::EventQueue);
|
2007-02-26 04:05:23 +08:00
|
|
|
}
|
|
|
|
|
2006-11-27 22:52:07 +08:00
|
|
|
View::~View()
|
|
|
|
{
|
2007-08-22 17:44:55 +08:00
|
|
|
osg::notify(osg::INFO)<<"Destructing osgViewer::View"<<std::endl;
|
2006-12-20 00:00:51 +08:00
|
|
|
}
|
|
|
|
|
2007-09-21 23:34:25 +08:00
|
|
|
void View::take(osg::View& rhs)
|
|
|
|
{
|
|
|
|
osg::View::take(rhs);
|
|
|
|
|
2007-09-23 01:39:15 +08:00
|
|
|
#if 1
|
2007-09-21 23:34:25 +08:00
|
|
|
osgViewer::View* rhs_osgViewer = dynamic_cast<osgViewer::View*>(&rhs);
|
|
|
|
if (rhs_osgViewer)
|
|
|
|
{
|
2007-09-23 01:39:15 +08:00
|
|
|
|
2007-09-21 23:34:25 +08:00
|
|
|
// copy across rhs
|
|
|
|
_startTick = rhs_osgViewer->_startTick;
|
|
|
|
_frameStamp = rhs_osgViewer->_frameStamp;
|
|
|
|
|
2007-09-23 01:39:15 +08:00
|
|
|
if (rhs_osgViewer->getSceneData())
|
|
|
|
{
|
|
|
|
_scene = rhs_osgViewer->_scene;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rhs_osgViewer->_cameraManipulator.valid())
|
|
|
|
{
|
|
|
|
_cameraManipulator = rhs_osgViewer->_cameraManipulator;
|
|
|
|
}
|
|
|
|
|
|
|
|
_eventHandlers.insert(_eventHandlers.end(), rhs_osgViewer->_eventHandlers.begin(), rhs_osgViewer->_eventHandlers.end());
|
2007-09-21 23:34:25 +08:00
|
|
|
|
|
|
|
_coordinateSystemNodePath = rhs_osgViewer->_coordinateSystemNodePath;
|
|
|
|
|
|
|
|
_displaySettings = rhs_osgViewer->_displaySettings;
|
|
|
|
_fusionDistanceMode = rhs_osgViewer->_fusionDistanceMode;
|
|
|
|
_fusionDistanceValue = rhs_osgViewer->_fusionDistanceValue;
|
|
|
|
|
|
|
|
|
|
|
|
// clear rhs
|
|
|
|
rhs_osgViewer->_frameStamp = 0;
|
|
|
|
rhs_osgViewer->_scene = 0;
|
|
|
|
rhs_osgViewer->_cameraManipulator = 0;
|
|
|
|
rhs_osgViewer->_eventHandlers.clear();
|
|
|
|
|
|
|
|
rhs_osgViewer->_coordinateSystemNodePath.clear();
|
|
|
|
|
|
|
|
rhs_osgViewer->_displaySettings;
|
|
|
|
}
|
2007-09-23 01:39:15 +08:00
|
|
|
#endif
|
|
|
|
computeActiveCoordinateSystemNodePath();
|
|
|
|
assignSceneDataToCameras();
|
2007-09-21 23:34:25 +08:00
|
|
|
}
|
2007-08-10 18:52:35 +08:00
|
|
|
|
2007-08-02 19:02:47 +08:00
|
|
|
osg::GraphicsOperation* View::createRenderer(osg::Camera* camera)
|
|
|
|
{
|
|
|
|
Renderer* render = new Renderer(camera);
|
|
|
|
camera->setStats(new osg::Stats("Camera"));
|
|
|
|
return render;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-01-17 00:01:01 +08:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-08-10 18:52:35 +08:00
|
|
|
void View::setStartTick(osg::Timer_t tick)
|
|
|
|
{
|
|
|
|
_startTick = tick;
|
|
|
|
}
|
|
|
|
|
2007-12-13 01:59:06 +08:00
|
|
|
void View::setSceneData(osg::ref_ptr<osg::Node> node)
|
2006-12-20 00:00:51 +08:00
|
|
|
{
|
2007-12-13 01:59:06 +08:00
|
|
|
if (node==_scene->getSceneData()) return;
|
2007-08-10 18:52:35 +08:00
|
|
|
|
2007-12-13 01:59:06 +08:00
|
|
|
osg::ref_ptr<Scene> scene = Scene::getScene(node.get());
|
2007-08-10 18:57:00 +08:00
|
|
|
|
2007-12-13 01:59:06 +08:00
|
|
|
if (scene.valid())
|
2007-08-10 18:52:35 +08:00
|
|
|
{
|
2007-12-13 01:59:06 +08:00
|
|
|
osg::notify(osg::INFO)<<"View::setSceneData() Sharing scene "<<scene.get()<<std::endl;
|
2007-08-10 18:52:35 +08:00
|
|
|
_scene = scene;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (_scene->referenceCount()!=1)
|
|
|
|
{
|
|
|
|
// we are not the only reference to the Scene so we cannot reuse it.
|
|
|
|
_scene = new Scene;
|
|
|
|
osg::notify(osg::INFO)<<"View::setSceneData() Allocating new scene"<<_scene.get()<<std::endl;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
osg::notify(osg::INFO)<<"View::setSceneData() Reusing exisitng scene"<<_scene.get()<<std::endl;
|
|
|
|
}
|
|
|
|
|
2007-12-13 01:59:06 +08:00
|
|
|
_scene->setSceneData(node.get());
|
2007-08-10 18:52:35 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (getSceneData())
|
|
|
|
{
|
2007-12-11 01:30:18 +08:00
|
|
|
// now make sure the scene graph is set up with the correct DataVariance to protect the dynamic elements of
|
2007-08-10 18:52:35 +08:00
|
|
|
// the scene graph from being run in parallel.
|
|
|
|
osgUtil::Optimizer::StaticObjectDetectionVisitor sodv;
|
|
|
|
getSceneData()->accept(sodv);
|
|
|
|
}
|
2006-12-20 00:00:51 +08:00
|
|
|
|
2007-05-18 18:33:56 +08:00
|
|
|
computeActiveCoordinateSystemNodePath();
|
|
|
|
|
2006-12-20 00:00:51 +08:00
|
|
|
assignSceneDataToCameras();
|
|
|
|
}
|
|
|
|
|
2007-08-10 18:57:00 +08:00
|
|
|
void View::setDatabasePager(osgDB::DatabasePager* dp)
|
|
|
|
{
|
|
|
|
_scene->setDatabasePager(dp);
|
|
|
|
}
|
|
|
|
|
2007-08-10 18:52:35 +08:00
|
|
|
osgDB::DatabasePager* View::getDatabasePager()
|
|
|
|
{
|
2007-08-10 18:57:00 +08:00
|
|
|
return _scene->getDatabasePager();
|
2007-08-10 18:52:35 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
const osgDB::DatabasePager* View::getDatabasePager() const
|
|
|
|
{
|
2007-08-10 18:57:00 +08:00
|
|
|
return _scene->getDatabasePager();
|
2007-08-10 18:52:35 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-12-21 05:13:29 +08:00
|
|
|
void View::setCameraManipulator(osgGA::MatrixManipulator* manipulator)
|
|
|
|
{
|
|
|
|
_cameraManipulator = manipulator;
|
2007-05-18 18:33:56 +08:00
|
|
|
|
|
|
|
if (_cameraManipulator.valid())
|
2006-12-21 05:13:29 +08:00
|
|
|
{
|
2007-05-18 18:33:56 +08:00
|
|
|
_cameraManipulator->setCoordinateFrameCallback(new ViewerCoordinateFrameCallback(this));
|
|
|
|
|
|
|
|
if (getSceneData()) _cameraManipulator->setNode(getSceneData());
|
2006-12-21 05:13:29 +08:00
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-06-07 17:58:49 +08:00
|
|
|
void View::home()
|
|
|
|
{
|
|
|
|
if (_cameraManipulator.valid())
|
|
|
|
{
|
|
|
|
osg::ref_ptr<osgGA::GUIEventAdapter> dummyEvent = _eventQueue->createEvent();
|
|
|
|
_cameraManipulator->home(*dummyEvent, *this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-12-27 01:38:47 +08:00
|
|
|
void View::addEventHandler(osgGA::GUIEventHandler* eventHandler)
|
|
|
|
{
|
|
|
|
_eventHandlers.push_back(eventHandler);
|
|
|
|
}
|
|
|
|
|
2007-05-18 18:33:56 +08:00
|
|
|
void View::setCoordinateSystemNodePath(const osg::NodePath& nodePath)
|
|
|
|
{
|
|
|
|
_coordinateSystemNodePath.clear();
|
|
|
|
std::copy(nodePath.begin(),
|
|
|
|
nodePath.end(),
|
|
|
|
std::back_inserter(_coordinateSystemNodePath));
|
|
|
|
}
|
|
|
|
|
|
|
|
osg::NodePath View::getCoordinateSystemNodePath() const
|
|
|
|
{
|
|
|
|
osg::NodePath nodePath;
|
2007-07-12 00:06:04 +08:00
|
|
|
for(ObserverNodePath::const_iterator itr = _coordinateSystemNodePath.begin();
|
2007-05-18 18:33:56 +08:00
|
|
|
itr != _coordinateSystemNodePath.end();
|
|
|
|
++itr)
|
|
|
|
{
|
|
|
|
nodePath.push_back(const_cast<osg::Node*>(itr->get()));
|
|
|
|
}
|
|
|
|
return nodePath;
|
|
|
|
}
|
|
|
|
|
|
|
|
void View::computeActiveCoordinateSystemNodePath()
|
|
|
|
{
|
|
|
|
// now search for CoordinateSystemNode's for which we want to track.
|
|
|
|
osg::Node* subgraph = getSceneData();
|
|
|
|
|
|
|
|
if (subgraph)
|
|
|
|
{
|
|
|
|
|
|
|
|
CollectedCoordinateSystemNodesVisitor ccsnv;
|
|
|
|
subgraph->accept(ccsnv);
|
|
|
|
|
|
|
|
if (!ccsnv._pathToCoordinateSystemNode.empty())
|
|
|
|
{
|
|
|
|
setCoordinateSystemNodePath(ccsnv._pathToCoordinateSystemNode);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// otherwise no node path found so reset to empty.
|
|
|
|
setCoordinateSystemNodePath(osg::NodePath());
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
|
2007-08-03 22:50:58 +08:00
|
|
|
osg::GraphicsContext::ScreenIdentifier si;
|
|
|
|
si.readDISPLAY();
|
|
|
|
|
|
|
|
// displayNum has not been set so reset it to 0.
|
|
|
|
if (si.displayNum<0) si.displayNum = 0;
|
|
|
|
|
|
|
|
unsigned int numScreens = wsi->getNumScreens(si);
|
2006-12-20 00:00:51 +08:00
|
|
|
if (numScreens==1)
|
|
|
|
{
|
2007-08-03 22:50:58 +08:00
|
|
|
if (si.screenNum<0) si.screenNum = 0;
|
|
|
|
|
2007-01-30 23:37:30 +08:00
|
|
|
unsigned int width, height;
|
2007-08-03 22:50:58 +08:00
|
|
|
wsi->getScreenResolution(si, width, height);
|
2007-01-30 23:37:30 +08:00
|
|
|
|
|
|
|
osg::ref_ptr<osg::GraphicsContext::Traits> traits = new osg::GraphicsContext::Traits;
|
2007-08-03 22:50:58 +08:00
|
|
|
traits->hostName = si.hostName;
|
|
|
|
traits->displayNum = si.displayNum;
|
|
|
|
traits->screenNum = si.screenNum;
|
2007-01-30 23:37:30 +08:00
|
|
|
traits->x = 0;
|
|
|
|
traits->y = 0;
|
|
|
|
traits->width = width;
|
|
|
|
traits->height = height;
|
|
|
|
traits->alpha = ds->getMinimumNumAlphaBits();
|
|
|
|
traits->stencil = ds->getMinimumNumStencilBits();
|
|
|
|
traits->windowDecoration = false;
|
|
|
|
traits->doubleBuffer = true;
|
|
|
|
traits->sharedContext = 0;
|
2007-04-06 22:40:39 +08:00
|
|
|
traits->sampleBuffers = ds->getMultiSamples();
|
|
|
|
traits->samples = ds->getNumMultiSamples();
|
2007-08-06 01:06:16 +08:00
|
|
|
if (ds->getStereo())
|
2007-06-13 18:38:40 +08:00
|
|
|
{
|
2007-08-06 01:06:16 +08:00
|
|
|
switch(ds->getStereoMode())
|
|
|
|
{
|
|
|
|
case(osg::DisplaySettings::QUAD_BUFFER): traits->quadBufferStereo = true; break;
|
|
|
|
case(osg::DisplaySettings::VERTICAL_INTERLACE):
|
2007-08-23 22:31:23 +08:00
|
|
|
case(osg::DisplaySettings::CHECKERBOARD):
|
2007-08-06 01:06:16 +08:00
|
|
|
case(osg::DisplaySettings::HORIZONTAL_INTERLACE): traits->stencil = 8; break;
|
|
|
|
default: break;
|
|
|
|
}
|
2007-04-06 22:40:39 +08:00
|
|
|
}
|
2007-08-06 01:06:16 +08:00
|
|
|
|
2007-01-30 23:37:30 +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)
|
|
|
|
{
|
|
|
|
osg::notify(osg::INFO)<<" GraphicsWindow has been created successfully."<<std::endl;
|
|
|
|
gw->getEventQueue()->getCurrentEventState()->setWindowRectangle(0, 0, width, height );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
osg::notify(osg::NOTICE)<<" GraphicsWindow has not been created successfully."<<std::endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
double newAspectRatio = double(traits->width) / double(traits->height);
|
|
|
|
double aspectRatioChange = newAspectRatio / aspectRatio;
|
|
|
|
if (aspectRatioChange != 1.0)
|
|
|
|
{
|
|
|
|
_camera->getProjectionMatrix() *= osg::Matrix::scale(1.0/aspectRatioChange,1.0,1.0);
|
|
|
|
}
|
|
|
|
|
|
|
|
_camera->setViewport(new osg::Viewport(0, 0, traits->width, traits->height));
|
|
|
|
|
|
|
|
GLenum buffer = traits->doubleBuffer ? GL_BACK : GL_FRONT;
|
|
|
|
|
|
|
|
_camera->setDrawBuffer(buffer);
|
|
|
|
_camera->setReadBuffer(buffer);
|
|
|
|
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
|
2007-02-18 22:21:16 +08:00
|
|
|
double translate_x = 0.0;
|
|
|
|
|
|
|
|
for(unsigned int i=0; i<numScreens; ++i)
|
|
|
|
{
|
2007-09-28 21:38:32 +08:00
|
|
|
si.screenNum = i;
|
|
|
|
|
2007-02-18 22:21:16 +08:00
|
|
|
unsigned int width, height;
|
2007-09-28 21:38:32 +08:00
|
|
|
wsi->getScreenResolution(si, width, height);
|
2007-02-18 22:21:16 +08:00
|
|
|
translate_x += double(width) / (double(height) * aspectRatio);
|
|
|
|
}
|
2007-06-09 18:06:38 +08:00
|
|
|
|
|
|
|
bool stereoSlitScreens = numScreens==2 &&
|
|
|
|
ds->getStereoMode()==osg::DisplaySettings::HORIZONTAL_SPLIT &&
|
|
|
|
ds->getStereo();
|
2007-02-18 22:21:16 +08:00
|
|
|
|
|
|
|
for(unsigned int i=0; i<numScreens; ++i)
|
2007-01-30 23:37:30 +08:00
|
|
|
{
|
2007-08-03 22:50:58 +08:00
|
|
|
si.screenNum = i;
|
|
|
|
|
2006-12-20 00:00:51 +08:00
|
|
|
unsigned int width, height;
|
2007-08-03 22:50:58 +08:00
|
|
|
wsi->getScreenResolution(si, width, height);
|
2006-12-20 00:00:51 +08:00
|
|
|
|
|
|
|
osg::ref_ptr<osg::GraphicsContext::Traits> traits = new osg::GraphicsContext::Traits;
|
2007-08-03 22:50:58 +08:00
|
|
|
traits->hostName = si.hostName;
|
|
|
|
traits->displayNum = si.displayNum;
|
|
|
|
traits->screenNum = si.screenNum;
|
2007-01-30 23:37:30 +08:00
|
|
|
traits->screenNum = i;
|
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;
|
2007-04-06 22:40:39 +08:00
|
|
|
traits->sampleBuffers = ds->getMultiSamples();
|
|
|
|
traits->samples = ds->getNumMultiSamples();
|
2007-08-06 01:06:16 +08:00
|
|
|
if (ds->getStereo())
|
2007-06-09 18:06:38 +08:00
|
|
|
{
|
2007-08-06 01:06:16 +08:00
|
|
|
switch(ds->getStereoMode())
|
|
|
|
{
|
|
|
|
case(osg::DisplaySettings::QUAD_BUFFER): traits->quadBufferStereo = true; break;
|
|
|
|
case(osg::DisplaySettings::VERTICAL_INTERLACE):
|
2007-08-23 22:31:23 +08:00
|
|
|
case(osg::DisplaySettings::CHECKERBOARD):
|
2007-08-06 01:06:16 +08:00
|
|
|
case(osg::DisplaySettings::HORIZONTAL_INTERLACE): traits->stencil = 8; break;
|
|
|
|
default: break;
|
|
|
|
}
|
2007-04-06 22:40:39 +08:00
|
|
|
}
|
2007-01-30 23:37:30 +08:00
|
|
|
|
2006-12-20 00:00:51 +08:00
|
|
|
osg::ref_ptr<osg::GraphicsContext> gc = osg::GraphicsContext::createGraphicsContext(traits.get());
|
2007-01-30 23:37:30 +08:00
|
|
|
|
|
|
|
osg::ref_ptr<osg::Camera> camera = new osg::Camera;
|
|
|
|
camera->setGraphicsContext(gc.get());
|
|
|
|
|
2006-12-20 00:00:51 +08:00
|
|
|
osgViewer::GraphicsWindow* gw = dynamic_cast<osgViewer::GraphicsWindow*>(gc.get());
|
|
|
|
if (gw)
|
|
|
|
{
|
2007-01-30 23:37:30 +08:00
|
|
|
osg::notify(osg::INFO)<<" GraphicsWindow has been created successfully."<<gw<<std::endl;
|
|
|
|
|
|
|
|
gw->getEventQueue()->getCurrentEventState()->setWindowRectangle(traits->x, traits->y, traits->width, traits->height );
|
2006-12-20 00:00:51 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
osg::notify(osg::NOTICE)<<" GraphicsWindow has not been created successfully."<<std::endl;
|
|
|
|
}
|
|
|
|
|
2007-01-30 23:37:30 +08:00
|
|
|
camera->setViewport(new osg::Viewport(0, 0, traits->width, traits->height));
|
2007-01-02 20:03:48 +08:00
|
|
|
|
2007-01-30 23:37:30 +08:00
|
|
|
GLenum buffer = traits->doubleBuffer ? GL_BACK : GL_FRONT;
|
|
|
|
camera->setDrawBuffer(buffer);
|
|
|
|
camera->setReadBuffer(buffer);
|
2007-01-02 20:03:48 +08:00
|
|
|
|
2007-06-09 18:06:38 +08:00
|
|
|
if (stereoSlitScreens)
|
|
|
|
{
|
|
|
|
unsigned int leftCameraNum = (ds->getSplitStereoHorizontalEyeMapping()==osg::DisplaySettings::LEFT_EYE_LEFT_VIEWPORT) ? 0 : 1;
|
|
|
|
|
|
|
|
osg::ref_ptr<osg::DisplaySettings> ds_local = new osg::DisplaySettings(*ds);
|
|
|
|
ds_local->setStereoMode(leftCameraNum==i ? osg::DisplaySettings::LEFT_EYE : osg::DisplaySettings::RIGHT_EYE);
|
|
|
|
camera->setDisplaySettings(ds_local.get());
|
|
|
|
|
|
|
|
addSlave(camera.get(), osg::Matrixd(), osg::Matrixd() );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
double newAspectRatio = double(traits->width) / double(traits->height);
|
|
|
|
double aspectRatioChange = newAspectRatio / aspectRatio;
|
2007-01-02 20:03:48 +08:00
|
|
|
|
2007-06-09 18:06:38 +08:00
|
|
|
addSlave(camera.get(), osg::Matrixd::translate( translate_x - aspectRatioChange, 0.0, 0.0) * osg::Matrix::scale(1.0/aspectRatioChange,1.0,1.0), osg::Matrixd() );
|
|
|
|
translate_x -= aspectRatioChange * 2.0;
|
|
|
|
}
|
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-06-13 18:38:40 +08:00
|
|
|
void View::setUpViewInWindow(int x, int y, int width, int height, unsigned int screenNum)
|
|
|
|
{
|
|
|
|
osg::DisplaySettings* ds = _displaySettings.valid() ? _displaySettings.get() : osg::DisplaySettings::instance();
|
|
|
|
|
|
|
|
osg::ref_ptr<osg::GraphicsContext::Traits> traits = new osg::GraphicsContext::Traits;
|
2007-08-03 22:50:58 +08:00
|
|
|
|
|
|
|
traits->readDISPLAY();
|
|
|
|
if (traits->displayNum<0) traits->displayNum = 0;
|
|
|
|
|
2007-06-13 18:38:40 +08:00
|
|
|
traits->screenNum = screenNum;
|
|
|
|
traits->x = x;
|
|
|
|
traits->y = y;
|
|
|
|
traits->width = width;
|
|
|
|
traits->height = height;
|
|
|
|
traits->alpha = ds->getMinimumNumAlphaBits();
|
|
|
|
traits->stencil = ds->getMinimumNumStencilBits();
|
|
|
|
traits->windowDecoration = true;
|
|
|
|
traits->doubleBuffer = true;
|
|
|
|
traits->sharedContext = 0;
|
|
|
|
traits->sampleBuffers = ds->getMultiSamples();
|
|
|
|
traits->samples = ds->getNumMultiSamples();
|
2007-08-06 01:06:16 +08:00
|
|
|
if (ds->getStereo())
|
2007-06-13 18:38:40 +08:00
|
|
|
{
|
2007-08-06 01:06:16 +08:00
|
|
|
switch(ds->getStereoMode())
|
|
|
|
{
|
|
|
|
case(osg::DisplaySettings::QUAD_BUFFER): traits->quadBufferStereo = true; break;
|
|
|
|
case(osg::DisplaySettings::VERTICAL_INTERLACE):
|
2007-08-23 22:31:23 +08:00
|
|
|
case(osg::DisplaySettings::CHECKERBOARD):
|
2007-08-06 01:06:16 +08:00
|
|
|
case(osg::DisplaySettings::HORIZONTAL_INTERLACE): traits->stencil = 8; break;
|
|
|
|
default: break;
|
|
|
|
}
|
2007-06-13 18:38:40 +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)
|
|
|
|
{
|
|
|
|
osg::notify(osg::INFO)<<"View::setUpViewOnSingleScreen - GraphicsWindow has been created successfully."<<std::endl;
|
|
|
|
gw->getEventQueue()->getCurrentEventState()->setWindowRectangle(x, y, width, height );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
osg::notify(osg::NOTICE)<<" GraphicsWindow has not been created successfully."<<std::endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
double fovy, aspectRatio, zNear, zFar;
|
|
|
|
_camera->getProjectionMatrixAsPerspective(fovy, aspectRatio, zNear, zFar);
|
|
|
|
|
|
|
|
double newAspectRatio = double(traits->width) / double(traits->height);
|
|
|
|
double aspectRatioChange = newAspectRatio / aspectRatio;
|
|
|
|
if (aspectRatioChange != 1.0)
|
|
|
|
{
|
|
|
|
_camera->getProjectionMatrix() *= osg::Matrix::scale(1.0/aspectRatioChange,1.0,1.0);
|
|
|
|
}
|
|
|
|
|
|
|
|
_camera->setViewport(new osg::Viewport(0, 0, traits->width, traits->height));
|
|
|
|
|
|
|
|
GLenum buffer = traits->doubleBuffer ? GL_BACK : GL_FRONT;
|
|
|
|
|
|
|
|
_camera->setDrawBuffer(buffer);
|
|
|
|
_camera->setReadBuffer(buffer);
|
|
|
|
}
|
|
|
|
|
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-08-03 22:50:58 +08:00
|
|
|
osg::GraphicsContext::ScreenIdentifier si;
|
|
|
|
si.readDISPLAY();
|
|
|
|
|
|
|
|
// displayNum has not been set so reset it to 0.
|
|
|
|
if (si.displayNum<0) si.displayNum = 0;
|
|
|
|
|
|
|
|
si.screenNum = screenNum;
|
|
|
|
|
2007-01-07 05:06:35 +08:00
|
|
|
unsigned int width, height;
|
2007-08-03 22:50:58 +08:00
|
|
|
wsi->getScreenResolution(si, width, height);
|
2007-01-07 05:06:35 +08:00
|
|
|
|
|
|
|
osg::ref_ptr<osg::GraphicsContext::Traits> traits = new osg::GraphicsContext::Traits;
|
2007-08-03 22:50:58 +08:00
|
|
|
traits->hostName = si.hostName;
|
|
|
|
traits->displayNum = si.displayNum;
|
|
|
|
traits->screenNum = si.screenNum;
|
2007-01-07 05:06:35 +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();
|
2007-01-07 05:06:35 +08:00
|
|
|
traits->windowDecoration = false;
|
|
|
|
traits->doubleBuffer = true;
|
|
|
|
traits->sharedContext = 0;
|
2007-04-06 22:40:39 +08:00
|
|
|
traits->sampleBuffers = ds->getMultiSamples();
|
|
|
|
traits->samples = ds->getNumMultiSamples();
|
2007-08-06 01:06:16 +08:00
|
|
|
if (ds->getStereo())
|
2007-06-13 18:38:40 +08:00
|
|
|
{
|
2007-08-06 01:06:16 +08:00
|
|
|
switch(ds->getStereoMode())
|
|
|
|
{
|
|
|
|
case(osg::DisplaySettings::QUAD_BUFFER): traits->quadBufferStereo = true; break;
|
|
|
|
case(osg::DisplaySettings::VERTICAL_INTERLACE):
|
2007-08-23 22:31:23 +08:00
|
|
|
case(osg::DisplaySettings::CHECKERBOARD):
|
2007-08-06 01:06:16 +08:00
|
|
|
case(osg::DisplaySettings::HORIZONTAL_INTERLACE): traits->stencil = 8; break;
|
|
|
|
default: break;
|
|
|
|
}
|
2007-04-06 22:40:39 +08:00
|
|
|
}
|
2007-01-07 05:06:35 +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)
|
|
|
|
{
|
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;
|
|
|
|
}
|
|
|
|
|
2007-01-30 23:37:30 +08:00
|
|
|
double fovy, aspectRatio, zNear, zFar;
|
|
|
|
_camera->getProjectionMatrixAsPerspective(fovy, aspectRatio, zNear, zFar);
|
|
|
|
|
|
|
|
double newAspectRatio = double(traits->width) / double(traits->height);
|
|
|
|
double aspectRatioChange = newAspectRatio / aspectRatio;
|
|
|
|
if (aspectRatioChange != 1.0)
|
|
|
|
{
|
|
|
|
_camera->getProjectionMatrix() *= osg::Matrix::scale(1.0/aspectRatioChange,1.0,1.0);
|
|
|
|
}
|
|
|
|
|
|
|
|
_camera->setViewport(new osg::Viewport(0, 0, traits->width, traits->height));
|
2007-01-07 05:06:35 +08:00
|
|
|
|
|
|
|
GLenum buffer = traits->doubleBuffer ? GL_BACK : GL_FRONT;
|
|
|
|
|
|
|
|
_camera->setDrawBuffer(buffer);
|
|
|
|
_camera->setReadBuffer(buffer);
|
|
|
|
}
|
|
|
|
|
2008-01-28 23:41:42 +08:00
|
|
|
static osg::Geometry* create3DSphericalDisplayDistortionMesh(const osg::Vec3& origin, const osg::Vec3& widthVector, const osg::Vec3& heightVector, double sphere_radius, double collar_radius,osg::Image* intensityMap, const osg::Matrix& projectorMatrix)
|
2007-09-02 00:56:53 +08:00
|
|
|
{
|
|
|
|
osg::Vec3d center(0.0,0.0,0.0);
|
|
|
|
osg::Vec3d eye(0.0,0.0,0.0);
|
|
|
|
|
|
|
|
double distance = sqrt(sphere_radius*sphere_radius - collar_radius*collar_radius);
|
|
|
|
|
|
|
|
bool centerProjection = false;
|
|
|
|
|
|
|
|
osg::Vec3d projector = eye - osg::Vec3d(0.0,0.0, distance);
|
|
|
|
|
2007-09-26 03:14:29 +08:00
|
|
|
osg::notify(osg::INFO)<<"create3DSphericalDisplayDistortionMesh : Projector position = "<<projector<<std::endl;
|
|
|
|
osg::notify(osg::INFO)<<"create3DSphericalDisplayDistortionMesh : distance = "<<distance<<std::endl;
|
2007-09-02 00:56:53 +08:00
|
|
|
|
|
|
|
|
|
|
|
// create the quad to visualize.
|
|
|
|
osg::Geometry* geometry = new osg::Geometry();
|
|
|
|
|
|
|
|
geometry->setSupportsDisplayList(false);
|
|
|
|
|
|
|
|
osg::Vec3 xAxis(widthVector);
|
|
|
|
float width = widthVector.length();
|
|
|
|
xAxis /= width;
|
|
|
|
|
|
|
|
osg::Vec3 yAxis(heightVector);
|
|
|
|
float height = heightVector.length();
|
|
|
|
yAxis /= height;
|
|
|
|
|
|
|
|
int noSteps = 50;
|
|
|
|
|
|
|
|
osg::Vec3Array* vertices = new osg::Vec3Array;
|
2007-09-26 03:14:29 +08:00
|
|
|
osg::Vec3Array* texcoords0 = new osg::Vec3Array;
|
2007-10-31 20:55:59 +08:00
|
|
|
osg::Vec2Array* texcoords1 = intensityMap==0 ? new osg::Vec2Array : 0;
|
2007-09-02 00:56:53 +08:00
|
|
|
osg::Vec4Array* colors = new osg::Vec4Array;
|
|
|
|
|
|
|
|
osg::Vec3 bottom = origin;
|
|
|
|
osg::Vec3 dx = xAxis*(width/((float)(noSteps-1)));
|
|
|
|
osg::Vec3 dy = yAxis*(height/((float)(noSteps-1)));
|
|
|
|
|
|
|
|
osg::Vec3d screenCenter = origin + widthVector*0.5f + heightVector*0.5f;
|
|
|
|
float screenRadius = heightVector.length() * 0.5f;
|
|
|
|
|
|
|
|
osg::Vec3 cursor = bottom;
|
|
|
|
int i,j;
|
2008-01-28 23:41:42 +08:00
|
|
|
|
2007-09-02 00:56:53 +08:00
|
|
|
if (centerProjection)
|
|
|
|
{
|
|
|
|
for(i=0;i<noSteps;++i)
|
|
|
|
{
|
|
|
|
osg::Vec3 cursor = bottom+dy*(float)i;
|
|
|
|
for(j=0;j<noSteps;++j)
|
|
|
|
{
|
|
|
|
osg::Vec2 delta(cursor.x() - screenCenter.x(), cursor.y() - screenCenter.y());
|
|
|
|
double theta = atan2(-delta.y(), delta.x());
|
|
|
|
double phi = osg::PI_2 * delta.length() / screenRadius;
|
|
|
|
if (phi > osg::PI_2) phi = osg::PI_2;
|
|
|
|
|
|
|
|
phi *= 2.0;
|
2007-09-26 03:14:29 +08:00
|
|
|
|
|
|
|
if (theta<0.0) theta += 2.0*osg::PI;
|
2007-09-02 00:56:53 +08:00
|
|
|
|
|
|
|
// osg::notify(osg::NOTICE)<<"theta = "<<theta<< "phi="<<phi<<std::endl;
|
|
|
|
|
|
|
|
osg::Vec3 texcoord(sin(phi) * cos(theta),
|
|
|
|
sin(phi) * sin(theta),
|
|
|
|
cos(phi));
|
|
|
|
|
|
|
|
vertices->push_back(cursor);
|
2008-01-28 23:41:42 +08:00
|
|
|
texcoords0->push_back(texcoord * projectorMatrix);
|
2007-10-31 20:55:59 +08:00
|
|
|
|
|
|
|
osg::Vec2 texcoord1(theta/(2.0*osg::PI), 1.0f - phi/osg::PI_2);
|
|
|
|
if (intensityMap)
|
|
|
|
{
|
|
|
|
colors->push_back(intensityMap->getColor(texcoord1));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
colors->push_back(osg::Vec4(1.0f,1.0f,1.0f,1.0f));
|
|
|
|
if (texcoords1) texcoords1->push_back( texcoord1 );
|
|
|
|
}
|
2007-09-02 00:56:53 +08:00
|
|
|
|
|
|
|
cursor += dx;
|
|
|
|
}
|
|
|
|
// osg::notify(osg::NOTICE)<<std::endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for(i=0;i<noSteps;++i)
|
|
|
|
{
|
|
|
|
osg::Vec3 cursor = bottom+dy*(float)i;
|
|
|
|
for(j=0;j<noSteps;++j)
|
|
|
|
{
|
|
|
|
osg::Vec2 delta(cursor.x() - screenCenter.x(), cursor.y() - screenCenter.y());
|
|
|
|
double theta = atan2(-delta.y(), delta.x());
|
|
|
|
double phi = osg::PI_2 * delta.length() / screenRadius;
|
|
|
|
if (phi > osg::PI_2) phi = osg::PI_2;
|
2007-09-26 03:14:29 +08:00
|
|
|
if (theta<0.0) theta += 2.0*osg::PI;
|
2007-09-02 00:56:53 +08:00
|
|
|
|
|
|
|
// osg::notify(osg::NOTICE)<<"theta = "<<theta<< "phi="<<phi<<std::endl;
|
|
|
|
|
|
|
|
double f = distance * sin(phi);
|
|
|
|
double e = distance * cos(phi) + sqrt( sphere_radius*sphere_radius - f*f);
|
|
|
|
double l = e * cos(phi);
|
|
|
|
double h = e * sin(phi);
|
|
|
|
double z = l - distance;
|
|
|
|
|
|
|
|
osg::Vec3 texcoord(h * cos(theta) / sphere_radius,
|
|
|
|
h * sin(theta) / sphere_radius,
|
|
|
|
z / sphere_radius);
|
|
|
|
|
|
|
|
vertices->push_back(cursor);
|
2008-01-28 23:41:42 +08:00
|
|
|
texcoords0->push_back(texcoord * projectorMatrix);
|
2007-10-31 20:55:59 +08:00
|
|
|
|
|
|
|
osg::Vec2 texcoord1(theta/(2.0*osg::PI), 1.0f - phi/osg::PI_2);
|
|
|
|
if (intensityMap)
|
|
|
|
{
|
|
|
|
colors->push_back(intensityMap->getColor(texcoord1));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
colors->push_back(osg::Vec4(1.0f,1.0f,1.0f,1.0f));
|
|
|
|
if (texcoords1) texcoords1->push_back( texcoord1 );
|
|
|
|
}
|
2007-09-02 00:56:53 +08:00
|
|
|
|
|
|
|
cursor += dx;
|
|
|
|
}
|
|
|
|
// osg::notify(osg::NOTICE)<<std::endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// pass the created vertex array to the points geometry object.
|
|
|
|
geometry->setVertexArray(vertices);
|
|
|
|
|
|
|
|
geometry->setColorArray(colors);
|
|
|
|
geometry->setColorBinding(osg::Geometry::BIND_PER_VERTEX);
|
|
|
|
|
2007-09-26 03:14:29 +08:00
|
|
|
geometry->setTexCoordArray(0,texcoords0);
|
2007-10-31 20:55:59 +08:00
|
|
|
if (texcoords1) geometry->setTexCoordArray(1,texcoords1);
|
2007-09-02 00:56:53 +08:00
|
|
|
|
|
|
|
for(i=0;i<noSteps-1;++i)
|
|
|
|
{
|
|
|
|
osg::DrawElementsUShort* elements = new osg::DrawElementsUShort(osg::PrimitiveSet::QUAD_STRIP);
|
|
|
|
for(j=0;j<noSteps;++j)
|
|
|
|
{
|
|
|
|
elements->push_back(j+(i+1)*noSteps);
|
|
|
|
elements->push_back(j+(i)*noSteps);
|
|
|
|
}
|
|
|
|
geometry->addPrimitiveSet(elements);
|
|
|
|
}
|
|
|
|
|
|
|
|
return geometry;
|
|
|
|
}
|
|
|
|
|
2008-01-28 23:41:42 +08:00
|
|
|
void View::setUpViewFor3DSphericalDisplay(double radius, double collar, unsigned int screenNum, osg::Image* intensityMap, const osg::Matrixd& projectorMatrix)
|
2007-09-02 00:56:53 +08:00
|
|
|
{
|
2007-09-26 03:14:29 +08:00
|
|
|
osg::notify(osg::INFO)<<"View::setUpViewFor3DSphericalDisplay(rad="<<radius<<", cllr="<<collar<<", sn="<<screenNum<<", im="<<intensityMap<<")"<<std::endl;
|
2007-09-02 00:56:53 +08:00
|
|
|
osg::GraphicsContext::WindowingSystemInterface* wsi = osg::GraphicsContext::getWindowingSystemInterface();
|
|
|
|
if (!wsi)
|
|
|
|
{
|
|
|
|
osg::notify(osg::NOTICE)<<"Error, no WindowSystemInterface available, cannot create windows."<<std::endl;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
osg::GraphicsContext::ScreenIdentifier si;
|
|
|
|
si.readDISPLAY();
|
|
|
|
|
|
|
|
// displayNum has not been set so reset it to 0.
|
|
|
|
if (si.displayNum<0) si.displayNum = 0;
|
|
|
|
|
|
|
|
si.screenNum = screenNum;
|
|
|
|
|
2007-09-28 21:42:41 +08:00
|
|
|
unsigned int width, height;
|
|
|
|
wsi->getScreenResolution(si, width, height);
|
|
|
|
|
|
|
|
|
2007-09-02 00:56:53 +08:00
|
|
|
osg::ref_ptr<osg::GraphicsContext::Traits> traits = new osg::GraphicsContext::Traits;
|
|
|
|
traits->hostName = si.hostName;
|
|
|
|
traits->displayNum = si.displayNum;
|
|
|
|
traits->screenNum = si.screenNum;
|
|
|
|
traits->x = 0;
|
|
|
|
traits->y = 0;
|
|
|
|
traits->width = width;
|
|
|
|
traits->height = height;
|
|
|
|
traits->windowDecoration = false;
|
|
|
|
traits->doubleBuffer = true;
|
|
|
|
traits->sharedContext = 0;
|
|
|
|
|
|
|
|
|
|
|
|
osg::ref_ptr<osg::GraphicsContext> gc = osg::GraphicsContext::createGraphicsContext(traits.get());
|
|
|
|
if (!gc)
|
|
|
|
{
|
|
|
|
osg::notify(osg::NOTICE)<<"GraphicsWindow has not been created successfully."<<std::endl;
|
|
|
|
return;
|
|
|
|
}
|
2007-10-31 20:55:59 +08:00
|
|
|
|
|
|
|
bool applyIntensityMapAsColours = true;
|
2007-09-02 00:56:53 +08:00
|
|
|
|
|
|
|
int tex_width = 512;
|
|
|
|
int tex_height = 512;
|
|
|
|
|
|
|
|
int camera_width = tex_width;
|
|
|
|
int camera_height = tex_height;
|
|
|
|
|
|
|
|
osg::TextureCubeMap* texture = new osg::TextureCubeMap;
|
|
|
|
|
|
|
|
texture->setTextureSize(tex_width, tex_height);
|
|
|
|
texture->setInternalFormat(GL_RGB);
|
|
|
|
texture->setFilter(osg::Texture::MIN_FILTER,osg::Texture::LINEAR);
|
|
|
|
texture->setFilter(osg::Texture::MAG_FILTER,osg::Texture::LINEAR);
|
2007-10-31 19:06:33 +08:00
|
|
|
texture->setWrap(osg::Texture::WRAP_S,osg::Texture::CLAMP_TO_EDGE);
|
|
|
|
texture->setWrap(osg::Texture::WRAP_T,osg::Texture::CLAMP_TO_EDGE);
|
|
|
|
texture->setWrap(osg::Texture::WRAP_R,osg::Texture::CLAMP_TO_EDGE);
|
2007-09-02 00:56:53 +08:00
|
|
|
|
|
|
|
#if 0
|
|
|
|
osg::Camera::RenderTargetImplementation renderTargetImplementation = osg::Camera::SEPERATE_WINDOW;
|
|
|
|
GLenum buffer = GL_FRONT;
|
|
|
|
#else
|
|
|
|
osg::Camera::RenderTargetImplementation renderTargetImplementation = osg::Camera::FRAME_BUFFER_OBJECT;
|
|
|
|
GLenum buffer = GL_FRONT;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// front face
|
|
|
|
{
|
|
|
|
osg::ref_ptr<osg::Camera> camera = new osg::Camera;
|
|
|
|
camera->setName("Front face camera");
|
|
|
|
camera->setGraphicsContext(gc.get());
|
|
|
|
camera->setViewport(new osg::Viewport(0,0,camera_width, camera_height));
|
|
|
|
camera->setDrawBuffer(buffer);
|
|
|
|
camera->setReadBuffer(buffer);
|
|
|
|
camera->setAllowEventFocus(false);
|
|
|
|
// tell the camera to use OpenGL frame buffer object where supported.
|
|
|
|
camera->setRenderTargetImplementation(renderTargetImplementation);
|
|
|
|
|
|
|
|
// attach the texture and use it as the color buffer.
|
|
|
|
camera->attach(osg::Camera::COLOR_BUFFER, texture, 0, osg::TextureCubeMap::POSITIVE_Y);
|
|
|
|
|
|
|
|
addSlave(camera.get(), osg::Matrixd(), osg::Matrixd());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// top face
|
|
|
|
{
|
|
|
|
osg::ref_ptr<osg::Camera> camera = new osg::Camera;
|
|
|
|
camera->setName("Top face camera");
|
|
|
|
camera->setGraphicsContext(gc.get());
|
|
|
|
camera->setViewport(new osg::Viewport(0,0,camera_width, camera_height));
|
|
|
|
GLenum buffer = traits->doubleBuffer ? GL_BACK : GL_FRONT;
|
|
|
|
camera->setDrawBuffer(buffer);
|
|
|
|
camera->setReadBuffer(buffer);
|
|
|
|
camera->setAllowEventFocus(false);
|
|
|
|
|
|
|
|
// tell the camera to use OpenGL frame buffer object where supported.
|
|
|
|
camera->setRenderTargetImplementation(renderTargetImplementation);
|
|
|
|
|
|
|
|
// attach the texture and use it as the color buffer.
|
|
|
|
camera->attach(osg::Camera::COLOR_BUFFER, texture, 0, osg::TextureCubeMap::POSITIVE_Z);
|
|
|
|
|
|
|
|
addSlave(camera.get(), osg::Matrixd(), osg::Matrixd::rotate(osg::inDegrees(-90.0f), 1.0,0.0,0.0));
|
|
|
|
}
|
|
|
|
|
|
|
|
// left face
|
|
|
|
{
|
|
|
|
osg::ref_ptr<osg::Camera> camera = new osg::Camera;
|
|
|
|
camera->setName("Left face camera");
|
|
|
|
camera->setGraphicsContext(gc.get());
|
|
|
|
camera->setViewport(new osg::Viewport(0,0,camera_width, camera_height));
|
|
|
|
camera->setDrawBuffer(buffer);
|
|
|
|
camera->setReadBuffer(buffer);
|
|
|
|
camera->setAllowEventFocus(false);
|
|
|
|
|
|
|
|
// tell the camera to use OpenGL frame buffer object where supported.
|
|
|
|
camera->setRenderTargetImplementation(renderTargetImplementation);
|
|
|
|
|
|
|
|
// attach the texture and use it as the color buffer.
|
|
|
|
camera->attach(osg::Camera::COLOR_BUFFER, texture, 0, osg::TextureCubeMap::NEGATIVE_X);
|
|
|
|
|
|
|
|
addSlave(camera.get(), osg::Matrixd(), osg::Matrixd::rotate(osg::inDegrees(-90.0f), 0.0,1.0,0.0) * osg::Matrixd::rotate(osg::inDegrees(-90.0f), 0.0,0.0,1.0));
|
|
|
|
}
|
|
|
|
|
|
|
|
// right face
|
|
|
|
{
|
|
|
|
osg::ref_ptr<osg::Camera> camera = new osg::Camera;
|
|
|
|
camera->setName("Right face camera");
|
|
|
|
camera->setGraphicsContext(gc.get());
|
|
|
|
camera->setViewport(new osg::Viewport(0,0,camera_width, camera_height));
|
|
|
|
camera->setDrawBuffer(buffer);
|
|
|
|
camera->setReadBuffer(buffer);
|
|
|
|
camera->setAllowEventFocus(false);
|
|
|
|
|
|
|
|
// tell the camera to use OpenGL frame buffer object where supported.
|
|
|
|
camera->setRenderTargetImplementation(renderTargetImplementation);
|
|
|
|
|
|
|
|
// attach the texture and use it as the color buffer.
|
|
|
|
camera->attach(osg::Camera::COLOR_BUFFER, texture, 0, osg::TextureCubeMap::POSITIVE_X);
|
|
|
|
|
|
|
|
addSlave(camera.get(), osg::Matrixd(), osg::Matrixd::rotate(osg::inDegrees(90.0f), 0.0,1.0,0.0 ) * osg::Matrixd::rotate(osg::inDegrees(90.0f), 0.0,0.0,1.0));
|
|
|
|
}
|
|
|
|
|
|
|
|
// bottom face
|
|
|
|
{
|
|
|
|
osg::ref_ptr<osg::Camera> camera = new osg::Camera;
|
|
|
|
camera->setGraphicsContext(gc.get());
|
|
|
|
camera->setName("Bottom face camera");
|
|
|
|
camera->setViewport(new osg::Viewport(0,0,camera_width, camera_height));
|
|
|
|
camera->setDrawBuffer(buffer);
|
|
|
|
camera->setReadBuffer(buffer);
|
|
|
|
camera->setAllowEventFocus(false);
|
|
|
|
|
|
|
|
// tell the camera to use OpenGL frame buffer object where supported.
|
|
|
|
camera->setRenderTargetImplementation(renderTargetImplementation);
|
|
|
|
|
|
|
|
// attach the texture and use it as the color buffer.
|
|
|
|
camera->attach(osg::Camera::COLOR_BUFFER, texture, 0, osg::TextureCubeMap::NEGATIVE_Z);
|
|
|
|
|
|
|
|
addSlave(camera.get(), osg::Matrixd(), osg::Matrixd::rotate(osg::inDegrees(90.0f), 1.0,0.0,0.0) * osg::Matrixd::rotate(osg::inDegrees(180.0f), 0.0,0.0,1.0));
|
|
|
|
}
|
|
|
|
|
|
|
|
// back face
|
|
|
|
{
|
|
|
|
osg::ref_ptr<osg::Camera> camera = new osg::Camera;
|
|
|
|
camera->setName("Back face camera");
|
|
|
|
camera->setGraphicsContext(gc.get());
|
|
|
|
camera->setViewport(new osg::Viewport(0,0,camera_width, camera_height));
|
|
|
|
camera->setDrawBuffer(buffer);
|
|
|
|
camera->setReadBuffer(buffer);
|
|
|
|
camera->setAllowEventFocus(false);
|
|
|
|
|
|
|
|
// tell the camera to use OpenGL frame buffer object where supported.
|
|
|
|
camera->setRenderTargetImplementation(renderTargetImplementation);
|
|
|
|
|
|
|
|
// attach the texture and use it as the color buffer.
|
|
|
|
camera->attach(osg::Camera::COLOR_BUFFER, texture, 0, osg::TextureCubeMap::NEGATIVE_Y);
|
|
|
|
|
|
|
|
addSlave(camera.get(), osg::Matrixd(), osg::Matrixd::rotate(osg::inDegrees(180.0f), 1.0,0.0,0.0));
|
|
|
|
}
|
|
|
|
|
|
|
|
getCamera()->setProjectionMatrixAsPerspective(90.0f, 1.0, 1, 1000.0);
|
|
|
|
|
|
|
|
// distortion correction set up.
|
|
|
|
{
|
|
|
|
osg::Geode* geode = new osg::Geode();
|
2008-01-28 23:41:42 +08:00
|
|
|
geode->addDrawable(create3DSphericalDisplayDistortionMesh(osg::Vec3(0.0f,0.0f,0.0f), osg::Vec3(width,0.0f,0.0f), osg::Vec3(0.0f,height,0.0f), radius, collar, applyIntensityMapAsColours ? intensityMap : 0, projectorMatrix));
|
2007-09-02 00:56:53 +08:00
|
|
|
|
|
|
|
// new we need to add the texture to the mesh, we do so by creating a
|
|
|
|
// StateSet to contain the Texture StateAttribute.
|
|
|
|
osg::StateSet* stateset = geode->getOrCreateStateSet();
|
|
|
|
stateset->setTextureAttributeAndModes(0, texture,osg::StateAttribute::ON);
|
|
|
|
stateset->setMode(GL_LIGHTING,osg::StateAttribute::OFF);
|
|
|
|
|
2007-10-31 20:55:59 +08:00
|
|
|
if (!applyIntensityMapAsColours && intensityMap)
|
2007-09-26 03:14:29 +08:00
|
|
|
{
|
|
|
|
stateset->setTextureAttributeAndModes(1, new osg::Texture2D(intensityMap), osg::StateAttribute::ON);
|
|
|
|
}
|
|
|
|
|
2007-09-02 00:56:53 +08:00
|
|
|
osg::ref_ptr<osg::Camera> camera = new osg::Camera;
|
|
|
|
camera->setGraphicsContext(gc.get());
|
|
|
|
camera->setClearMask(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT );
|
2008-01-28 23:41:42 +08:00
|
|
|
camera->setClearColor( osg::Vec4(0.0,0.0,0.0,1.0) );
|
2007-09-02 00:56:53 +08:00
|
|
|
camera->setViewport(new osg::Viewport(0, 0, width, height));
|
|
|
|
GLenum buffer = traits->doubleBuffer ? GL_BACK : GL_FRONT;
|
|
|
|
camera->setDrawBuffer(buffer);
|
|
|
|
camera->setReadBuffer(buffer);
|
|
|
|
camera->setReferenceFrame(osg::Camera::ABSOLUTE_RF);
|
|
|
|
camera->setAllowEventFocus(false);
|
2008-01-28 23:41:42 +08:00
|
|
|
camera->setInheritanceMask(camera->getInheritanceMask() & ~osg::CullSettings::CLEAR_COLOR & ~osg::CullSettings::COMPUTE_NEAR_FAR_MODE);
|
2007-09-02 00:56:53 +08:00
|
|
|
//camera->setComputeNearFarMode(osg::CullSettings::DO_NOT_COMPUTE_NEAR_FAR);
|
|
|
|
|
|
|
|
camera->setProjectionMatrixAsOrtho2D(0,width,0,height);
|
|
|
|
camera->setViewMatrix(osg::Matrix::identity());
|
|
|
|
|
|
|
|
// add subgraph to render
|
|
|
|
camera->addChild(geode);
|
|
|
|
|
|
|
|
camera->setName("DistortionCorrectionCamera");
|
|
|
|
|
|
|
|
addSlave(camera.get(), osg::Matrixd(), osg::Matrixd(), false);
|
|
|
|
}
|
|
|
|
|
|
|
|
getCamera()->setNearFarRatio(0.0001f);
|
|
|
|
|
|
|
|
if (getLightingMode()==osg::View::HEADLIGHT)
|
|
|
|
{
|
|
|
|
// set a local light source for headlight to ensure that lighting is consistent across sides of cube.
|
|
|
|
getLight()->setPosition(osg::Vec4(0.0f,0.0f,0.0f,1.0f));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-01-28 23:41:42 +08:00
|
|
|
static osg::Geometry* createParoramicSphericalDisplayDistortionMesh(const osg::Vec3& origin, const osg::Vec3& widthVector, const osg::Vec3& heightVector, double sphere_radius, double collar_radius, osg::Image* intensityMap, const osg::Matrix& projectorMatrix)
|
2007-09-26 03:14:29 +08:00
|
|
|
{
|
|
|
|
osg::Vec3d center(0.0,0.0,0.0);
|
|
|
|
osg::Vec3d eye(0.0,0.0,0.0);
|
|
|
|
|
|
|
|
bool centerProjection = false;
|
|
|
|
|
|
|
|
double distance = sqrt(sphere_radius*sphere_radius - collar_radius*collar_radius);
|
|
|
|
bool flip = false;
|
|
|
|
bool texcoord_flip = false;
|
|
|
|
|
|
|
|
osg::Vec3d projector = eye - osg::Vec3d(0.0,0.0, distance);
|
|
|
|
|
|
|
|
|
|
|
|
osg::notify(osg::INFO)<<"createParoramicSphericalDisplayDistortionMesh : Projector position = "<<projector<<std::endl;
|
|
|
|
osg::notify(osg::INFO)<<"createParoramicSphericalDisplayDistortionMesh : distance = "<<distance<<std::endl;
|
|
|
|
|
|
|
|
// create the quad to visualize.
|
|
|
|
osg::Geometry* geometry = new osg::Geometry();
|
|
|
|
|
|
|
|
geometry->setSupportsDisplayList(false);
|
|
|
|
|
|
|
|
osg::Vec3 xAxis(widthVector);
|
|
|
|
float width = widthVector.length();
|
|
|
|
xAxis /= width;
|
|
|
|
|
|
|
|
osg::Vec3 yAxis(heightVector);
|
|
|
|
float height = heightVector.length();
|
|
|
|
yAxis /= height;
|
|
|
|
|
|
|
|
int noSteps = 160;
|
|
|
|
|
|
|
|
osg::Vec3Array* vertices = new osg::Vec3Array;
|
|
|
|
osg::Vec2Array* texcoords0 = new osg::Vec2Array;
|
2007-10-31 20:55:59 +08:00
|
|
|
osg::Vec2Array* texcoords1 = intensityMap==0 ? new osg::Vec2Array : 0;
|
2007-09-26 03:14:29 +08:00
|
|
|
osg::Vec4Array* colors = new osg::Vec4Array;
|
|
|
|
|
|
|
|
osg::Vec3 bottom = origin;
|
|
|
|
osg::Vec3 dx = xAxis*(width/((float)(noSteps-2)));
|
|
|
|
osg::Vec3 dy = yAxis*(height/((float)(noSteps-1)));
|
|
|
|
|
|
|
|
osg::Vec3 top = origin + yAxis*height;
|
|
|
|
|
2008-01-28 23:41:42 +08:00
|
|
|
osg::Vec3 screenCenter = origin + widthVector*0.5f + heightVector*0.5f;
|
2007-09-26 03:14:29 +08:00
|
|
|
float screenRadius = heightVector.length() * 0.5f;
|
|
|
|
|
|
|
|
double rotation = 0.0;
|
|
|
|
|
2008-01-28 23:41:42 +08:00
|
|
|
geometry->getOrCreateStateSet()->setMode(GL_CULL_FACE, osg::StateAttribute::OFF | osg::StateAttribute::PROTECTED);
|
|
|
|
|
|
|
|
for(int i=0;i<noSteps;++i)
|
2007-09-26 03:14:29 +08:00
|
|
|
{
|
|
|
|
osg::Vec3 cursor = bottom+dy*(float)i;
|
2008-01-28 23:41:42 +08:00
|
|
|
for(int j=0;j<noSteps;++j)
|
2007-09-26 03:14:29 +08:00
|
|
|
{
|
2008-01-28 23:41:42 +08:00
|
|
|
osg::Vec2 texcoord(double(i)/double(noSteps-1), double(j)/double(noSteps-1));
|
|
|
|
double theta = texcoord.x() * 2.0 * osg::PI;
|
|
|
|
double phi = (1.0-texcoord.y()) * osg::PI;
|
2007-09-26 03:14:29 +08:00
|
|
|
|
2008-01-28 23:41:42 +08:00
|
|
|
if (texcoord_flip) texcoord.y() = 1.0f - texcoord.y();
|
2007-09-26 03:14:29 +08:00
|
|
|
|
2008-01-28 23:41:42 +08:00
|
|
|
osg::Vec3 pos(sin(phi)*sin(theta), sin(phi)*cos(theta), cos(phi));
|
|
|
|
pos = pos*projectorMatrix;
|
|
|
|
|
|
|
|
double alpha = atan2(pos.x(), pos.y());
|
|
|
|
if (alpha<0.0) alpha += 2.0*osg::PI;
|
|
|
|
|
|
|
|
double beta = atan2(sqrt(pos.x()*pos.x() + pos.y()*pos.y()), pos.z());
|
|
|
|
if (beta<0.0) beta += 2.0*osg::PI;
|
2007-09-26 03:14:29 +08:00
|
|
|
|
2008-01-29 03:42:16 +08:00
|
|
|
double gamma = atan2(sqrt(double(pos.x()*pos.x() + pos.y()*pos.y())), double(pos.z()+distance));
|
2008-01-28 23:41:42 +08:00
|
|
|
if (gamma<0.0) gamma += 2.0*osg::PI;
|
|
|
|
|
|
|
|
|
|
|
|
osg::Vec3 v = screenCenter + osg::Vec3(sin(alpha)*gamma*2.0/osg::PI, -cos(alpha)*gamma*2.0/osg::PI, 0.0f)*screenRadius;
|
|
|
|
|
2007-09-26 03:14:29 +08:00
|
|
|
if (flip)
|
2008-01-28 23:41:42 +08:00
|
|
|
vertices->push_back(osg::Vec3(v.x(), top.y()-(v.y()-origin.y()),v.z()));
|
2007-09-26 03:14:29 +08:00
|
|
|
else
|
2008-01-28 23:41:42 +08:00
|
|
|
vertices->push_back(v);
|
2007-10-31 20:55:59 +08:00
|
|
|
|
2008-01-28 23:41:42 +08:00
|
|
|
texcoords0->push_back( texcoord );
|
|
|
|
|
|
|
|
osg::Vec2 texcoord1(alpha/(2.0*osg::PI), 1.0f - beta/osg::PI);
|
2007-10-31 20:55:59 +08:00
|
|
|
if (intensityMap)
|
|
|
|
{
|
|
|
|
colors->push_back(intensityMap->getColor(texcoord1));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
colors->push_back(osg::Vec4(1.0f,1.0f,1.0f,1.0f));
|
|
|
|
if (texcoords1) texcoords1->push_back( texcoord1 );
|
|
|
|
}
|
2007-09-26 03:14:29 +08:00
|
|
|
|
|
|
|
|
2008-01-28 23:41:42 +08:00
|
|
|
}
|
2007-09-26 03:14:29 +08:00
|
|
|
}
|
|
|
|
|
2008-01-28 23:41:42 +08:00
|
|
|
|
2007-09-26 03:14:29 +08:00
|
|
|
// pass the created vertex array to the points geometry object.
|
|
|
|
geometry->setVertexArray(vertices);
|
|
|
|
|
|
|
|
geometry->setColorArray(colors);
|
|
|
|
geometry->setColorBinding(osg::Geometry::BIND_PER_VERTEX);
|
|
|
|
|
|
|
|
geometry->setTexCoordArray(0,texcoords0);
|
2007-10-31 20:55:59 +08:00
|
|
|
if (texcoords1) geometry->setTexCoordArray(1,texcoords1);
|
2007-09-26 03:14:29 +08:00
|
|
|
|
2008-01-28 23:41:42 +08:00
|
|
|
osg::DrawElementsUShort* elements = new osg::DrawElementsUShort(osg::PrimitiveSet::TRIANGLES);
|
|
|
|
geometry->addPrimitiveSet(elements);
|
|
|
|
|
|
|
|
for(int i=0;i<noSteps-1;++i)
|
2007-09-26 03:14:29 +08:00
|
|
|
{
|
2008-01-28 23:41:42 +08:00
|
|
|
for(int j=0;j<noSteps-1;++j)
|
2007-09-26 03:14:29 +08:00
|
|
|
{
|
2008-01-28 23:41:42 +08:00
|
|
|
int i1 = j+(i+1)*noSteps;
|
|
|
|
int i2 = j+(i)*noSteps;
|
|
|
|
int i3 = j+1+(i)*noSteps;
|
|
|
|
int i4 = j+1+(i+1)*noSteps;
|
|
|
|
|
|
|
|
osg::Vec3& v1 = (*vertices)[i1];
|
|
|
|
osg::Vec3& v2 = (*vertices)[i2];
|
|
|
|
osg::Vec3& v3 = (*vertices)[i3];
|
|
|
|
osg::Vec3& v4 = (*vertices)[i4];
|
|
|
|
|
|
|
|
if ((v1-screenCenter).length()>screenRadius) continue;
|
|
|
|
if ((v2-screenCenter).length()>screenRadius) continue;
|
|
|
|
if ((v3-screenCenter).length()>screenRadius) continue;
|
|
|
|
if ((v4-screenCenter).length()>screenRadius) continue;
|
|
|
|
|
|
|
|
elements->push_back(i1);
|
|
|
|
elements->push_back(i2);
|
|
|
|
elements->push_back(i3);
|
|
|
|
|
|
|
|
elements->push_back(i1);
|
|
|
|
elements->push_back(i3);
|
|
|
|
elements->push_back(i4);
|
2007-09-26 03:14:29 +08:00
|
|
|
}
|
|
|
|
}
|
2008-01-28 23:41:42 +08:00
|
|
|
|
2007-09-26 03:14:29 +08:00
|
|
|
return geometry;
|
|
|
|
}
|
|
|
|
|
2008-01-28 23:41:42 +08:00
|
|
|
void View::setUpViewForPanoramicSphericalDisplay(double radius, double collar, unsigned int screenNum, osg::Image* intensityMap, const osg::Matrixd& projectorMatrix)
|
2007-09-02 00:56:53 +08:00
|
|
|
{
|
2007-09-26 03:14:29 +08:00
|
|
|
osg::notify(osg::INFO)<<"View::setUpViewForPanoramicSphericalDisplay(rad="<<radius<<", cllr="<<collar<<", sn="<<screenNum<<", im="<<intensityMap<<")"<<std::endl;
|
|
|
|
|
|
|
|
osg::GraphicsContext::WindowingSystemInterface* wsi = osg::GraphicsContext::getWindowingSystemInterface();
|
|
|
|
if (!wsi)
|
|
|
|
{
|
|
|
|
osg::notify(osg::NOTICE)<<"Error, no WindowSystemInterface available, cannot create windows."<<std::endl;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
osg::GraphicsContext::ScreenIdentifier si;
|
|
|
|
si.readDISPLAY();
|
|
|
|
|
|
|
|
// displayNum has not been set so reset it to 0.
|
|
|
|
if (si.displayNum<0) si.displayNum = 0;
|
|
|
|
|
|
|
|
si.screenNum = screenNum;
|
|
|
|
|
2007-09-28 21:42:41 +08:00
|
|
|
unsigned int width, height;
|
|
|
|
wsi->getScreenResolution(si, width, height);
|
|
|
|
|
2007-09-26 03:14:29 +08:00
|
|
|
osg::ref_ptr<osg::GraphicsContext::Traits> traits = new osg::GraphicsContext::Traits;
|
|
|
|
traits->hostName = si.hostName;
|
|
|
|
traits->displayNum = si.displayNum;
|
|
|
|
traits->screenNum = si.screenNum;
|
|
|
|
traits->x = 0;
|
|
|
|
traits->y = 0;
|
|
|
|
traits->width = width;
|
|
|
|
traits->height = height;
|
|
|
|
traits->windowDecoration = false;
|
|
|
|
traits->doubleBuffer = true;
|
|
|
|
traits->sharedContext = 0;
|
|
|
|
|
|
|
|
|
2007-10-31 20:55:59 +08:00
|
|
|
bool applyIntensityMapAsColours = true;
|
|
|
|
|
2007-09-26 03:14:29 +08:00
|
|
|
osg::ref_ptr<osg::GraphicsContext> gc = osg::GraphicsContext::createGraphicsContext(traits.get());
|
|
|
|
if (!gc)
|
|
|
|
{
|
|
|
|
osg::notify(osg::NOTICE)<<"GraphicsWindow has not been created successfully."<<std::endl;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
int tex_width = width;
|
|
|
|
int tex_height = height;
|
|
|
|
|
|
|
|
int camera_width = tex_width;
|
|
|
|
int camera_height = tex_height;
|
|
|
|
|
|
|
|
osg::TextureRectangle* texture = new osg::TextureRectangle;
|
|
|
|
|
|
|
|
texture->setTextureSize(tex_width, tex_height);
|
|
|
|
texture->setInternalFormat(GL_RGB);
|
|
|
|
texture->setFilter(osg::Texture::MIN_FILTER,osg::Texture::LINEAR);
|
|
|
|
texture->setFilter(osg::Texture::MAG_FILTER,osg::Texture::LINEAR);
|
2007-10-31 19:06:33 +08:00
|
|
|
texture->setWrap(osg::Texture::WRAP_S,osg::Texture::CLAMP_TO_EDGE);
|
|
|
|
texture->setWrap(osg::Texture::WRAP_T,osg::Texture::CLAMP_TO_EDGE);
|
2007-09-26 03:14:29 +08:00
|
|
|
|
|
|
|
#if 0
|
|
|
|
osg::Camera::RenderTargetImplementation renderTargetImplementation = osg::Camera::SEPERATE_WINDOW;
|
|
|
|
GLenum buffer = GL_FRONT;
|
|
|
|
#else
|
|
|
|
osg::Camera::RenderTargetImplementation renderTargetImplementation = osg::Camera::FRAME_BUFFER_OBJECT;
|
|
|
|
GLenum buffer = GL_FRONT;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// front face
|
|
|
|
{
|
|
|
|
osg::ref_ptr<osg::Camera> camera = new osg::Camera;
|
|
|
|
camera->setName("Front face camera");
|
|
|
|
camera->setGraphicsContext(gc.get());
|
|
|
|
camera->setViewport(new osg::Viewport(0,0,camera_width, camera_height));
|
|
|
|
camera->setDrawBuffer(buffer);
|
|
|
|
camera->setReadBuffer(buffer);
|
|
|
|
camera->setAllowEventFocus(false);
|
|
|
|
// tell the camera to use OpenGL frame buffer object where supported.
|
|
|
|
camera->setRenderTargetImplementation(renderTargetImplementation);
|
|
|
|
|
|
|
|
// attach the texture and use it as the color buffer.
|
|
|
|
camera->attach(osg::Camera::COLOR_BUFFER, texture);
|
|
|
|
|
|
|
|
addSlave(camera.get(), osg::Matrixd(), osg::Matrixd());
|
|
|
|
}
|
|
|
|
|
|
|
|
// distortion correction set up.
|
|
|
|
{
|
|
|
|
osg::Geode* geode = new osg::Geode();
|
2008-01-28 23:41:42 +08:00
|
|
|
geode->addDrawable(createParoramicSphericalDisplayDistortionMesh(osg::Vec3(0.0f,0.0f,0.0f), osg::Vec3(width,0.0f,0.0f), osg::Vec3(0.0f,height,0.0f), radius, collar, applyIntensityMapAsColours ? intensityMap : 0, projectorMatrix));
|
2007-09-26 03:14:29 +08:00
|
|
|
|
|
|
|
// new we need to add the texture to the mesh, we do so by creating a
|
|
|
|
// StateSet to contain the Texture StateAttribute.
|
|
|
|
osg::StateSet* stateset = geode->getOrCreateStateSet();
|
|
|
|
stateset->setTextureAttributeAndModes(0, texture,osg::StateAttribute::ON);
|
|
|
|
stateset->setMode(GL_LIGHTING,osg::StateAttribute::OFF);
|
|
|
|
|
|
|
|
osg::TexMat* texmat = new osg::TexMat;
|
|
|
|
texmat->setScaleByTextureRectangleSize(true);
|
|
|
|
stateset->setTextureAttributeAndModes(0, texmat, osg::StateAttribute::ON);
|
|
|
|
|
2007-10-31 20:55:59 +08:00
|
|
|
if (!applyIntensityMapAsColours && intensityMap)
|
2007-09-26 03:14:29 +08:00
|
|
|
{
|
|
|
|
stateset->setTextureAttributeAndModes(1, new osg::Texture2D(intensityMap), osg::StateAttribute::ON);
|
|
|
|
}
|
|
|
|
|
|
|
|
osg::ref_ptr<osg::Camera> camera = new osg::Camera;
|
|
|
|
camera->setGraphicsContext(gc.get());
|
|
|
|
camera->setClearMask(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT );
|
2008-01-28 23:41:42 +08:00
|
|
|
camera->setClearColor( osg::Vec4(0.0,0.0,0.0,1.0) );
|
2007-09-26 03:14:29 +08:00
|
|
|
camera->setViewport(new osg::Viewport(0, 0, width, height));
|
|
|
|
GLenum buffer = traits->doubleBuffer ? GL_BACK : GL_FRONT;
|
|
|
|
camera->setDrawBuffer(buffer);
|
|
|
|
camera->setReadBuffer(buffer);
|
|
|
|
camera->setReferenceFrame(osg::Camera::ABSOLUTE_RF);
|
|
|
|
camera->setAllowEventFocus(false);
|
2008-01-28 23:41:42 +08:00
|
|
|
camera->setInheritanceMask(camera->getInheritanceMask() & ~osg::CullSettings::CLEAR_COLOR & ~osg::CullSettings::COMPUTE_NEAR_FAR_MODE);
|
2007-09-26 03:14:29 +08:00
|
|
|
//camera->setComputeNearFarMode(osg::CullSettings::DO_NOT_COMPUTE_NEAR_FAR);
|
|
|
|
|
|
|
|
camera->setProjectionMatrixAsOrtho2D(0,width,0,height);
|
|
|
|
camera->setViewMatrix(osg::Matrix::identity());
|
|
|
|
|
|
|
|
// add subgraph to render
|
|
|
|
camera->addChild(geode);
|
|
|
|
|
|
|
|
camera->setName("DistortionCorrectionCamera");
|
|
|
|
|
|
|
|
addSlave(camera.get(), osg::Matrixd(), osg::Matrixd(), false);
|
|
|
|
}
|
2007-09-02 00:56:53 +08:00
|
|
|
}
|
|
|
|
|
2008-05-07 22:17:15 +08:00
|
|
|
void View::setUpViewForWoWVxDisplay(unsigned int screenNum, unsigned char wow_content, unsigned char wow_factor, unsigned char wow_offset, float wow_disparity_Zd, float wow_disparity_vz, float wow_disparity_M, float wow_disparity_C)
|
|
|
|
{
|
|
|
|
osg::notify(osg::INFO)<<"View::setUpViewForWoWVxDisplay(...)"<<std::endl;
|
|
|
|
|
|
|
|
osg::GraphicsContext::WindowingSystemInterface* wsi = osg::GraphicsContext::getWindowingSystemInterface();
|
|
|
|
if (!wsi)
|
|
|
|
{
|
|
|
|
osg::notify(osg::NOTICE)<<"Error, no WindowSystemInterface available, cannot create windows."<<std::endl;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
osg::GraphicsContext::ScreenIdentifier si;
|
|
|
|
si.readDISPLAY();
|
|
|
|
|
|
|
|
// displayNum has not been set so reset it to 0.
|
|
|
|
if (si.displayNum<0) si.displayNum = 0;
|
|
|
|
|
|
|
|
si.screenNum = screenNum;
|
|
|
|
|
|
|
|
unsigned int width, height;
|
|
|
|
wsi->getScreenResolution(si, width, height);
|
|
|
|
|
|
|
|
osg::ref_ptr<osg::GraphicsContext::Traits> traits = new osg::GraphicsContext::Traits;
|
|
|
|
traits->hostName = si.hostName;
|
|
|
|
traits->displayNum = si.displayNum;
|
|
|
|
traits->screenNum = si.screenNum;
|
|
|
|
traits->x = 0;
|
|
|
|
traits->y = 0;
|
|
|
|
traits->width = width;
|
|
|
|
traits->height = height;
|
|
|
|
traits->windowDecoration = false;
|
|
|
|
traits->doubleBuffer = true;
|
|
|
|
traits->sharedContext = 0;
|
|
|
|
|
|
|
|
|
|
|
|
osg::ref_ptr<osg::GraphicsContext> gc = osg::GraphicsContext::createGraphicsContext(traits.get());
|
|
|
|
if (!gc)
|
|
|
|
{
|
|
|
|
osg::notify(osg::NOTICE)<<"GraphicsWindow has not been created successfully."<<std::endl;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
int tex_width = width;
|
|
|
|
int tex_height = height;
|
|
|
|
|
|
|
|
int camera_width = tex_width;
|
|
|
|
int camera_height = tex_height;
|
|
|
|
|
|
|
|
osg::Texture2D* texture = new osg::Texture2D;
|
|
|
|
texture->setTextureSize(tex_width, tex_height);
|
|
|
|
texture->setInternalFormat(GL_RGB);
|
|
|
|
texture->setFilter(osg::Texture2D::MIN_FILTER,osg::Texture2D::LINEAR);
|
|
|
|
texture->setFilter(osg::Texture2D::MAG_FILTER,osg::Texture2D::LINEAR);
|
|
|
|
|
|
|
|
osg::Texture2D* textureD = new osg::Texture2D;
|
|
|
|
textureD->setTextureSize(tex_width, tex_height);
|
|
|
|
textureD->setInternalFormat(GL_DEPTH_COMPONENT);
|
|
|
|
textureD->setFilter(osg::Texture2D::MIN_FILTER,osg::Texture2D::LINEAR);
|
|
|
|
textureD->setFilter(osg::Texture2D::MAG_FILTER,osg::Texture2D::LINEAR);
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
osg::Camera::RenderTargetImplementation renderTargetImplementation = osg::Camera::SEPERATE_WINDOW;
|
|
|
|
GLenum buffer = GL_FRONT;
|
|
|
|
#else
|
|
|
|
osg::Camera::RenderTargetImplementation renderTargetImplementation = osg::Camera::FRAME_BUFFER_OBJECT;
|
|
|
|
GLenum buffer = GL_FRONT;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// front face
|
|
|
|
{
|
|
|
|
osg::ref_ptr<osg::Camera> camera = new osg::Camera;
|
|
|
|
camera->setName("Front face camera");
|
|
|
|
camera->setGraphicsContext(gc.get());
|
|
|
|
camera->setViewport(new osg::Viewport(0,0,camera_width, camera_height));
|
|
|
|
camera->setDrawBuffer(buffer);
|
|
|
|
camera->setReadBuffer(buffer);
|
|
|
|
camera->setAllowEventFocus(false);
|
|
|
|
// tell the camera to use OpenGL frame buffer object where supported.
|
|
|
|
camera->setRenderTargetImplementation(renderTargetImplementation);
|
|
|
|
|
|
|
|
// attach the texture and use it as the color buffer.
|
|
|
|
camera->attach(osg::Camera::COLOR_BUFFER, texture);
|
|
|
|
camera->attach(osg::Camera::DEPTH_BUFFER, textureD);
|
|
|
|
|
|
|
|
addSlave(camera.get(), osg::Matrixd(), osg::Matrixd());
|
|
|
|
}
|
|
|
|
|
|
|
|
// WoW display set up.
|
|
|
|
{
|
|
|
|
osg::Texture1D *textureHeader = new osg::Texture1D();
|
|
|
|
// Set up the header
|
|
|
|
{
|
|
|
|
unsigned char header[]= {0xF1,wow_content,wow_factor,wow_offset,0x00,0x00,0x00,0x00,0x00,0x00};
|
|
|
|
// Calc the CRC32
|
|
|
|
{
|
|
|
|
unsigned long _register = 0;
|
|
|
|
for(int i = 0; i < 10; ++i) {
|
|
|
|
unsigned char mask = 0x80;
|
|
|
|
unsigned char byte = header[i];
|
|
|
|
for (int j = 0; j < 8; ++j)
|
|
|
|
{
|
|
|
|
bool topBit = (_register & 0x80000000) != 0;
|
|
|
|
_register <<= 1;
|
|
|
|
_register ^= ((byte & mask) != 0? 0x1: 0x0);
|
|
|
|
if (topBit)
|
|
|
|
{
|
|
|
|
_register ^= 0x04c11db7;
|
|
|
|
}
|
|
|
|
mask >>= 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
unsigned char *p = (unsigned char*) &_register;
|
|
|
|
for(size_t i = 0; i < 4; ++i)
|
|
|
|
{
|
|
|
|
header[i+6] = p[3-i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
osg::ref_ptr<osg::Image> imageheader = new osg::Image();
|
|
|
|
imageheader->allocateImage(256,1,1,GL_LUMINANCE,GL_UNSIGNED_BYTE);
|
|
|
|
{
|
|
|
|
unsigned char *cheader = imageheader->data();
|
|
|
|
for (int x=0; x<256; ++x){
|
|
|
|
cheader[x] = 0;
|
|
|
|
}
|
|
|
|
for (int x=0; x<=9; ++x){
|
|
|
|
for (int y=7; y>=0; --y){
|
|
|
|
int i = 2*(7-y)+16*x;
|
|
|
|
cheader[i] = (((1<<(y))&(header[x])) << (7-(y)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
textureHeader->setImage(imageheader.get());
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create the Screen Aligned Quad
|
|
|
|
osg::Geode* geode = new osg::Geode();
|
|
|
|
{
|
|
|
|
osg::Geometry* geom = new osg::Geometry;
|
|
|
|
|
|
|
|
osg::Vec3Array* vertices = new osg::Vec3Array;
|
|
|
|
vertices->push_back(osg::Vec3(0,height,0));
|
|
|
|
vertices->push_back(osg::Vec3(0,0,0));
|
|
|
|
vertices->push_back(osg::Vec3(width,0,0));
|
|
|
|
vertices->push_back(osg::Vec3(width,height,0));
|
|
|
|
geom->setVertexArray(vertices);
|
|
|
|
|
|
|
|
osg::Vec2Array* tex = new osg::Vec2Array;
|
|
|
|
tex->push_back(osg::Vec2(0,1));
|
|
|
|
tex->push_back(osg::Vec2(0,0));
|
|
|
|
tex->push_back(osg::Vec2(1,0));
|
|
|
|
tex->push_back(osg::Vec2(1,1));
|
|
|
|
geom->setTexCoordArray(0,tex);
|
|
|
|
|
|
|
|
geom->addPrimitiveSet(new osg::DrawArrays(GL_QUADS,0,4));
|
|
|
|
geode->addDrawable(geom);
|
|
|
|
|
|
|
|
// new we need to add the textures to the quad, and setting up the shader.
|
|
|
|
osg::StateSet* stateset = geode->getOrCreateStateSet();
|
|
|
|
stateset->setTextureAttributeAndModes(0, textureHeader,osg::StateAttribute::ON);
|
|
|
|
stateset->setTextureAttributeAndModes(1, texture,osg::StateAttribute::ON);
|
|
|
|
stateset->setTextureAttributeAndModes(2, textureD,osg::StateAttribute::ON);
|
|
|
|
stateset->setMode(GL_LIGHTING,osg::StateAttribute::OFF);
|
|
|
|
|
|
|
|
osg::ref_ptr<osg::Program> programShader = new osg::Program();
|
|
|
|
stateset->setAttribute(programShader.get(), osg::StateAttribute::ON);
|
|
|
|
stateset->addUniform( new osg::Uniform("wow_width", (int)width));
|
|
|
|
stateset->addUniform( new osg::Uniform("wow_height", (int)height));
|
|
|
|
stateset->addUniform( new osg::Uniform("wow_disparity_M", wow_disparity_M));
|
|
|
|
stateset->addUniform( new osg::Uniform("wow_disparity_Zd", wow_disparity_Zd));
|
|
|
|
stateset->addUniform( new osg::Uniform("wow_disparity_vz", wow_disparity_vz));
|
|
|
|
stateset->addUniform( new osg::Uniform("wow_disparity_C", wow_disparity_C));
|
|
|
|
|
|
|
|
stateset->addUniform(new osg::Uniform("wow_header", 0));
|
|
|
|
stateset->addUniform(new osg::Uniform("wow_tcolor", 1));
|
|
|
|
stateset->addUniform(new osg::Uniform("wow_tdepth", 2));
|
|
|
|
|
|
|
|
osg::Shader *frag = new osg::Shader(osg::Shader::FRAGMENT);
|
|
|
|
frag->setShaderSource(" "\
|
|
|
|
" uniform sampler1D wow_header; " \
|
|
|
|
" uniform sampler2D wow_tcolor; " \
|
|
|
|
" uniform sampler2D wow_tdepth; " \
|
|
|
|
" " \
|
|
|
|
" uniform int wow_width; " \
|
|
|
|
" uniform int wow_height; " \
|
|
|
|
" uniform float wow_disparity_M; " \
|
|
|
|
" uniform float wow_disparity_Zd; " \
|
|
|
|
" uniform float wow_disparity_vz; " \
|
|
|
|
" uniform float wow_disparity_C; " \
|
|
|
|
" " \
|
|
|
|
" float disparity(float Z) " \
|
|
|
|
" { " \
|
|
|
|
" return (wow_disparity_M*(1.0-(wow_disparity_vz/(Z-wow_disparity_Zd+wow_disparity_vz))) " \
|
|
|
|
" + wow_disparity_C) / 255.0; " \
|
|
|
|
" } " \
|
|
|
|
" " \
|
|
|
|
" void main() " \
|
|
|
|
" { " \
|
|
|
|
" vec2 pos = (gl_FragCoord.xy / vec2(wow_width/2,wow_height) ); " \
|
|
|
|
" if (gl_FragCoord.x > float(wow_width/2)) " \
|
|
|
|
" { " \
|
|
|
|
" gl_FragColor = vec4(disparity(( texture2D(wow_tdepth, pos - vec2(1,0))).z)); " \
|
|
|
|
" } " \
|
|
|
|
" else{ " \
|
|
|
|
" gl_FragColor = texture2D(wow_tcolor, pos); " \
|
|
|
|
" } " \
|
|
|
|
" if ( (gl_FragCoord.y >= float(wow_height-1)) && (gl_FragCoord.x < 256.0) ) " \
|
|
|
|
" { " \
|
|
|
|
" float pos = gl_FragCoord.x/256.0; " \
|
|
|
|
" float blue = texture1D(wow_header, pos).b; " \
|
|
|
|
" if ( blue < 0.5) " \
|
|
|
|
" gl_FragColor.b -=0.5; " \
|
|
|
|
" else " \
|
|
|
|
" gl_FragColor.b += 0.5; " \
|
|
|
|
" } " \
|
|
|
|
" } " );
|
|
|
|
|
|
|
|
programShader->addShader(frag);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create the Camera
|
|
|
|
{
|
|
|
|
osg::ref_ptr<osg::Camera> camera = new osg::Camera;
|
|
|
|
camera->setGraphicsContext(gc.get());
|
|
|
|
camera->setClearMask(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT );
|
|
|
|
camera->setClearColor( osg::Vec4(0.0,0.0,0.0,1.0) );
|
|
|
|
camera->setViewport(new osg::Viewport(0, 0, width, height));
|
|
|
|
GLenum buffer = traits->doubleBuffer ? GL_BACK : GL_FRONT;
|
|
|
|
camera->setDrawBuffer(buffer);
|
|
|
|
camera->setReadBuffer(buffer);
|
|
|
|
camera->setReferenceFrame(osg::Camera::ABSOLUTE_RF);
|
|
|
|
camera->setAllowEventFocus(false);
|
|
|
|
camera->setInheritanceMask(camera->getInheritanceMask() & ~osg::CullSettings::CLEAR_COLOR & ~osg::CullSettings::COMPUTE_NEAR_FAR_MODE);
|
|
|
|
//camera->setComputeNearFarMode(osg::CullSettings::DO_NOT_COMPUTE_NEAR_FAR);
|
|
|
|
|
|
|
|
camera->setProjectionMatrixAsOrtho2D(0,width,0,height);
|
|
|
|
camera->setViewMatrix(osg::Matrix::identity());
|
|
|
|
|
|
|
|
// add subgraph to render
|
|
|
|
camera->addChild(geode);
|
|
|
|
|
|
|
|
camera->setName("WoWCamera");
|
|
|
|
|
|
|
|
addSlave(camera.get(), osg::Matrixd(), osg::Matrixd(), false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-09-02 00:56:53 +08:00
|
|
|
|
2006-12-20 00:00:51 +08:00
|
|
|
void View::assignSceneDataToCameras()
|
|
|
|
{
|
2007-02-21 22:17:15 +08:00
|
|
|
// osg::notify(osg::NOTICE)<<"View::assignSceneDataToCameras()"<<std::endl;
|
2007-02-21 21:48:01 +08:00
|
|
|
|
2006-12-20 00:00:51 +08:00
|
|
|
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);
|
2008-05-11 01:04:02 +08:00
|
|
|
|
|
|
|
Renderer* renderer = dynamic_cast<Renderer*>(_camera->getRenderer());
|
|
|
|
if (renderer) renderer->setCompileOnNextDraw(true);
|
|
|
|
|
2006-12-20 00:00:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
for(unsigned i=0; i<getNumSlaves(); ++i)
|
|
|
|
{
|
|
|
|
Slave& slave = getSlave(i);
|
2007-02-23 19:53:45 +08:00
|
|
|
if (slave._camera.valid() && slave._useMastersSceneData)
|
2006-12-20 00:00:51 +08:00
|
|
|
{
|
|
|
|
slave._camera->removeChildren(0,slave._camera->getNumChildren());
|
|
|
|
if (sceneData) slave._camera->addChild(sceneData);
|
2008-05-11 01:04:02 +08:00
|
|
|
|
|
|
|
Renderer* renderer = dynamic_cast<Renderer*>(slave._camera->getRenderer());
|
|
|
|
if (renderer) renderer->setCompileOnNextDraw(true);
|
2006-12-20 00:00:51 +08:00
|
|
|
}
|
|
|
|
}
|
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-17 00:01:01 +08:00
|
|
|
osg::notify(osg::INFO)<<"View::requestWarpPointer("<<x<<","<<y<<")"<<std::endl;
|
2007-01-16 23:05:44 +08:00
|
|
|
|
2007-01-16 00:09:32 +08:00
|
|
|
float local_x, local_y;
|
|
|
|
const osg::Camera* camera = getCameraContainingPosition(x, y, local_x, local_y);
|
|
|
|
if (camera)
|
2007-01-02 02:20:10 +08:00
|
|
|
{
|
2007-01-16 00:09:32 +08:00
|
|
|
const osgViewer::GraphicsWindow* gw = dynamic_cast<const osgViewer::GraphicsWindow*>(camera->getGraphicsContext());
|
|
|
|
if (gw)
|
|
|
|
{
|
2007-01-16 23:05:44 +08:00
|
|
|
getEventQueue()->mouseWarped(x,y);
|
2007-01-16 00:09:32 +08:00
|
|
|
if (gw->getEventQueue()->getCurrentEventState()->getMouseYOrientation()==osgGA::GUIEventAdapter::Y_INCREASING_DOWNWARDS)
|
|
|
|
{
|
|
|
|
local_y = gw->getTraits()->height - local_y;
|
|
|
|
}
|
2007-01-16 23:05:44 +08:00
|
|
|
const_cast<osgViewer::GraphicsWindow*>(gw)->getEventQueue()->mouseWarped(local_x,local_y);
|
2007-01-16 00:09:32 +08:00
|
|
|
const_cast<osgViewer::GraphicsWindow*>(gw)->requestWarpPointer(local_x, local_y);
|
|
|
|
}
|
|
|
|
}
|
2007-01-16 22:15:49 +08:00
|
|
|
else
|
|
|
|
{
|
2007-01-17 00:01:01 +08:00
|
|
|
osg::notify(osg::INFO)<<"View::requestWarpPointer failed no camera containing pointer"<<std::endl;
|
2007-01-16 22:15:49 +08:00
|
|
|
}
|
2007-01-16 00:09:32 +08:00
|
|
|
}
|
2007-01-02 02:20:10 +08:00
|
|
|
|
2007-01-16 16:56:33 +08:00
|
|
|
bool View::containsCamera(const osg::Camera* camera) const
|
|
|
|
{
|
|
|
|
if (_camera == camera) return true;
|
|
|
|
|
|
|
|
for(unsigned i=0; i<getNumSlaves(); ++i)
|
|
|
|
{
|
|
|
|
const Slave& slave = getSlave(i);
|
|
|
|
if (slave._camera == camera) return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2007-01-16 00:09:32 +08:00
|
|
|
const osg::Camera* View::getCameraContainingPosition(float x, float y, float& local_x, float& local_y) const
|
|
|
|
{
|
|
|
|
const osgGA::GUIEventAdapter* eventState = getEventQueue()->getCurrentEventState();
|
2008-06-03 01:34:47 +08:00
|
|
|
const osgViewer::GraphicsWindow* gw = dynamic_cast<const osgViewer::GraphicsWindow*>(eventState->getGraphicsContext());
|
|
|
|
|
2007-01-16 00:09:32 +08:00
|
|
|
bool view_invert_y = eventState->getMouseYOrientation()==osgGA::GUIEventAdapter::Y_INCREASING_DOWNWARDS;
|
2007-01-17 00:01:01 +08:00
|
|
|
|
2007-01-16 00:09:32 +08:00
|
|
|
double epsilon = 0.5;
|
2007-01-02 02:20:10 +08:00
|
|
|
|
2008-06-03 01:34:47 +08:00
|
|
|
if (_camera->getGraphicsContext() &&
|
|
|
|
(!gw || _camera->getGraphicsContext()==gw) &&
|
|
|
|
_camera->getViewport())
|
2007-01-16 00:09:32 +08:00
|
|
|
{
|
|
|
|
const osg::Viewport* viewport = _camera->getViewport();
|
2007-01-02 02:20:10 +08:00
|
|
|
|
2008-06-03 01:34:47 +08:00
|
|
|
double new_x = x;
|
|
|
|
double new_y = y;
|
|
|
|
|
|
|
|
if (!gw)
|
|
|
|
{
|
|
|
|
new_x = static_cast<double>(_camera->getGraphicsContext()->getTraits()->width) * (x - eventState->getXmin())/(eventState->getXmax()-eventState->getXmin());
|
|
|
|
new_y = view_invert_y ?
|
2007-02-22 18:31:09 +08:00
|
|
|
static_cast<double>(_camera->getGraphicsContext()->getTraits()->height) * (1.0 - (y- eventState->getYmin())/(eventState->getYmax()-eventState->getYmin())) :
|
2007-02-15 20:11:16 +08:00
|
|
|
static_cast<double>(_camera->getGraphicsContext()->getTraits()->height) * (y - eventState->getYmin())/(eventState->getYmax()-eventState->getXmin());
|
2008-06-03 01:34:47 +08:00
|
|
|
}
|
2007-01-02 02:20:10 +08:00
|
|
|
|
2007-01-16 00:09:32 +08:00
|
|
|
if (viewport &&
|
2007-02-15 20:11:16 +08:00
|
|
|
new_x >= (viewport->x()-epsilon) && new_y >= (viewport->y()-epsilon) &&
|
|
|
|
new_x < (viewport->x()+viewport->width()-1.0+epsilon) && new_y <= (viewport->y()+viewport->height()-1.0+epsilon) )
|
2007-01-16 00:09:32 +08:00
|
|
|
{
|
2007-02-15 20:11:16 +08:00
|
|
|
local_x = new_x;
|
|
|
|
local_y = new_y;
|
|
|
|
|
2008-06-03 01:34:47 +08:00
|
|
|
osg::notify(osg::INFO)<<"Returning master camera"<<std::endl;
|
2007-02-22 03:41:53 +08:00
|
|
|
|
2007-01-16 00:09:32 +08:00
|
|
|
return _camera.get();
|
|
|
|
}
|
2007-01-02 02:20:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
osg::Matrix masterCameraVPW = getCamera()->getViewMatrix() * getCamera()->getProjectionMatrix();
|
|
|
|
|
2008-06-03 01:34:47 +08:00
|
|
|
// convert to non dimensional
|
2007-01-02 02:20:10 +08:00
|
|
|
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-02-22 03:41:53 +08:00
|
|
|
for(int i=getNumSlaves()-1; i>=0; --i)
|
2007-01-02 02:20:10 +08:00
|
|
|
{
|
2007-01-16 00:09:32 +08:00
|
|
|
const Slave& slave = getSlave(i);
|
2007-02-22 03:41:53 +08:00
|
|
|
if (slave._camera.valid() &&
|
|
|
|
slave._camera->getAllowEventFocus() &&
|
|
|
|
slave._camera->getRenderTargetImplementation()==osg::Camera::FRAME_BUFFER)
|
2007-01-02 02:20:10 +08:00
|
|
|
{
|
2008-06-03 01:34:47 +08:00
|
|
|
osg::notify(osg::INFO)<<"Testing slave camera "<<slave._camera->getName()<<std::endl;
|
2007-02-22 03:41:53 +08:00
|
|
|
|
2007-01-16 00:09:32 +08:00
|
|
|
const osg::Camera* camera = slave._camera.get();
|
|
|
|
const osg::Viewport* viewport = camera ? camera->getViewport() : 0;
|
2007-01-02 02:20:10 +08:00
|
|
|
|
|
|
|
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-02-22 04:47:32 +08:00
|
|
|
//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;;
|
2007-01-02 20:03:48 +08:00
|
|
|
|
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-02-22 04:47:32 +08:00
|
|
|
// osg::notify(osg::NOTICE)<<" in viewport "<<std::endl;;
|
2007-01-16 00:09:32 +08:00
|
|
|
|
|
|
|
local_x = new_coord.x();
|
|
|
|
local_y = new_coord.y();
|
2007-01-02 20:03:48 +08:00
|
|
|
|
2007-01-16 00:09:32 +08:00
|
|
|
return camera;
|
2007-01-02 02:20:10 +08:00
|
|
|
}
|
2007-01-02 20:03:48 +08:00
|
|
|
else
|
|
|
|
{
|
2007-02-22 04:47:32 +08:00
|
|
|
// osg::notify(osg::NOTICE)<<" not in viewport "<<viewport->x()<<" "<<(viewport->x()+viewport->width())<<std::endl;;
|
2007-01-02 20:03:48 +08:00
|
|
|
}
|
2007-01-02 02:20:10 +08:00
|
|
|
|
|
|
|
}
|
2007-01-16 00:09:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
local_x = x;
|
|
|
|
local_y = y;
|
|
|
|
|
|
|
|
return 0;
|
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;
|
2007-01-16 00:09:32 +08:00
|
|
|
|
|
|
|
float local_x, local_y = 0.0;
|
|
|
|
const osg::Camera* camera = getCameraContainingPosition(x, y, local_x, local_y);
|
|
|
|
if (!camera) camera = _camera.get();
|
2007-01-10 01:35:46 +08:00
|
|
|
|
2007-01-17 01:08:47 +08:00
|
|
|
|
2007-01-16 00:09:32 +08:00
|
|
|
osgUtil::LineSegmentIntersector::CoordinateFrame cf = camera->getViewport() ? osgUtil::Intersector::WINDOW : osgUtil::Intersector::PROJECTION;
|
2007-12-08 23:08:32 +08:00
|
|
|
osg::ref_ptr< osgUtil::LineSegmentIntersector > picker = new osgUtil::LineSegmentIntersector(cf, local_x, local_y);
|
2007-01-16 00:09:32 +08:00
|
|
|
|
2007-01-17 01:08:47 +08:00
|
|
|
#if 0
|
|
|
|
osg::notify(osg::NOTICE)<<"View::computeIntersections(x="<<x<<", y="<<y<<", local_x="<<local_x<<", local_y="<<local_y<<") "<<cf<<std::endl;
|
|
|
|
osg::notify(osg::NOTICE)<<" viewport ("<<camera->getViewport()->x()<<","<<camera->getViewport()->y()<<","<<camera->getViewport()->width()<<","<<camera->getViewport()->height()<<")"<<std::endl;
|
|
|
|
|
|
|
|
const osg::GraphicsContext::Traits* traits = camera->getGraphicsContext() ? camera->getGraphicsContext()->getTraits() : 0;
|
|
|
|
if (traits)
|
|
|
|
{
|
|
|
|
osg::notify(osg::NOTICE)<<" window ("<<traits->x<<","<<traits->y<<","<<traits->width<<","<<traits->height<<")"<<std::endl;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2007-12-08 23:08:32 +08:00
|
|
|
osgUtil::IntersectionVisitor iv(picker.get());
|
2007-01-10 01:35:46 +08:00
|
|
|
iv.setTraversalMask(traversalMask);
|
2008-07-10 03:26:40 +08:00
|
|
|
|
|
|
|
|
|
|
|
#if 1
|
|
|
|
const_cast<osg::Camera*>(camera)->accept(iv);
|
|
|
|
#else
|
|
|
|
|
|
|
|
// timing test code paths
|
|
|
|
|
|
|
|
iv.setUseKdTreeWhenAvailable(true);
|
|
|
|
iv.setDoDummyTraversal(true);
|
|
|
|
|
|
|
|
const_cast<osg::Camera*>(camera)->accept(iv);
|
|
|
|
|
|
|
|
osg::Timer_t before = osg::Timer::instance()->tick();
|
|
|
|
const_cast<osg::Camera*>(camera)->accept(iv);
|
|
|
|
|
|
|
|
osg::Timer_t after_dummy = osg::Timer::instance()->tick();
|
|
|
|
|
|
|
|
iv.setDoDummyTraversal(false);
|
2007-01-16 00:09:32 +08:00
|
|
|
const_cast<osg::Camera*>(camera)->accept(iv);
|
2008-07-10 03:26:40 +08:00
|
|
|
osg::Timer_t after_kdTree_2 = osg::Timer::instance()->tick();
|
|
|
|
|
|
|
|
iv.setUseKdTreeWhenAvailable(false);
|
|
|
|
const_cast<osg::Camera*>(camera)->accept(iv);
|
|
|
|
osg::Timer_t after = osg::Timer::instance()->tick();
|
|
|
|
|
|
|
|
double timeDummy = osg::Timer::instance()->delta_m(before, after_dummy);
|
|
|
|
double timeKdTree = osg::Timer::instance()->delta_m(after_dummy, after_kdTree_2);
|
|
|
|
double timeConventional = osg::Timer::instance()->delta_m(after_kdTree_2, after);
|
|
|
|
|
|
|
|
osg::notify(osg::NOTICE)<<"Using Dummy "<<timeDummy<<std::endl;
|
|
|
|
osg::notify(osg::NOTICE)<<" KdTrees "<<timeKdTree<<std::endl;
|
|
|
|
osg::notify(osg::NOTICE)<<" KdTrees - Traversal "<<timeKdTree-timeDummy<<std::endl;
|
|
|
|
osg::notify(osg::NOTICE)<<" Conventional "<<timeConventional<<std::endl;
|
|
|
|
osg::notify(osg::NOTICE)<<" Conventional - Traversal "<<timeConventional-timeDummy<<std::endl;
|
|
|
|
osg::notify(osg::NOTICE)<<" Delta "<<timeConventional/timeKdTree<<std::endl;
|
|
|
|
osg::notify(osg::NOTICE)<<" Delta sans Traversal "<<(timeConventional-timeDummy)/(timeKdTree-timeDummy)<<std::endl;
|
|
|
|
osg::notify(osg::NOTICE)<<std::endl;
|
|
|
|
#endif
|
2007-01-10 01:35:46 +08:00
|
|
|
|
|
|
|
if (picker->containsIntersections())
|
|
|
|
{
|
|
|
|
intersections = picker->getIntersections();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
intersections.clear();
|
|
|
|
return false;
|
|
|
|
}
|
2007-01-16 00:09:32 +08:00
|
|
|
|
|
|
|
return false;
|
2007-01-10 01:35:46 +08:00
|
|
|
}
|
|
|
|
|
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-16 00:09:32 +08:00
|
|
|
float local_x, local_y = 0.0;
|
|
|
|
const osg::Camera* camera = getCameraContainingPosition(x, y, local_x, local_y);
|
|
|
|
if (!camera) camera = _camera.get();
|
2007-01-10 18:09:05 +08:00
|
|
|
|
2007-01-16 00:09:32 +08:00
|
|
|
osg::Matrix matrix = osg::computeWorldToLocal(nodePath) * camera->getViewMatrix() * camera->getProjectionMatrix();
|
|
|
|
|
2007-01-10 18:09:05 +08:00
|
|
|
double zNear = -1.0;
|
|
|
|
double zFar = 1.0;
|
2007-01-16 00:09:32 +08:00
|
|
|
if (camera->getViewport())
|
2007-01-10 18:09:05 +08:00
|
|
|
{
|
2007-01-16 00:09:32 +08:00
|
|
|
matrix.postMult(camera->getViewport()->computeWindowMatrix());
|
2007-01-10 18:09:05 +08:00
|
|
|
zNear = 0.0;
|
|
|
|
zFar = 1.0;
|
|
|
|
}
|
2007-01-16 00:09:32 +08:00
|
|
|
|
2007-01-10 18:09:05 +08:00
|
|
|
osg::Matrix inverse;
|
|
|
|
inverse.invert(matrix);
|
|
|
|
|
2007-01-16 00:09:32 +08:00
|
|
|
osg::Vec3d startVertex = osg::Vec3d(local_x,local_y,zNear) * inverse;
|
|
|
|
osg::Vec3d endVertex = osg::Vec3d(local_x,local_y,zFar) * inverse;
|
2007-01-10 18:09:05 +08:00
|
|
|
|
2007-12-08 23:08:32 +08:00
|
|
|
osg::ref_ptr< osgUtil::LineSegmentIntersector > picker = new osgUtil::LineSegmentIntersector(osgUtil::Intersector::MODEL, startVertex, endVertex);
|
2007-01-10 18:09:05 +08:00
|
|
|
|
2007-12-08 23:08:32 +08:00
|
|
|
osgUtil::IntersectionVisitor iv(picker.get());
|
2007-01-10 18:09:05 +08:00
|
|
|
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
|
|
|
}
|
2007-09-29 19:41:57 +08:00
|
|
|
|