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

@@ -201,8 +201,9 @@ class PickModeHandler : public osgGA::GUIEventHandler
for(unsigned int i=0;i<_viewer->getNumberOfCameras();++i)
{
if ((ea.getEventType() == osgGA::GUIEventAdapter::PUSH) &&
_viewer->computeIntersections(ea.getX(), ea.getY(), i, hitList))
_viewer->computeIntersections(ea.getX(), ea.getY(), i, _pointer.hitList))
{
float pixel_x,pixel_y;
if (computePixelCoords(_viewer,ea.getX(),ea.getY(),i,pixel_x,pixel_y))
@@ -212,17 +213,21 @@ class PickModeHandler : public osgGA::GUIEventHandler
osgProducer::OsgSceneHandler* sh = dynamic_cast<osgProducer::OsgSceneHandler*>(camera->getSceneHandler());
osgUtil::SceneView* sv = sh ? sh->getSceneView() : 0;
if (! sv) continue;
_pointer.pixel_x = int(pixel_x+0.5);
_pointer.pixel_y = int(pixel_y+0.5);
_pointer.sv = sv;
_pointer.hitIter = _pointer.hitList.begin();
for (osg::NodePath::iterator itr = hitList.front().getNodePath().begin();
itr != hitList.front().getNodePath().end();
for (osg::NodePath::iterator itr = _pointer.hitList.front().getNodePath().begin();
itr != _pointer.hitList.front().getNodePath().end();
++itr)
{
osgManipulator::Dragger* dragger = dynamic_cast<osgManipulator::Dragger*>(*itr);
if (dragger)
{
dragger->handle(int(pixel_x+0.5), int(pixel_y+0.5), *sv,
hitList, hitList.begin(),
ea, aa);
dragger->handle(_pointer, ea, aa);
_activeDragger = dragger;
break;
}
@@ -244,9 +249,14 @@ class PickModeHandler : public osgGA::GUIEventHandler
osgProducer::OsgSceneHandler* sh = dynamic_cast<osgProducer::OsgSceneHandler*>(camera->getSceneHandler());
osgUtil::SceneView* sv = sh ? sh->getSceneView() : 0;
if (_activeDragger && sv)
_activeDragger->handle(int(pixel_x+0.5), int(pixel_y+0.5), *sv,
hitList, hitList.begin(),
ea, aa);
{
_pointer.pixel_x = int(pixel_x+0.5);
_pointer.pixel_y = int(pixel_y+0.5);
_pointer.sv = sv;
_pointer.hitIter = _pointer.hitList.begin();
_activeDragger->handle(_pointer, ea, aa);
}
}
}
break;
@@ -257,7 +267,7 @@ class PickModeHandler : public osgGA::GUIEventHandler
if (ea.getEventType() == osgGA::GUIEventAdapter::RELEASE)
{
_activeDragger = 0;
hitList.clear();
_pointer.hitList.clear();
}
}
return true;
@@ -267,7 +277,7 @@ class PickModeHandler : public osgGA::GUIEventHandler
osgProducer::Viewer* _viewer;
unsigned int _mode;
osgManipulator::Dragger* _activeDragger;
osgUtil::IntersectVisitor::HitList hitList;
osgManipulator::Dragger::PointerInfo _pointer;
};
int main( int argc, char **argv )

View File

@@ -59,11 +59,47 @@ class OSGMANIPULATOR_EXPORT Dragger : public Selection
/** Returns 0 if this Dragger is not a CompositeDragger. */
virtual CompositeDragger* getComposite() { return 0; }
struct OSGMANIPULATOR_EXPORT PointerInfo
{
PointerInfo();
virtual bool handle(int, int, const osgUtil::SceneView&,
const osgUtil::IntersectVisitor::HitList&,
const osgUtil::IntersectVisitor::HitList::iterator&,
const osgGA::GUIEventAdapter&, osgGA::GUIActionAdapter&) { return false; }
PointerInfo(const PointerInfo& rhs):
pixel_x(rhs.pixel_x),
pixel_y(rhs.pixel_y),
sv(rhs.sv),
hitList(rhs.hitList)
{
hitIter = hitList.begin();
}
bool completed() const { return hitIter==hitList.end(); }
void next()
{
if (!completed()) ++hitIter;
}
int pixel_x, pixel_y;
osgUtil::SceneView* sv;
osgUtil::IntersectVisitor::HitList hitList;
osgUtil::IntersectVisitor::HitList::iterator hitIter;
osg::Vec2 pointToProject() const { return osg::Vec2(pixel_x, pixel_y); }
osg::Vec3 getLocalIntersectPoint() const { return hitIter->getLocalIntersectPoint(); }
bool projectWindowXYIntoObject(const osg::Vec2& windowCoord, osg::Vec3& nearPoint, osg::Vec3& farPoint) const { return sv->projectWindowXYIntoObject(static_cast<int>(windowCoord.x()), static_cast<int>(windowCoord.y()), nearPoint, farPoint); }
bool projectWindowXYIntoObject(osg::Vec3& nearPoint, osg::Vec3& farPoint) const { return sv->projectWindowXYIntoObject(pixel_x, pixel_y, nearPoint, farPoint); }
const osg::Matrix& getViewMatrix() const { return sv->getViewMatrix(); }
bool contains(const osg::Node* node) const;
};
virtual bool handle(const PointerInfo&, const osgGA::GUIEventAdapter&, osgGA::GUIActionAdapter&) { return false; }
protected:
@@ -94,10 +130,7 @@ class OSGMANIPULATOR_EXPORT CompositeDragger : public Dragger
virtual void setParentDragger(Dragger* parent);
virtual bool handle(int pixel_x, int pixel_y, const osgUtil::SceneView& sv,
const osgUtil::IntersectVisitor::HitList& hitList,
const osgUtil::IntersectVisitor::HitList::iterator& hitIter,
const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa);
virtual bool handle(const PointerInfo& pi, const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa);
// Composite-specific methods below
virtual bool addDragger(Dragger* dragger);

