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

@@ -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();