3 #include "OsgMovableItem.h"
5 #include "OsgRigidBody.h"
7 #include "OsgMouseSpring.h"
8 #include "OsgDraggerHandler.h"
10 #include "OsgUserData.h"
11 #include "OsgDragger.h"
12 #include "OsgSimulator.h"
16 namespace Visualization
19 OsgDraggerHandler::OsgDraggerHandler(Simulator *lpSim, osgViewer::Viewer *osgViewer, osg::Viewport *osgViewport)
22 m_osgViewer = osgViewer;
23 m_osgViewport = osgViewport;
24 m_osgActiveDragger = NULL;
27 OsgDraggerHandler::~OsgDraggerHandler(
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 OsgDraggerHandler::StartGripDrag()
101 if(m_osgActiveDragger && m_osgActiveDragger->getUserData())
104 if(osgData && osgData->GetMovable())
107 if(lpItem && m_lpSim)
109 m_lpSim->InDrag(
true);
110 lpItem->StartGripDrag();
116 void OsgDraggerHandler::EndGripDrag()
118 if(m_osgActiveDragger && m_osgActiveDragger->getUserData())
121 if(osgData && osgData->GetMovable())
124 if(lpItem && m_lpSim)
126 m_lpSim->InDrag(
false);
127 lpItem->EndGripDrag();
133 void OsgDraggerHandler::pick(
const osgGA::GUIEventAdapter& ea, GUIActionAdapter& aa)
135 osgUtil::LineSegmentIntersector::Intersections intersections;
141 const osg::Camera* camera = m_osgViewer->getCamera();
143 osgUtil::LineSegmentIntersector::CoordinateFrame cf = camera->getViewport() ? osgUtil::Intersector::WINDOW : osgUtil::Intersector::PROJECTION;
144 osg::ref_ptr< osgUtil::LineSegmentIntersector > picker =
new osgUtil::LineSegmentIntersector(cf, x, y);
146 m_osgManipInfo.reset();
148 RigidBody *lpBody = NULL;
149 Joint *lpJoint = NULL;
150 if (m_osgViewer->computeIntersections(x,y,intersections))
152 m_osgManipInfo.setCamera((osg::Camera *) camera);
153 m_osgManipInfo.setMousePosition(x, y);
155 #pragma region LineSegmentIntersector
157 for(osgUtil::LineSegmentIntersector::Intersections::iterator hitr = intersections.begin();
158 hitr != intersections.end();
162 m_osgManipInfo.addIntersection(hitr->nodePath, hitr->getLocalIntersectPoint());
166 for (osg::NodePath::iterator itr = m_osgManipInfo._hitList.front().first.begin();
167 itr != m_osgManipInfo._hitList.front().first.end();
170 osgManipulator::Dragger* dragger =
dynamic_cast<osgManipulator::Dragger*
>(*itr);
174 dragger->handle(m_osgManipInfo, ea, aa);
175 m_osgActiveDragger = dragger;
Classes for implementing the cm-labs vortex physics engine for AnimatLab.
virtual bool handle(const GUIEventAdapter &ea, GUIActionAdapter &us)
Declares the vortex structure class.