View File

@@ -20,6 +20,8 @@
#include <osg/LineSegment>
#include <osgUtil/SceneView>
#include <osgManipulator/Dragger>
namespace osgManipulator {
/**
@@ -38,7 +40,7 @@ class OSGMANIPULATOR_EXPORT Projector : public osg::Referenced
* projecting window coordinates into object coordinates and vice versa.
* Returns true on successful projection.
*/
virtual bool project(const osg::Vec2& pointToProject, const osgUtil::SceneView& sv, osg::Vec3& projectedPoint) const = 0;
virtual bool project(const Dragger::PointerInfo& pi, osg::Vec3& projectedPoint) const = 0;
/**
* Sets the matrix for transforming the projector's local coordinate
@@ -103,7 +105,7 @@ class OSGMANIPULATOR_EXPORT LineProjector : public Projector
* coordinate (pointToProject) when projected onto the given line.
* Returns true on successful projection.
*/
virtual bool project(const osg::Vec2& pointToProject, const osgUtil::SceneView& sv, osg::Vec3& projectedPoint) const;
virtual bool project(const Dragger::PointerInfo& pi, osg::Vec3& projectedPoint) const;
protected:
@@ -131,7 +133,7 @@ class OSGMANIPULATOR_EXPORT PlaneProjector : public Projector
* coordinate (pointToProject) when projected onto the given plane.
* Returns true on successful projection.
*/
virtual bool project(const osg::Vec2& pointToProject, const osgUtil::SceneView& sv, osg::Vec3& projectedPoint) const;
virtual bool project(const Dragger::PointerInfo& pi, osg::Vec3& projectedPoint) const;
protected:
@@ -159,13 +161,13 @@ class OSGMANIPULATOR_EXPORT SphereProjector : public Projector
* coordinate (pointToProject) when projected onto the given sphere.
* Returns true on successful projection.
*/
virtual bool project(const osg::Vec2& pointToProject, const osgUtil::SceneView& sv, osg::Vec3& projectedPoint) const;
virtual bool project(const Dragger::PointerInfo& pi, osg::Vec3& projectedPoint) const;
/**
* Returns true is the point is in front of the cylinder given the eye
* direction.
*/
bool isPointInFront(const osg::Vec3& point, const osgUtil::SceneView& sv, const osg::Matrix& localToWorld) const;
bool isPointInFront(const Dragger::PointerInfo& pi, const osg::Matrix& localToWorld) const;
void setFront(bool front) { _front = front; }
@@ -194,7 +196,7 @@ class OSGMANIPULATOR_EXPORT SpherePlaneProjector : public SphereProjector
* coordinate (pointToProject) when projected onto the given sphere.
* Returns true on successful projection.
*/
virtual bool project(const osg::Vec2& pointToProject, const osgUtil::SceneView& sv, osg::Vec3& projectedPoint) const;
virtual bool project(const Dragger::PointerInfo& pi, osg::Vec3& projectedPoint) const;
/**
* Returns true if the previous projection was on the sphere and false
@@ -238,14 +240,14 @@ class OSGMANIPULATOR_EXPORT CylinderProjector : public Projector
* coordinate (pointToProject) when projected onto the given plane.
* Returns true on successful projection.
*/
virtual bool project(const osg::Vec2& pointToProject, const osgUtil::SceneView& sv, osg::Vec3& projectedPoint) const;
virtual bool project(const Dragger::PointerInfo& pi, osg::Vec3& projectedPoint) const;
/**
* Returns true is the point is in front of the cylinder given the eye
* direction.
*/
bool isPointInFront(const osg::Vec3& point, const osgUtil::SceneView& sv, const osg::Matrix& localToWorld) const;
bool isPointInFront(const Dragger::PointerInfo& pi, const osg::Matrix& localToWorld) const;
void setFront(bool front) { _front = front; }
@@ -274,7 +276,7 @@ class OSGMANIPULATOR_EXPORT CylinderPlaneProjector : public CylinderProjector
* coordinate (pointToProject) when projected onto the given plane.
* Returns true on successful projection.
*/
virtual bool project(const osg::Vec2& pointToProject, const osgUtil::SceneView& sv, osg::Vec3& projectedPoint) const;
virtual bool project(const Dragger::PointerInfo& pi, osg::Vec3& projectedPoint) const;
/**
* Returns true if the previous projection was on the cylinder and

View File

@@ -32,10 +32,7 @@ class OSGMANIPULATOR_EXPORT RotateCylinderDragger : public Dragger
/**
* Handle pick events on dragger and generate TranslateInLine commands.
*/
virtual bool handle(int pixel_x, int pixel_y, const osgUtil::SceneView& sv,
const osgUtil::IntersectVisitor::HitList& hitList,
const osgUtil::IntersectVisitor::HitList::iterator& hitIter,
const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& us);
virtual bool handle(const PointerInfo& pi, const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& us);
/** Setup default geometry for dragger. */
void setupDefaultGeometry();

View File

@@ -32,10 +32,7 @@ class OSGMANIPULATOR_EXPORT RotateSphereDragger : public Dragger
/**
* Handle pick events on dragger and generate TranslateInLine commands.
*/
virtual bool handle(int pixel_x, int pixel_y, const osgUtil::SceneView& sv,
const osgUtil::IntersectVisitor::HitList& hitList,
const osgUtil::IntersectVisitor::HitList::iterator& hitIter,
const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& us);
virtual bool handle(const PointerInfo&, const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& us);
/** Setup default geometry for dragger. */
void setupDefaultGeometry();

View File

@@ -38,10 +38,7 @@ class OSGMANIPULATOR_EXPORT Scale1DDragger : public Dragger
/**
* Handle pick events on dragger and generate TranslateInLine commands.
*/
virtual bool handle(int pixel_x, int pixel_y, const osgUtil::SceneView& sv,
const osgUtil::IntersectVisitor::HitList& hitList,
const osgUtil::IntersectVisitor::HitList::iterator& hitIter,
const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& us);
virtual bool handle(const PointerInfo& pi, const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& us);
/** Setup default geometry for dragger. */
void setupDefaultGeometry();

View File

@@ -38,10 +38,7 @@ class OSGMANIPULATOR_EXPORT Scale2DDragger : public Dragger
/**
* Handle pick events on dragger and generate TranslateInLine commands.
*/
virtual bool handle(int pixel_x, int pixel_y, const osgUtil::SceneView& sv,
const osgUtil::IntersectVisitor::HitList& hitList,
const osgUtil::IntersectVisitor::HitList::iterator& hitIter,
const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& us);
virtual bool handle(const PointerInfo& pi, const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& us);
/** Setup default geometry for dragger. */
void setupDefaultGeometry();

View File

@@ -31,10 +31,7 @@ class OSGMANIPULATOR_EXPORT TabPlaneDragger : public CompositeDragger
TabPlaneDragger();
virtual bool handle(int pixel_x, int pixel_y, const osgUtil::SceneView& sv,
const osgUtil::IntersectVisitor::HitList& hitList,
const osgUtil::IntersectVisitor::HitList::iterator& hit,
const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& us);
virtual bool handle(const PointerInfo& pi, const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& us);
/** Setup default geometry for dragger. */
void setupDefaultGeometry(bool twoSidedHandle = true);

View File

@@ -33,10 +33,7 @@ class OSGMANIPULATOR_EXPORT Translate1DDragger : public Dragger
Translate1DDragger(const osg::Vec3& s, const osg::Vec3& e);
/** Handle pick events on dragger and generate TranslateInLine commands. */
virtual bool handle(int pixel_x, int pixel_y, const osgUtil::SceneView& sv,
const osgUtil::IntersectVisitor::HitList& hitList,
const osgUtil::IntersectVisitor::HitList::iterator& hit,
const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& us);
virtual bool handle(const PointerInfo& pi, const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& us);
/** Setup default geometry for dragger. */
void setupDefaultGeometry();

View File

@@ -34,10 +34,7 @@ class OSGMANIPULATOR_EXPORT Translate2DDragger : public Dragger
Translate2DDragger(const osg::Plane& plane);
/** Handle pick events on dragger and generate TranslateInLine commands. */
virtual bool handle(int pixel_x, int pixel_y, const osgUtil::SceneView& sv,
const osgUtil::IntersectVisitor::HitList& hitList,
const osgUtil::IntersectVisitor::HitList::iterator& hit,
const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& us);
virtual bool handle(const PointerInfo& pi, const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& us);
/** Setup default geometry for dragger. */
void setupDefaultGeometry();

View File

@@ -30,10 +30,7 @@ class OSGMANIPULATOR_EXPORT TranslatePlaneDragger : public CompositeDragger
TranslatePlaneDragger();
virtual bool handle(int pixel_x, int pixel_y, const osgUtil::SceneView& sv,
const osgUtil::IntersectVisitor::HitList& hitList,
const osgUtil::IntersectVisitor::HitList::iterator& hit,
const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& us);
virtual bool handle(const PointerInfo& pi, const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& us);
/** Setup default geometry for dragger. */
void setupDefaultGeometry();

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;
}