3 #include "VsMouseSpring.h"
4 #include "VsDraggerHandler.h"
5 #include "VsMovableItem.h"
8 #include "VsRigidBody.h"
10 #include "VsSimulator.h"
11 #include "VsOsgUserData.h"
12 #include "VsDragger.h"
16 namespace Visualization
19 VsDraggerHandler::VsDraggerHandler(Simulator *lpSim, osgViewer::Viewer *osgViewer, osg::Viewport *osgViewport)
22 m_osgViewer = osgViewer;
23 m_osgViewport = osgViewport;
24 m_osgActiveDragger = NULL;
27 VsDraggerHandler::~VsDraggerHandler(
void)
34 bool bHandled =
false;
42 switch(ea.getEventType())
44 case(GUIEventAdapter::PUSH):
50 case(GUIEventAdapter::RELEASE):
52 if(m_osgActiveDragger)
54 m_osgManipInfo._hitIter = m_osgManipInfo._hitList.begin();
55 m_osgManipInfo.setCamera((osg::Camera *) m_osgViewer->getCamera());
56 m_osgManipInfo.setMousePosition(ea.getX(), ea.getY());
58 bHandled = m_osgActiveDragger->handle(m_osgManipInfo, ea, aa);
64 case(GUIEventAdapter::DRAG):
68 if(m_osgActiveDragger)
70 m_osgManipInfo._hitIter = m_osgManipInfo._hitList.begin();
71 m_osgManipInfo.setCamera((osg::Camera *) m_osgViewer->getCamera());
72 m_osgManipInfo.setMousePosition(ea.getX(), ea.getY());
74 bHandled = m_osgActiveDragger->handle(m_osgManipInfo, ea, aa);
84 if (ea.getEventType() == osgGA::GUIEventAdapter::RELEASE)
86 m_osgActiveDragger = NULL;
87 m_osgManipInfo.reset();
91 catch(CStdErrorInfo oError)
99 void VsDraggerHandler::EndGripDrag()
101 if(m_osgActiveDragger && m_osgActiveDragger->getUserData())
104 if(osgData && osgData->GetMovable())
107 lpItem->EndGripDrag();
112 void VsDraggerHandler::pick(
const osgGA::GUIEventAdapter& ea, GUIActionAdapter& aa)
114 osgUtil::LineSegmentIntersector::Intersections intersections;
120 const osg::Camera* camera = m_osgViewer->getCamera();
122 osgUtil::LineSegmentIntersector::CoordinateFrame cf = camera->getViewport() ? osgUtil::Intersector::WINDOW : osgUtil::Intersector::PROJECTION;
123 osg::ref_ptr< osgUtil::LineSegmentIntersector > picker =
new osgUtil::LineSegmentIntersector(cf, x, y);
125 m_osgManipInfo.reset();
127 RigidBody *lpBody = NULL;
128 Joint *lpJoint = NULL;
129 if (m_osgViewer->computeIntersections(x,y,intersections))
131 m_osgManipInfo.setCamera((osg::Camera *) camera);
132 m_osgManipInfo.setMousePosition(x, y);
134 #pragma region LineSegmentIntersector
136 for(osgUtil::LineSegmentIntersector::Intersections::iterator hitr = intersections.begin();
137 hitr != intersections.end();
141 m_osgManipInfo.addIntersection(hitr->nodePath, hitr->getLocalIntersectPoint());
145 for (osg::NodePath::iterator itr = m_osgManipInfo._hitList.front().first.begin();
146 itr != m_osgManipInfo._hitList.front().first.end();
149 osgManipulator::Dragger* dragger =
dynamic_cast<osgManipulator::Dragger*
>(*itr);
153 dragger->handle(m_osgManipInfo, ea, aa);
154 m_osgActiveDragger = dragger;
virtual bool handle(const GUIEventAdapter &ea, GUIActionAdapter &us)
Classes for implementing the cm-labs vortex physics engine for AnimatLab.
Declares the vortex structure class.