Changed osgManipulator::Dragger::handle(..) method to use a nested PointerInfo

class to encapsulate the pixel coords, SceneView and picking operations in prep for
making the code more general purpose, and less reliant on classes like osgUtil::SceneView and osgUtil::IntersectVisitor.
This commit is contained in:
Robert Osfield
2007-02-11 21:12:34 +00:00
parent 004e150ad7
commit 3006bb14f4
21 changed files with 177 additions and 170 deletions

View File

@@ -26,17 +26,30 @@ Dragger::~Dragger()
{
}
bool CompositeDragger::handle(int pixel_x, int pixel_y, const osgUtil::SceneView& sv,
const osgUtil::IntersectVisitor::HitList& hl, const osgUtil::IntersectVisitor::HitList::iterator& hitIter,
const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa)
Dragger::PointerInfo::PointerInfo():
pixel_x(0),
pixel_y(0),
sv(0),
hitIter(0)
{
}
bool Dragger::PointerInfo::contains(const osg::Node* node) const
{
if (node) return std::find((*hitIter)._nodePath.begin(), (*hitIter)._nodePath.end(), node) != (*hitIter)._nodePath.end();
else return false;
}
bool CompositeDragger::handle(const PointerInfo& pi, const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa)
{
// Check if the dragger node is in the nodepath.
if (std::find((*hitIter)._nodePath.begin(), (*hitIter)._nodePath.end(), this) == (*hitIter)._nodePath.end())
if (!pi.contains(this))
return false;
for (DraggerList::iterator itr=_draggerList.begin(); itr!=_draggerList.end(); ++itr)
{
if ((*itr)->handle(pixel_x, pixel_y, sv, hl, hitIter, ea, aa))
if ((*itr)->handle(pi, ea, aa))
return true;
}
return false;

View File

@@ -243,7 +243,7 @@ LineProjector::~LineProjector()
{
}
bool LineProjector::project(const osg::Vec2& pointToProject, const osgUtil::SceneView& sv, osg::Vec3& projectedPoint) const
bool LineProjector::project(const Dragger::PointerInfo& pi, osg::Vec3& projectedPoint) const
{
if (!_line->valid())
{
@@ -257,8 +257,8 @@ bool LineProjector::project(const osg::Vec2& pointToProject, const osgUtil::Scen
// Project the objectLine onto the window.
osg::ref_ptr<osg::LineSegment> windowLine = new osg::LineSegment;
sv.projectObjectIntoWindow(objectLine->start(), windowLine->start());
sv.projectObjectIntoWindow(objectLine->end(), windowLine->end());
pi.sv->projectObjectIntoWindow(objectLine->start(), windowLine->start());
pi.sv->projectObjectIntoWindow(objectLine->end(), windowLine->end());
windowLine->start().z() = windowLine->end().z() = 0.0f;
@@ -271,14 +271,14 @@ bool LineProjector::project(const osg::Vec2& pointToProject, const osgUtil::Scen
osg::Vec2 windowLineEnd(windowLine->end().x(),windowLine->end().y());
osg::Vec2 windowLineDirection = windowLineEnd - windowLineStart;
windowLineDirection.normalize();
float dotProduct = (windowLineDirection) * (pointToProject - windowLineStart);
float dotProduct = (windowLineDirection) * (pi.pointToProject() - windowLineStart);
// Get the closest point on the windowLine from (x,y).
osg::Vec2 closestWindowPt = windowLineStart + windowLineDirection * dotProduct;
// Project the closest point back into the scene and into local space.
osg::ref_ptr<osg::LineSegment> projectedLocalLine = new osg::LineSegment;
sv.projectWindowXYIntoObject((int)closestWindowPt.x(), (int)closestWindowPt.y(), projectedLocalLine->start(), projectedLocalLine->end());
pi.projectWindowXYIntoObject(closestWindowPt, projectedLocalLine->start(), projectedLocalLine->end());
projectedLocalLine->mult(*projectedLocalLine, getWorldToLocal());
// Find the closest point between _line and projectedLocalLine on _line and that's the result.
@@ -305,7 +305,7 @@ PlaneProjector::~PlaneProjector()
{
}
bool PlaneProjector::project(const osg::Vec2& pointToProject, const osgUtil::SceneView& sv, osg::Vec3& projectedPoint) const
bool PlaneProjector::project(const Dragger::PointerInfo& pi, osg::Vec3& projectedPoint) const
{
if (!_plane.valid())
{
@@ -315,7 +315,7 @@ bool PlaneProjector::project(const osg::Vec2& pointToProject, const osgUtil::Sce
// Get the near and far points for the mouse point.
osg::Vec3 nearPoint, farPoint;
sv.projectWindowXYIntoObject((int)pointToProject[0],(int)pointToProject[1],nearPoint,farPoint);
pi.projectWindowXYIntoObject(nearPoint,farPoint);
// Transform these points into local coordinates.
osg::Vec3 objectNearPoint, objectFarPoint;
@@ -340,7 +340,7 @@ SphereProjector::~SphereProjector()
{
}
bool SphereProjector::project(const osg::Vec2& pointToProject, const osgUtil::SceneView& sv, osg::Vec3& projectedPoint) const
bool SphereProjector::project(const Dragger::PointerInfo& pi, osg::Vec3& projectedPoint) const
{
if (!_sphere->valid())
{
@@ -350,7 +350,7 @@ bool SphereProjector::project(const osg::Vec2& pointToProject, const osgUtil::Sc
// Get the near and far points for the mouse point.
osg::Vec3 nearPoint, farPoint;
sv.projectWindowXYIntoObject((int)pointToProject[0],(int)pointToProject[1],nearPoint,farPoint);
pi.projectWindowXYIntoObject(nearPoint,farPoint);
// Transform these points into local coordinates.
osg::Vec3 objectNearPoint, objectFarPoint;
@@ -364,10 +364,10 @@ bool SphereProjector::project(const osg::Vec2& pointToProject, const osgUtil::Sc
return getSphereLineIntersection(*_sphere, objectNearPoint, objectFarPoint, dontCare, projectedPoint);
}
bool SphereProjector::isPointInFront(const osg::Vec3& point, const osgUtil::SceneView& sv, const osg::Matrix& localToWorld) const
bool SphereProjector::isPointInFront(const Dragger::PointerInfo& pi, const osg::Matrix& localToWorld) const
{
osg::Vec3 centerToPoint = getSphere()->getCenter() - point;
if (centerToPoint * getEyeDirection(sv.getViewMatrix(), localToWorld) < 0.0)
osg::Vec3 centerToPoint = getSphere()->getCenter() - pi.getLocalIntersectPoint();
if (centerToPoint * getEyeDirection(pi.sv->getViewMatrix(), localToWorld) < 0.0)
return false;
return true;
}
@@ -449,17 +449,19 @@ osg::Quat SpherePlaneProjector::getRotation(const osg::Vec3& p1, bool p1OnSphere
}
}
bool SpherePlaneProjector::project(const osg::Vec2& pointToProject, const osgUtil::SceneView& sv, osg::Vec3& projectedPoint) const
bool SpherePlaneProjector::project(const Dragger::PointerInfo& pi, osg::Vec3& projectedPoint) const
{
if (!_sphere->valid())
{
osg::notify(osg::WARN) << "Warning: Invalid sphere. SpherePlaneProjector::project() failed." << std::endl;
return false;
}
const osg::Vec2 pointToProject = pi.pointToProject();
// Get the near and far points for the mouse point.
osg::Vec3 nearPoint, farPoint;
sv.projectWindowXYIntoObject((int)pointToProject[0],(int)pointToProject[1],nearPoint,farPoint);
pi.projectWindowXYIntoObject(nearPoint,farPoint);
// Transform these points into local coordinates.
osg::Vec3 objectNearPoint, objectFarPoint;
@@ -475,7 +477,7 @@ bool SpherePlaneProjector::project(const osg::Vec2& pointToProject, const osgUti
hitSphere = getSphereLineIntersection(*_sphere, objectNearPoint, objectFarPoint, dontCare, sphereIntersection);
// Compute plane oriented to the eye.
_plane = computePlaneThruPointAndOrientedToEye(sv.getViewMatrix(), getLocalToWorld(), getSphere()->getCenter(), _front);
_plane = computePlaneThruPointAndOrientedToEye(pi.getViewMatrix(), getLocalToWorld(), getSphere()->getCenter(), _front);
// Find the intersection on the plane.
osg::Vec3 planeIntersection;
@@ -522,7 +524,7 @@ CylinderProjector::~CylinderProjector()
{
}
bool CylinderProjector::project(const osg::Vec2& pointToProject, const osgUtil::SceneView& sv, osg::Vec3& projectedPoint) const
bool CylinderProjector::project(const Dragger::PointerInfo& pi, osg::Vec3& projectedPoint) const
{
if (!_cylinder.valid())
{
@@ -533,7 +535,7 @@ bool CylinderProjector::project(const osg::Vec2& pointToProject, const osgUtil::
// Get the near and far points for the mouse point.
osg::Vec3 nearPoint, farPoint;
sv.projectWindowXYIntoObject((int)pointToProject[0],(int)pointToProject[1],nearPoint,farPoint);
pi.projectWindowXYIntoObject(nearPoint,farPoint);
// Transform these points into local coordinates.
osg::Vec3 objectNearPoint, objectFarPoint;
@@ -545,14 +547,14 @@ bool CylinderProjector::project(const osg::Vec2& pointToProject, const osgUtil::
return getCylinderLineIntersection(*_cylinder, objectNearPoint, objectFarPoint, projectedPoint, dontCare);
}
bool CylinderProjector::isPointInFront(const osg::Vec3& point, const osgUtil::SceneView& sv, const osg::Matrix& localToWorld) const
bool CylinderProjector::isPointInFront(const Dragger::PointerInfo& pi, const osg::Matrix& localToWorld) const
{
osg::Vec3 closestPointOnAxis;
computeClosestPointOnLine(getCylinder()->getCenter(), getCylinder()->getCenter() + _cylinderAxis,
point, closestPointOnAxis);
pi.getLocalIntersectPoint(), closestPointOnAxis);
osg::Vec3 perpPoint = point - closestPointOnAxis;
if (perpPoint * getEyeDirection(sv.getViewMatrix(), localToWorld) < 0.0)
osg::Vec3 perpPoint = pi.getLocalIntersectPoint() - closestPointOnAxis;
if (perpPoint * getEyeDirection(pi.getViewMatrix(), localToWorld) < 0.0)
return false;
return true;
}
@@ -569,7 +571,7 @@ CylinderPlaneProjector::~CylinderPlaneProjector()
{
}
bool CylinderPlaneProjector::project(const osg::Vec2& pointToProject, const osgUtil::SceneView& sv, osg::Vec3& projectedPoint) const
bool CylinderPlaneProjector::project(const Dragger::PointerInfo& pi, osg::Vec3& projectedPoint) const
{
if (!_cylinder.valid())
{
@@ -580,7 +582,7 @@ bool CylinderPlaneProjector::project(const osg::Vec2& pointToProject, const osgU
// Get the near and far points for the mouse point.
osg::Vec3 nearPoint, farPoint;
sv.projectWindowXYIntoObject((int)pointToProject[0],(int)pointToProject[1],nearPoint,farPoint);
pi.projectWindowXYIntoObject(nearPoint,farPoint);
// Transform these points into local coordinates.
osg::Vec3 objectNearPoint, objectFarPoint;
@@ -602,7 +604,7 @@ bool CylinderPlaneProjector::project(const osg::Vec2& pointToProject, const osgU
}
// Compute plane oriented to the eye.
_plane = computePlaneParallelToAxisAndOrientedToEye(sv.getViewMatrix(), getLocalToWorld(), _cylinderAxis,
_plane = computePlaneParallelToAxisAndOrientedToEye(pi.getViewMatrix(), getLocalToWorld(), _cylinderAxis,
getCylinder()->getRadius(), _planeLineStart, _planeLineEnd,
_front);

View File

@@ -34,13 +34,10 @@ RotateCylinderDragger::~RotateCylinderDragger()
{
}
bool RotateCylinderDragger::handle(int pixel_x, int pixel_y, const osgUtil::SceneView& sv,
const osgUtil::IntersectVisitor::HitList&, const osgUtil::IntersectVisitor::HitList::iterator& hitIter,
const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa)
bool RotateCylinderDragger::handle(const PointerInfo& pointer, const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa)
{
// Check if the dragger node is in the nodepath.
if (std::find((*hitIter)._nodePath.begin(), (*hitIter)._nodePath.end(), this) == (*hitIter)._nodePath.end())
return false;
if (!pointer.contains(this)) return false;
switch (ea.getEventType())
{
@@ -56,13 +53,13 @@ bool RotateCylinderDragger::handle(int pixel_x, int pixel_y, const osgUtil::Scen
_startLocalToWorld = _projector->getLocalToWorld();
_startWorldToLocal = _projector->getWorldToLocal();
if (_projector->isPointInFront(hitIter->getLocalIntersectPoint(), sv, _startLocalToWorld))
if (_projector->isPointInFront(pointer, _startLocalToWorld))
_projector->setFront(true);
else
_projector->setFront(false);
osg::Vec3 projectedPoint;
if (_projector->project(osg::Vec2(pixel_x, pixel_y), sv, projectedPoint))
if (_projector->project(pointer, projectedPoint))
{
// Generate the motion command.
osg::ref_ptr<Rotate3DCommand> cmd = new Rotate3DCommand();
@@ -96,7 +93,7 @@ bool RotateCylinderDragger::handle(int pixel_x, int pixel_y, const osgUtil::Scen
_projector->setLocalToWorld(localToWorld);
osg::Vec3 projectedPoint;
if (_projector->project(osg::Vec2(pixel_x, pixel_y), sv, projectedPoint))
if (_projector->project(pointer, projectedPoint))
{
osg::Vec3 prevProjectedPoint = _prevWorldProjPt * _projector->getWorldToLocal();
osg::Quat deltaRotation = _projector->getRotation(prevProjectedPoint, _prevPtOnCylinder,

View File

@@ -35,13 +35,10 @@ RotateSphereDragger::~RotateSphereDragger()
{
}
bool RotateSphereDragger::handle(int pixel_x, int pixel_y, const osgUtil::SceneView& sv,
const osgUtil::IntersectVisitor::HitList&, const osgUtil::IntersectVisitor::HitList::iterator& hitIter,
const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa)
bool RotateSphereDragger::handle(const PointerInfo& pointer, const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa)
{
// Check if the dragger node is in the nodepath.
if (std::find((*hitIter)._nodePath.begin(), (*hitIter)._nodePath.end(), this) == (*hitIter)._nodePath.end())
return false;
if (!pointer.contains(this)) return false;
switch (ea.getEventType())
{
@@ -57,13 +54,13 @@ bool RotateSphereDragger::handle(int pixel_x, int pixel_y, const osgUtil::SceneV
_startLocalToWorld = _projector->getLocalToWorld();
_startWorldToLocal = _projector->getWorldToLocal();
if (_projector->isPointInFront(hitIter->getLocalIntersectPoint(), sv, _startLocalToWorld))
if (_projector->isPointInFront(pointer, _startLocalToWorld))
_projector->setFront(true);
else
_projector->setFront(false);
osg::Vec3 projectedPoint;
if (_projector->project(osg::Vec2(pixel_x, pixel_y), sv, projectedPoint))
if (_projector->project(pointer, projectedPoint))
{
// Generate the motion command.
osg::ref_ptr<Rotate3DCommand> cmd = new Rotate3DCommand();
@@ -98,7 +95,7 @@ bool RotateSphereDragger::handle(int pixel_x, int pixel_y, const osgUtil::SceneV
_projector->setLocalToWorld(localToWorld);
osg::Vec3 projectedPoint;
if (_projector->project(osg::Vec2(pixel_x, pixel_y), sv, projectedPoint))
if (_projector->project(pointer, projectedPoint))
{
osg::Vec3 prevProjectedPoint = _prevWorldProjPt * _projector->getWorldToLocal();
osg::Quat deltaRotation = _projector->getRotation(prevProjectedPoint, _prevPtOnSphere,

View File

@@ -47,13 +47,10 @@ Scale1DDragger::~Scale1DDragger()
{
}
bool Scale1DDragger::handle(int pixel_x, int pixel_y, const osgUtil::SceneView& sv,
const osgUtil::IntersectVisitor::HitList&, const osgUtil::IntersectVisitor::HitList::iterator& hitIter,
const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa)
bool Scale1DDragger::handle(const PointerInfo& pointer, const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa)
{
// Check if the dragger node is in the nodepath.
if (std::find((*hitIter)._nodePath.begin(), (*hitIter)._nodePath.end(), this) == (*hitIter)._nodePath.end())
return false;
if (!pointer.contains(this)) return false;
switch (ea.getEventType())
{
@@ -66,16 +63,14 @@ bool Scale1DDragger::handle(int pixel_x, int pixel_y, const osgUtil::SceneView&
osg::Matrix localToWorld = osg::computeLocalToWorld(nodePathToRoot);
_projector->setLocalToWorld(localToWorld);
if (_projector->project(osg::Vec2(pixel_x, pixel_y), sv, _startProjectedPoint))
if (_projector->project(pointer, _startProjectedPoint))
{
_scaleCenter = 0.0f;
if (_scaleMode == SCALE_WITH_OPPOSITE_HANDLE_AS_PIVOT)
{
if (std::find((*hitIter)._nodePath.begin(), (*hitIter)._nodePath.end(), _leftHandleNode.get())
!= (*hitIter)._nodePath.end())
if ( pointer.contains(_leftHandleNode.get()) )
_scaleCenter = _projector->getLineEnd()[0];
else if (std::find((*hitIter)._nodePath.begin(), (*hitIter)._nodePath.end(), _rightHandleNode.get())
!= (*hitIter)._nodePath.end())
else if ( pointer.contains( _rightHandleNode.get()) )
_scaleCenter = _projector->getLineStart()[0];
}
@@ -103,7 +98,7 @@ bool Scale1DDragger::handle(int pixel_x, int pixel_y, const osgUtil::SceneView&
case (osgGA::GUIEventAdapter::DRAG):
{
osg::Vec3 projectedPoint;
if (_projector->project(osg::Vec2(pixel_x, pixel_y), sv, projectedPoint))
if (_projector->project(pointer, projectedPoint))
{
// Generate the motion command.
osg::ref_ptr<Scale1DCommand> cmd = new Scale1DCommand();

View File

@@ -56,13 +56,10 @@ Scale2DDragger::~Scale2DDragger()
{
}
bool Scale2DDragger::handle(int pixel_x, int pixel_y, const osgUtil::SceneView& sv,
const osgUtil::IntersectVisitor::HitList&, const osgUtil::IntersectVisitor::HitList::iterator& hitIter,
const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa)
bool Scale2DDragger::handle(const PointerInfo& pointer, const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa)
{
// Check if the dragger node is in the nodepath.
if (std::find((*hitIter)._nodePath.begin(), (*hitIter)._nodePath.end(), this) == (*hitIter)._nodePath.end())
return false;
if (!pointer.contains(this)) return false;
switch (ea.getEventType())
{
@@ -75,33 +72,29 @@ bool Scale2DDragger::handle(int pixel_x, int pixel_y, const osgUtil::SceneView&
osg::Matrix localToWorld = osg::computeLocalToWorld(nodePathToRoot);
_projector->setLocalToWorld(localToWorld);
if (_projector->project(osg::Vec2(pixel_x, pixel_y), sv, _startProjectedPoint))
if (_projector->project(pointer, _startProjectedPoint))
{
_scaleCenter.set(0.0,0.0);
if (std::find((*hitIter)._nodePath.begin(), (*hitIter)._nodePath.end(), _topLeftHandleNode.get())
!= (*hitIter)._nodePath.end())
if (pointer.contains(_topLeftHandleNode.get()))
{
_referencePoint = _topLeftHandlePosition;
if (_scaleMode == SCALE_WITH_OPPOSITE_HANDLE_AS_PIVOT)
_scaleCenter = _bottomRightHandlePosition;
}
else if (std::find((*hitIter)._nodePath.begin(), (*hitIter)._nodePath.end(), _bottomLeftHandleNode.get())
!= (*hitIter)._nodePath.end())
else if (pointer.contains(_bottomLeftHandleNode.get()))
{
_referencePoint = _bottomLeftHandlePosition;
if (_scaleMode == SCALE_WITH_OPPOSITE_HANDLE_AS_PIVOT)
_scaleCenter = _topRightHandlePosition;
}
else if (std::find((*hitIter)._nodePath.begin(), (*hitIter)._nodePath.end(), _bottomRightHandleNode.get())
!= (*hitIter)._nodePath.end())
else if (pointer.contains(_bottomRightHandleNode.get()))
{
_referencePoint = _bottomRightHandlePosition;
if (_scaleMode == SCALE_WITH_OPPOSITE_HANDLE_AS_PIVOT)
_scaleCenter = _topLeftHandlePosition;
}
else if (std::find((*hitIter)._nodePath.begin(), (*hitIter)._nodePath.end(), _topRightHandleNode.get())
!= (*hitIter)._nodePath.end())
else if (pointer.contains(_topRightHandleNode.get()))
{
_referencePoint = _topRightHandlePosition;
if (_scaleMode == SCALE_WITH_OPPOSITE_HANDLE_AS_PIVOT)
@@ -134,7 +127,7 @@ bool Scale2DDragger::handle(int pixel_x, int pixel_y, const osgUtil::SceneView&
case (osgGA::GUIEventAdapter::DRAG):
{
osg::Vec3 projectedPoint;
if (_projector->project(osg::Vec2(pixel_x, pixel_y), sv, projectedPoint))
if (_projector->project(pointer, projectedPoint))
{
// Compute scale.
osg::Vec2 scale = computeScale(_startProjectedPoint,projectedPoint,_scaleCenter);

View File

@@ -217,39 +217,39 @@ TabPlaneDragger::~TabPlaneDragger()
{
}
bool TabPlaneDragger::handle(int pixel_x, int pixel_y, const osgUtil::SceneView& sv,
const osgUtil::IntersectVisitor::HitList& hl, const osgUtil::IntersectVisitor::HitList::iterator& hitIter,
const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa)
bool TabPlaneDragger::handle(const PointerInfo& pointer, const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa)
{
if (ea.getButtonMask() & osgGA::GUIEventAdapter::RIGHT_MOUSE_BUTTON) return false;
// Check if the dragger node is in the nodepath.
if (std::find((*hitIter)._nodePath.begin(), (*hitIter)._nodePath.end(), this) == (*hitIter)._nodePath.end())
return false;
if (!pointer.contains(this)) return false;
// Since the translate plane and the handleNode lie on the same plane the hit could've been on either one. But we
// need to handle the scaling draggers before the translation. Check if the node path has the scaling nodes else
// check for the scaling nodes in next hit.
if (_cornerScaleDragger->handle(pixel_x, pixel_y, sv, hl, hitIter, ea, aa))
if (_cornerScaleDragger->handle(pointer, ea, aa))
return true;
if (_horzEdgeScaleDragger->handle(pixel_x, pixel_y, sv, hl, hitIter, ea, aa))
if (_horzEdgeScaleDragger->handle(pointer, ea, aa))
return true;
if (_vertEdgeScaleDragger->handle(pixel_x, pixel_y, sv, hl, hitIter, ea, aa))
if (_vertEdgeScaleDragger->handle(pointer, ea, aa))
return true;
osgUtil::IntersectVisitor::HitList::iterator nextHit = hitIter + 1;
while (nextHit != hl.end())
PointerInfo nextPointer(pointer);
nextPointer.next();
while (!nextPointer.completed())
{
if (_cornerScaleDragger->handle(pixel_x, pixel_y, sv, hl, nextHit, ea, aa))
if (_cornerScaleDragger->handle(nextPointer, ea, aa))
return true;
if (_horzEdgeScaleDragger->handle(pixel_x, pixel_y, sv, hl, nextHit, ea, aa))
if (_horzEdgeScaleDragger->handle(nextPointer, ea, aa))
return true;
if (_vertEdgeScaleDragger->handle(pixel_x, pixel_y, sv, hl, nextHit, ea, aa))
if (_vertEdgeScaleDragger->handle(nextPointer, ea, aa))
return true;
++nextHit;
nextPointer.next();
}
if (_translateDragger->handle(pixel_x, pixel_y, sv, hl, hitIter, ea, aa))
if (_translateDragger->handle(pointer, ea, aa))
return true;
return false;

View File

@@ -41,15 +41,12 @@ Translate1DDragger::~Translate1DDragger()
{
}
bool Translate1DDragger::handle(int pixel_x, int pixel_y, const osgUtil::SceneView& sv,
const osgUtil::IntersectVisitor::HitList&, const osgUtil::IntersectVisitor::HitList::iterator& hitIter,
const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa)
bool Translate1DDragger::handle(const PointerInfo& pointer, const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa)
{
// Check if the dragger node is in the nodepath.
if (_checkForNodeInNodePath)
{
if (std::find((*hitIter)._nodePath.begin(), (*hitIter)._nodePath.end(), this) == (*hitIter)._nodePath.end())
return false;
if (!pointer.contains(this)) return false;
}
switch (ea.getEventType())
@@ -63,7 +60,7 @@ bool Translate1DDragger::handle(int pixel_x, int pixel_y, const osgUtil::SceneVi
osg::Matrix localToWorld = osg::computeLocalToWorld(nodePathToRoot);
_projector->setLocalToWorld(localToWorld);
if (_projector->project(osg::Vec2(pixel_x, pixel_y), sv, _startProjectedPoint))
if (_projector->project(pointer, _startProjectedPoint))
{
// Generate the motion command.
osg::ref_ptr<TranslateInLineCommand> cmd = new TranslateInLineCommand(_projector->getLineStart(),
@@ -90,7 +87,7 @@ bool Translate1DDragger::handle(int pixel_x, int pixel_y, const osgUtil::SceneVi
case (osgGA::GUIEventAdapter::DRAG):
{
osg::Vec3 projectedPoint;
if (_projector->project(osg::Vec2(pixel_x, pixel_y), sv, projectedPoint))
if (_projector->project(pointer, projectedPoint))
{
// Generate the motion command.
osg::ref_ptr<TranslateInLineCommand> cmd = new TranslateInLineCommand(_projector->getLineStart(),
@@ -115,7 +112,7 @@ bool Translate1DDragger::handle(int pixel_x, int pixel_y, const osgUtil::SceneVi
case (osgGA::GUIEventAdapter::RELEASE):
{
osg::Vec3 projectedPoint;
if (_projector->project(osg::Vec2(pixel_x, pixel_y), sv, projectedPoint))
if (_projector->project(pointer, projectedPoint))
{
osg::ref_ptr<TranslateInLineCommand> cmd = new TranslateInLineCommand(_projector->getLineStart(),
_projector->getLineEnd());

View File

@@ -43,14 +43,10 @@ Translate2DDragger::~Translate2DDragger()
{
}
bool Translate2DDragger::handle(int pixel_x, int pixel_y, const osgUtil::SceneView& sv,
const osgUtil::IntersectVisitor::HitList&,
const osgUtil::IntersectVisitor::HitList::iterator& hitIter,
const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa)
bool Translate2DDragger::handle(const PointerInfo& pointer, const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa)
{
// Check if the dragger node is in the nodepath.
if (std::find((*hitIter)._nodePath.begin(), (*hitIter)._nodePath.end(), this) == (*hitIter)._nodePath.end())
return false;
if (!pointer.contains(this)) return false;
switch (ea.getEventType())
{
@@ -63,7 +59,7 @@ bool Translate2DDragger::handle(int pixel_x, int pixel_y, const osgUtil::SceneVi
osg::Matrix localToWorld = osg::computeLocalToWorld(nodePathToRoot);
_projector->setLocalToWorld(localToWorld);
if (_projector->project(osg::Vec2((float)pixel_x, (float)pixel_y), sv, _startProjectedPoint))
if (_projector->project(pointer, _startProjectedPoint))
{
// Generate the motion command.
osg::ref_ptr<TranslateInPlaneCommand> cmd = new TranslateInPlaneCommand(_projector->getPlane());
@@ -92,7 +88,7 @@ bool Translate2DDragger::handle(int pixel_x, int pixel_y, const osgUtil::SceneVi
case (osgGA::GUIEventAdapter::DRAG):
{
osg::Vec3 projectedPoint;
if (_projector->project(osg::Vec2(pixel_x, pixel_y), sv, projectedPoint))
if (_projector->project(pointer, projectedPoint))
{
// Generate the motion command.
osg::ref_ptr<TranslateInPlaneCommand> cmd = new TranslateInPlaneCommand(_projector->getPlane());

View File

@@ -43,14 +43,10 @@ TranslatePlaneDragger::~TranslatePlaneDragger()
{
}
bool TranslatePlaneDragger::handle(int pixel_x, int pixel_y, const osgUtil::SceneView& sv,
const osgUtil::IntersectVisitor::HitList& hl,
const osgUtil::IntersectVisitor::HitList::iterator& hitIter,
const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa)
bool TranslatePlaneDragger::handle(const PointerInfo& pointer, const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa)
{
// Check if the dragger node is in the nodepath.
if (std::find((*hitIter)._nodePath.begin(), (*hitIter)._nodePath.end(), this) == (*hitIter)._nodePath.end())
return false;
if (!pointer.contains(this)) return false;
if ((ea.getButtonMask() & osgGA::GUIEventAdapter::MIDDLE_MOUSE_BUTTON) &&
ea.getEventType() == osgGA::GUIEventAdapter::PUSH)
@@ -59,12 +55,12 @@ bool TranslatePlaneDragger::handle(int pixel_x, int pixel_y, const osgUtil::Scen
bool handled = false;
if (_usingTranslate1DDragger)
{
if (_translate1DDragger->handle(pixel_x, pixel_y, sv, hl, hitIter, ea, aa))
if (_translate1DDragger->handle(pointer, ea, aa))
handled = true;
}
else
{
if (_translate2DDragger->handle(pixel_x, pixel_y, sv, hl, hitIter, ea, aa))
if (_translate2DDragger->handle(pointer, ea, aa))
handled = true;
}