Moved experimental Widget class to osgGA

Add computeIntersections() to the osgGA::GUIActionAdapter base class to enable intersection tests without needing to directly link to osgViewer.
This commit is contained in:
Robert Osfield 2014-02-06 17:32:41 +00:00
parent 958a7d0ab0
commit 4016aed62d
6 changed files with 24 additions and 16 deletions

View File

@ -1,5 +1,4 @@
SET(TARGET_SRC SET(TARGET_SRC
Widget.cpp
TransferFunctionWidget.cpp TransferFunctionWidget.cpp
osgtransferfunction.cpp osgtransferfunction.cpp
) )

View File

@ -17,14 +17,14 @@
#include <osg/Group> #include <osg/Group>
#include <osg/TransferFunction> #include <osg/TransferFunction>
#include "Widget.h" #include <osgGA/Widget>
#define OSGUI_EXPORT #define OSGUI_EXPORT
namespace osgUI namespace osgUI
{ {
class OSGUI_EXPORT TransferFunctionWidget : public osgUI::Widget class OSGUI_EXPORT TransferFunctionWidget : public osgGA::Widget
{ {
public: public:
TransferFunctionWidget(osg::TransferFunction1D* tf=0); TransferFunctionWidget(osg::TransferFunction1D* tf=0);

View File

@ -16,6 +16,7 @@
#include <osgGA/Export> #include <osgGA/Export>
#include <osg/View> #include <osg/View>
#include <osgUtil/LineSegmentIntersector>
namespace osgGA{ namespace osgGA{
@ -83,6 +84,13 @@ public:
*/ */
virtual void requestWarpPointer(float x,float y) = 0; virtual void requestWarpPointer(float x,float y) = 0;
/** Compute intersections of a ray, starting the current mouse position, through the specified camera. */
virtual bool computeIntersections(const osgGA::GUIEventAdapter& /*ea*/, osgUtil::LineSegmentIntersector::Intersections& /*intersections*/,osg::Node::NodeMask /*traversalMask*/ = 0xffffffff) { return false; }
/** Compute intersections of a ray, starting the current mouse position, through the specified master camera's window/eye coordinates and a specified nodePath's subgraph. */
virtual bool computeIntersections(const osgGA::GUIEventAdapter& /*ea*/, const osg::NodePath& /*nodePath*/, osgUtil::LineSegmentIntersector::Intersections& /*intersections*/,osg::Node::NodeMask /*traversalMask*/ = 0xffffffff) { return false; }
}; };
} }

View File

@ -21,7 +21,7 @@
#define OSGUI_EXPORT #define OSGUI_EXPORT
namespace osgUI namespace osgGA
{ {
class OSGUI_EXPORT Widget : public osg::Group class OSGUI_EXPORT Widget : public osg::Group

View File

@ -9,6 +9,7 @@ SET(LIB_NAME osgGA)
SET(HEADER_PATH ${OpenSceneGraph_SOURCE_DIR}/include/${LIB_NAME}) SET(HEADER_PATH ${OpenSceneGraph_SOURCE_DIR}/include/${LIB_NAME})
SET(TARGET_H SET(TARGET_H
${HEADER_PATH}/AnimationPathManipulator ${HEADER_PATH}/AnimationPathManipulator
${HEADER_PATH}/CameraViewSwitchManipulator
${HEADER_PATH}/DriveManipulator ${HEADER_PATH}/DriveManipulator
${HEADER_PATH}/Device ${HEADER_PATH}/Device
${HEADER_PATH}/Event ${HEADER_PATH}/Event
@ -32,8 +33,8 @@ SET(TARGET_H
${HEADER_PATH}/TerrainManipulator ${HEADER_PATH}/TerrainManipulator
${HEADER_PATH}/TrackballManipulator ${HEADER_PATH}/TrackballManipulator
${HEADER_PATH}/UFOManipulator ${HEADER_PATH}/UFOManipulator
${HEADER_PATH}/Widget
${HEADER_PATH}/Version ${HEADER_PATH}/Version
${HEADER_PATH}/CameraViewSwitchManipulator
) )
SET(TARGET_SRC SET(TARGET_SRC
@ -59,6 +60,7 @@ SET(TARGET_SRC
TerrainManipulator.cpp TerrainManipulator.cpp
TrackballManipulator.cpp TrackballManipulator.cpp
UFOManipulator.cpp UFOManipulator.cpp
Widget.cpp
Version.cpp Version.cpp
CameraViewSwitchManipulator.cpp CameraViewSwitchManipulator.cpp
${OPENSCENEGRAPH_VERSIONINFO_RC} ${OPENSCENEGRAPH_VERSIONINFO_RC}

View File

@ -11,7 +11,6 @@
* OpenSceneGraph Public License for more details. * OpenSceneGraph Public License for more details.
*/ */
#include "Widget.h"
#include <osg/Geode> #include <osg/Geode>
#include <osg/ScriptEngine> #include <osg/ScriptEngine>
@ -19,10 +18,11 @@
#include <osg/MatrixTransform> #include <osg/MatrixTransform>
#include <osg/io_utils> #include <osg/io_utils>
#include <osgGA/Widget>
#include <osgGA/EventVisitor> #include <osgGA/EventVisitor>
#include <osgViewer/View> #include <osgGA/GUIActionAdapter>
using namespace osgUI; using namespace osgGA;
Widget::Widget(): Widget::Widget():
_focusBehaviour(FOCUS_FOLLOWS_POINTER), _focusBehaviour(FOCUS_FOLLOWS_POINTER),
@ -50,8 +50,8 @@ void Widget::setExtents(const osg::BoundingBox& bb)
void Widget::updateFocus(osg::NodeVisitor& nv) void Widget::updateFocus(osg::NodeVisitor& nv)
{ {
osgGA::EventVisitor* ev = dynamic_cast<osgGA::EventVisitor*>(&nv); osgGA::EventVisitor* ev = dynamic_cast<osgGA::EventVisitor*>(&nv);
osgViewer::View* view = ev ? dynamic_cast<osgViewer::View*>(ev->getActionAdapter()) : 0; osgGA::GUIActionAdapter* aa = ev ? ev->getActionAdapter() : 0;
if (ev && view) if (ev && aa)
{ {
osgGA::EventQueue::Events& events = ev->getEvents(); osgGA::EventQueue::Events& events = ev->getEvents();
for(osgGA::EventQueue::Events::iterator itr = events.begin(); for(osgGA::EventQueue::Events::iterator itr = events.begin();
@ -74,7 +74,7 @@ void Widget::updateFocus(osg::NodeVisitor& nv)
if (numButtonsPressed==1) if (numButtonsPressed==1)
{ {
osgUtil::LineSegmentIntersector::Intersections intersections; osgUtil::LineSegmentIntersector::Intersections intersections;
bool withinWidget = view->computeIntersections(*ea, nv.getNodePath(), intersections); bool withinWidget = aa->computeIntersections(*ea, nv.getNodePath(), intersections);
if (withinWidget) _hasEventFocus = true; if (withinWidget) _hasEventFocus = true;
else _hasEventFocus = false; else _hasEventFocus = false;
} }
@ -104,7 +104,7 @@ void Widget::updateFocus(osg::NodeVisitor& nv)
if (checkWithinWidget) if (checkWithinWidget)
{ {
osgUtil::LineSegmentIntersector::Intersections intersections; osgUtil::LineSegmentIntersector::Intersections intersections;
bool withinWidget = view->computeIntersections(*ea, nv.getNodePath(), intersections); bool withinWidget = aa->computeIntersections(*ea, nv.getNodePath(), intersections);
_hasEventFocus = withinWidget; _hasEventFocus = withinWidget;
} }
@ -205,8 +205,7 @@ void Widget::traverseImplementation(osg::NodeVisitor& nv)
if (!_graphicsInitialized && nv.getVisitorType()!=osg::NodeVisitor::CULL_VISITOR) createGraphics(); if (!_graphicsInitialized && nv.getVisitorType()!=osg::NodeVisitor::CULL_VISITOR) createGraphics();
osgGA::EventVisitor* ev = dynamic_cast<osgGA::EventVisitor*>(&nv); osgGA::EventVisitor* ev = dynamic_cast<osgGA::EventVisitor*>(&nv);
osgViewer::View* view = ev ? dynamic_cast<osgViewer::View*>(ev->getActionAdapter()) : 0; if (ev)
if (ev && view)
{ {
updateFocus(nv); updateFocus(nv);
@ -263,9 +262,9 @@ bool Widget::handleImplementation(osgGA::EventVisitor* /*ev*/, osgGA::Event* /*e
bool Widget::computePositionInLocalCoordinates(osgGA::EventVisitor* ev, osgGA::GUIEventAdapter* event, osg::Vec3& localPosition) const bool Widget::computePositionInLocalCoordinates(osgGA::EventVisitor* ev, osgGA::GUIEventAdapter* event, osg::Vec3& localPosition) const
{ {
osgViewer::View* view = ev ? dynamic_cast<osgViewer::View*>(ev->getActionAdapter()) : 0; osgGA::GUIActionAdapter* aa = ev ? ev->getActionAdapter() : 0;
osgUtil::LineSegmentIntersector::Intersections intersections; osgUtil::LineSegmentIntersector::Intersections intersections;
if (view && view->computeIntersections(*event, ev->getNodePath(), intersections)) if (aa && aa->computeIntersections(*event, ev->getNodePath(), intersections))
{ {
localPosition = intersections.begin()->getLocalIntersectPoint(); localPosition = intersections.begin()->getLocalIntersectPoint();