Added View::computeIntersection implementation for a node withing a scene graph.
This commit is contained in:
parent
4d4b342e97
commit
4954262eb0
@ -33,7 +33,7 @@ class OSGUTIL_EXPORT LineSegmentIntersector : public Intersector
|
|||||||
|
|
||||||
/** Convinience constructor for supporting picking in WINDOW, or PROJECTION coorindates
|
/** Convinience constructor for supporting picking in WINDOW, or PROJECTION coorindates
|
||||||
* In WINDOW coordinates creates a start value of (x,y,0) and end value of (x,y,1).
|
* In WINDOW coordinates creates a start value of (x,y,0) and end value of (x,y,1).
|
||||||
* In PROJECTION coordinates (clip space cube) creates a start value of (x,y,1) and end value of (x,y,-1).
|
* In PROJECTION coordinates (clip space cube) creates a start value of (x,y,-1) and end value of (x,y,1).
|
||||||
* In VIEW and MODEL coordinates creates a start value of (x,y,0) and end value of (x,y,1).*/
|
* In VIEW and MODEL coordinates creates a start value of (x,y,0) and end value of (x,y,1).*/
|
||||||
LineSegmentIntersector(CoordinateFrame cf, double x, double y);
|
LineSegmentIntersector(CoordinateFrame cf, double x, double y);
|
||||||
|
|
||||||
|
@ -41,22 +41,12 @@ class OSGVIEWER_EXPORT Scene : public virtual osg::Referenced
|
|||||||
|
|
||||||
osg::FrameStamp* getFrameStamp() { return _frameStamp.get(); }
|
osg::FrameStamp* getFrameStamp() { return _frameStamp.get(); }
|
||||||
|
|
||||||
void setEventQueue(osgGA::EventQueue* eventQueue) { _eventQueue = eventQueue; }
|
|
||||||
osgGA::EventQueue* getEventQueue() { return _eventQueue.get(); }
|
|
||||||
const osgGA::EventQueue* getEventQueue() const { return _eventQueue.get(); }
|
|
||||||
|
|
||||||
typedef std::list< osg::ref_ptr<osgGA::GUIEventHandler> > EventHandlers;
|
|
||||||
|
|
||||||
void addEventHandler(osgGA::GUIEventHandler* eventHandler);
|
|
||||||
EventHandlers& getEventHandlers() { return _eventHandlers; }
|
|
||||||
const EventHandlers& getEventHandlers() const { return _eventHandlers; }
|
|
||||||
|
|
||||||
void setDatabasePager(osgDB::DatabasePager* dp);
|
void setDatabasePager(osgDB::DatabasePager* dp);
|
||||||
osgDB::DatabasePager* getDatabasePager() { return _databasePager.get(); }
|
osgDB::DatabasePager* getDatabasePager() { return _databasePager.get(); }
|
||||||
const osgDB::DatabasePager* getDatabasePager() const { return _databasePager.get(); }
|
const osgDB::DatabasePager* getDatabasePager() const { return _databasePager.get(); }
|
||||||
|
|
||||||
virtual void frameAdvance();
|
virtual void frameAdvance();
|
||||||
virtual void frameEventTraversal();
|
|
||||||
virtual void frameUpdateTraversal();
|
virtual void frameUpdateTraversal();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@ -72,13 +62,7 @@ class OSGVIEWER_EXPORT Scene : public virtual osg::Referenced
|
|||||||
|
|
||||||
osg::ref_ptr<osgUtil::UpdateVisitor> _updateVisitor;
|
osg::ref_ptr<osgUtil::UpdateVisitor> _updateVisitor;
|
||||||
|
|
||||||
osg::ref_ptr<osgGA::EventQueue> _eventQueue;
|
|
||||||
osg::ref_ptr<osgGA::EventVisitor> _eventVisitor;
|
|
||||||
|
|
||||||
osg::ref_ptr<osgDB::DatabasePager> _databasePager;
|
osg::ref_ptr<osgDB::DatabasePager> _databasePager;
|
||||||
|
|
||||||
EventHandlers _eventHandlers;
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -64,12 +64,8 @@ class OSGVIEWER_EXPORT View : public osg::View, public osgGA::GUIActionAdapter
|
|||||||
* directly on to the computeIntersections method. */
|
* directly on to the computeIntersections method. */
|
||||||
bool computeIntersections(float x,float y, osgUtil::LineSegmentIntersector::Intersections& intersections,osg::Node::NodeMask traversalMask = 0xffffffff);
|
bool computeIntersections(float x,float y, osgUtil::LineSegmentIntersector::Intersections& intersections,osg::Node::NodeMask traversalMask = 0xffffffff);
|
||||||
|
|
||||||
/** Compute intersections between a ray through the specified master cameras window/eye coords and a specified node.
|
/** Compute intersections between a ray through the specified master cameras window/eye coords and a specified nodePath's subgraph. */
|
||||||
* Note, when a master cameras has slaves and no viewport itself its coordinate frame will be in clip space i.e. -1,-1 to 1,1,
|
bool computeIntersections(float x,float y, osg::NodePath& nodePath, osgUtil::LineSegmentIntersector::Intersections& intersections,osg::Node::NodeMask traversalMask = 0xffffffff);
|
||||||
* while if its has a viewport the coordintates will be relative to its viewport dimensions.
|
|
||||||
* Mouse events handled by the view will automatically be attached into the master camera window/clip coords so can be passed
|
|
||||||
* directly on to the computeIntersections method. */
|
|
||||||
bool computeIntersections(float x,float y, osg::Node* node, osgUtil::LineSegmentIntersector::Intersections& intersections,osg::Node::NodeMask traversalMask = 0xffffffff);
|
|
||||||
|
|
||||||
|
|
||||||
virtual void requestRedraw();
|
virtual void requestRedraw();
|
||||||
@ -91,7 +87,6 @@ class OSGVIEWER_EXPORT View : public osg::View, public osgGA::GUIActionAdapter
|
|||||||
|
|
||||||
typedef std::map<osg::ref_ptr<osg::Camera>, osg::ref_ptr<osgUtil::SceneView> > CameraSceneViewMap;
|
typedef std::map<osg::ref_ptr<osg::Camera>, osg::ref_ptr<osgUtil::SceneView> > CameraSceneViewMap;
|
||||||
CameraSceneViewMap _cameraSceneViewMap;
|
CameraSceneViewMap _cameraSceneViewMap;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
#include <osgViewer/GraphicsWindow>
|
#include <osgViewer/GraphicsWindow>
|
||||||
#include <osgViewer/View>
|
#include <osgViewer/View>
|
||||||
|
#include <osgGA/EventVisitor>
|
||||||
|
|
||||||
namespace osgViewer {
|
namespace osgViewer {
|
||||||
|
|
||||||
@ -134,6 +135,7 @@ class OSGVIEWER_EXPORT Viewer : public osgViewer::View
|
|||||||
|
|
||||||
osg::observer_ptr<osg::Camera> _cameraWithFocus;
|
osg::observer_ptr<osg::Camera> _cameraWithFocus;
|
||||||
|
|
||||||
|
osg::ref_ptr<osgGA::EventVisitor> _eventVisitor;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -220,7 +220,7 @@ LineSegmentIntersector::LineSegmentIntersector(CoordinateFrame cf, double x, dou
|
|||||||
switch(cf)
|
switch(cf)
|
||||||
{
|
{
|
||||||
case WINDOW : _start.set(x,y,0.0); _end.set(x,y,1.0); break;
|
case WINDOW : _start.set(x,y,0.0); _end.set(x,y,1.0); break;
|
||||||
case PROJECTION : _start.set(x,y,1.0); _end.set(x,y,-1.0); break;
|
case PROJECTION : _start.set(x,y,-1.0); _end.set(x,y,1.0); break;
|
||||||
case VIEW : _start.set(x,y,0.0); _end.set(x,y,1.0); break;
|
case VIEW : _start.set(x,y,0.0); _end.set(x,y,1.0); break;
|
||||||
case MODEL : _start.set(x,y,0.0); _end.set(x,y,1.0); break;
|
case MODEL : _start.set(x,y,0.0); _end.set(x,y,1.0); break;
|
||||||
}
|
}
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <osgViewer/Scene>
|
#include <osgViewer/Scene>
|
||||||
|
#include <osgGA/EventVisitor>
|
||||||
|
|
||||||
using namespace osgViewer;
|
using namespace osgViewer;
|
||||||
|
|
||||||
@ -64,11 +65,6 @@ void Scene::setDatabasePager(osgDB::DatabasePager* dp)
|
|||||||
_databasePager = dp;
|
_databasePager = dp;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Scene::addEventHandler(osgGA::GUIEventHandler*)
|
|
||||||
{
|
|
||||||
osg::notify(osg::NOTICE)<<"Scene::addEventHandler() not implementated yet."<<std::endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Scene::frameAdvance()
|
void Scene::frameAdvance()
|
||||||
{
|
{
|
||||||
// double previousTime = _frameStamp->getReferenceTime();
|
// double previousTime = _frameStamp->getReferenceTime();
|
||||||
@ -79,45 +75,6 @@ void Scene::frameAdvance()
|
|||||||
// osg::notify(osg::NOTICE)<<"Frame rate = "<<1.0/(_frameStamp->getReferenceTime()-previousTime)<<std::endl;
|
// osg::notify(osg::NOTICE)<<"Frame rate = "<<1.0/(_frameStamp->getReferenceTime()-previousTime)<<std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Scene::frameEventTraversal()
|
|
||||||
{
|
|
||||||
_eventQueue->frame( _frameStamp->getReferenceTime() );
|
|
||||||
|
|
||||||
osgGA::EventQueue::Events events;
|
|
||||||
_eventQueue->takeEvents(events);
|
|
||||||
|
|
||||||
if (_eventVisitor.valid())
|
|
||||||
{
|
|
||||||
_eventVisitor->setTraversalNumber(_frameStamp->getFrameNumber());
|
|
||||||
}
|
|
||||||
|
|
||||||
for(osgGA::EventQueue::Events::iterator itr = events.begin();
|
|
||||||
itr != events.end();
|
|
||||||
++itr)
|
|
||||||
{
|
|
||||||
osgGA::GUIEventAdapter* event = itr->get();
|
|
||||||
|
|
||||||
bool handled = false;
|
|
||||||
|
|
||||||
if (_eventVisitor.valid() && getSceneData())
|
|
||||||
{
|
|
||||||
_eventVisitor->reset();
|
|
||||||
_eventVisitor->addEvent( event );
|
|
||||||
|
|
||||||
getSceneData()->accept(*_eventVisitor);
|
|
||||||
|
|
||||||
if (_eventVisitor->getEventHandled()) handled = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
for(EventHandlers::iterator hitr = _eventHandlers.begin();
|
|
||||||
hitr != _eventHandlers.end() && !handled;
|
|
||||||
++hitr)
|
|
||||||
{
|
|
||||||
// handled = (*hitr)->handle( *event, *this, 0, 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Scene::frameUpdateTraversal()
|
void Scene::frameUpdateTraversal()
|
||||||
{
|
{
|
||||||
if (!getSceneData()) return;
|
if (!getSceneData()) return;
|
||||||
|
@ -409,11 +409,43 @@ bool View::computeIntersections(float x,float y, osgUtil::LineSegmentIntersector
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool View::computeIntersections(float x,float y, osg::Node* node, osgUtil::LineSegmentIntersector::Intersections& intersections,osg::Node::NodeMask traversalMask)
|
bool View::computeIntersections(float x,float y, osg::NodePath& nodePath, osgUtil::LineSegmentIntersector::Intersections& intersections,osg::Node::NodeMask traversalMask)
|
||||||
{
|
{
|
||||||
if (!_camera.valid()) return false;
|
if (!_camera.valid()) return false;
|
||||||
|
|
||||||
osg::notify(osg::NOTICE)<<"View::computeIntersections(x,y,node,intersections) not implemented"<<std::endl;
|
osg::notify(osg::NOTICE)<<"View::computeIntersections(x,y,node,intersections) not implemented"<<std::endl;
|
||||||
|
|
||||||
|
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;
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -31,6 +31,8 @@ Viewer::Viewer():
|
|||||||
_threadingModel(ThreadPerContext),
|
_threadingModel(ThreadPerContext),
|
||||||
_numThreadsOnBarrier(0)
|
_numThreadsOnBarrier(0)
|
||||||
{
|
{
|
||||||
|
_eventVisitor = new osgGA::EventVisitor;
|
||||||
|
_eventVisitor->setActionAdapter(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
Viewer::~Viewer()
|
Viewer::~Viewer()
|
||||||
@ -723,37 +725,6 @@ void Viewer::eventTraversal()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0
|
|
||||||
// pointer coordinate transform
|
|
||||||
for(osgGA::EventQueue::Events::iterator itr = events.begin();
|
|
||||||
itr != events.end();
|
|
||||||
++itr)
|
|
||||||
{
|
|
||||||
osgGA::GUIEventAdapter* event = itr->get();
|
|
||||||
|
|
||||||
if (getEventQueue()->getUseFixedMouseInputRange())
|
|
||||||
{
|
|
||||||
event->setInputRange(eventState->getXmin(), eventState->getYmin(), eventState->getXmax(), eventState->getYmax());
|
|
||||||
}
|
|
||||||
|
|
||||||
switch(event->getEventType())
|
|
||||||
{
|
|
||||||
case(osgGA::GUIEventAdapter::PUSH):
|
|
||||||
case(osgGA::GUIEventAdapter::RELEASE):
|
|
||||||
case(osgGA::GUIEventAdapter::DRAG):
|
|
||||||
case(osgGA::GUIEventAdapter::MOVE):
|
|
||||||
eventState->setX(event->getX());
|
|
||||||
eventState->setY(event->getY());
|
|
||||||
eventState->setButtonMask(event->getButtonMask());
|
|
||||||
// osg::notify(osg::NOTICE)<<" mouse x = "<<event->getX()<<" y="<<event->getY()<<std::endl;
|
|
||||||
// osg::notify(osg::NOTICE)<<" mouse Xmin = "<<event->getXmin()<<" Ymin="<<event->getYmin()<<" xMax="<<event->getXmax()<<" Ymax="<<event->getYmax()<<std::endl;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// osg::notify(osg::NOTICE)<<"mouseEventState Xmin = "<<eventState->getXmin()<<" Ymin="<<eventState->getYmin()<<" xMax="<<eventState->getXmax()<<" Ymax="<<eventState->getYmax()<<std::endl;
|
// osg::notify(osg::NOTICE)<<"mouseEventState Xmin = "<<eventState->getXmin()<<" Ymin="<<eventState->getYmin()<<" xMax="<<eventState->getXmax()<<" Ymax="<<eventState->getYmax()<<std::endl;
|
||||||
|
|
||||||
@ -792,7 +763,7 @@ void Viewer::eventTraversal()
|
|||||||
case(osgGA::GUIEventAdapter::KEYUP):
|
case(osgGA::GUIEventAdapter::KEYUP):
|
||||||
osg::notify(osg::NOTICE)<<" KEYUP '"<<(char)event->getKey()<<"'"<<std::endl;
|
osg::notify(osg::NOTICE)<<" KEYUP '"<<(char)event->getKey()<<"'"<<std::endl;
|
||||||
break;
|
break;
|
||||||
*/ case(osgGA::GUIEventAdapter::RESIZE):
|
case(osgGA::GUIEventAdapter::RESIZE):
|
||||||
osg::notify(osg::NOTICE)<<" RESIZE "<<event->getWindowX()<<"/"<<event->getWindowY()<<" x "<<event->getWindowWidth()<<"/"<<event->getWindowHeight() << std::endl;
|
osg::notify(osg::NOTICE)<<" RESIZE "<<event->getWindowX()<<"/"<<event->getWindowY()<<" x "<<event->getWindowWidth()<<"/"<<event->getWindowHeight() << std::endl;
|
||||||
break;
|
break;
|
||||||
case(osgGA::GUIEventAdapter::QUIT_APPLICATION):
|
case(osgGA::GUIEventAdapter::QUIT_APPLICATION):
|
||||||
@ -861,6 +832,28 @@ void Viewer::eventTraversal()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (_eventVisitor.valid())
|
||||||
|
{
|
||||||
|
_eventVisitor->setFrameStamp(_scene->getFrameStamp());
|
||||||
|
_eventVisitor->setTraversalNumber(_scene->getFrameStamp()->getFrameNumber());
|
||||||
|
|
||||||
|
for(osgGA::EventQueue::Events::iterator itr = events.begin();
|
||||||
|
itr != events.end();
|
||||||
|
++itr)
|
||||||
|
{
|
||||||
|
osgGA::GUIEventAdapter* event = itr->get();
|
||||||
|
|
||||||
|
bool handled = false;
|
||||||
|
|
||||||
|
_eventVisitor->reset();
|
||||||
|
_eventVisitor->addEvent( event );
|
||||||
|
|
||||||
|
getSceneData()->accept(*_eventVisitor);
|
||||||
|
|
||||||
|
if (_eventVisitor->getEventHandled()) handled = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Viewer::updateTraversal()
|
void Viewer::updateTraversal()
|
||||||
|
Loading…
Reference in New Issue
Block a user