30 #include "../common/math/linearAlgebra/WLinearAlgebra.h"
32 #include "WPickHandler.h"
33 #include "WPickInfo.h"
51 m_viewerName( viewerName ),
73 switch ( ea.getEventType() )
75 case osgGA::GUIEventAdapter::DRAG :
76 case osgGA::GUIEventAdapter::PUSH :
78 unsigned int buttonMask = ea.getButtonMask();
79 if( buttonMask == osgGA::GUIEventAdapter::RIGHT_MOUSE_BUTTON )
82 osgViewer::View* view =
static_cast< osgViewer::View*
>( &aa );
88 if( ( buttonMask == osgGA::GUIEventAdapter::LEFT_MOUSE_BUTTON ) && (
m_paintMode == 1 ) )
91 osgViewer::View* view =
static_cast< osgViewer::View*
>( &aa );
99 case osgGA::GUIEventAdapter::RELEASE :
102 osgViewer::View* view =
static_cast< osgViewer::View*
>( &aa );
109 case osgGA::GUIEventAdapter::KEYUP :
115 case osgGA::GUIEventAdapter::KEYDOWN :
117 if( ea.getKey() ==
'c' )
119 osgViewer::View* view =
static_cast< osgViewer::View*
>( &aa );
120 osg::ref_ptr< osgGA::GUIEventAdapter >
event =
new osgGA::GUIEventAdapter( ea );
121 event->setX( ( ea.getXmin() + ea.getXmax() ) * 0.5 );
122 event->setY( ( ea.getYmin() + ea.getYmax() ) * 0.5 );
125 pick( view, *event );
128 if( ea.getKey() == osgGA::GUIEventAdapter::KEY_Shift_L )
132 if( ea.getKey() == osgGA::GUIEventAdapter::KEY_Control_L || ea.getKey() == osgGA::GUIEventAdapter::KEY_Control_R )
153 std::string extractSuitableName( osgUtil::LineSegmentIntersector::Intersections::iterator hitr )
155 if( !hitr->nodePath.empty() && !( hitr->nodePath.back()->getName().empty() ) )
157 return hitr->nodePath.back()->getName();
159 else if( hitr->drawable.valid() )
161 return hitr->drawable->className();
163 assert( 0 &&
"This should not happen. Tell \"wiebel\" if it does." );
182 osgUtil::LineSegmentIntersector::Intersections intersections;
206 bool intersetionsExist = view->computeIntersections( x, y, intersections );
209 bool startPickIsStillInList =
false;
210 osgUtil::LineSegmentIntersector::Intersections::iterator hitr;
211 if( intersetionsExist )
213 assert( intersections.size() );
214 hitr = intersections.begin();
216 bool ignoreFirst =
m_ctrl;
218 while( hitr != intersections.end() )
220 std::string nodeName = extractSuitableName( hitr );
227 else if( ignoreFirst )
238 if( hitr == intersections.end() )
251 while( ( hitr != intersections.end() ) && !startPickIsStillInList )
256 if( !startPickIsStillInList )
284 pickPos[0] = hitr->getWorldIntersectPoint()[0];
285 pickPos[1] = hitr->getWorldIntersectPoint()[1];
286 pickPos[2] = hitr->getWorldIntersectPoint()[2];
289 pickNormal[0] = hitr->getWorldIntersectNormal()[0];
290 pickNormal[1] = hitr->getWorldIntersectNormal()[1];
291 pickNormal[2] = hitr->getWorldIntersectNormal()[2];