Completed refactor of osgManipulator, key changes are:
Selection is now just a typedef of osg::MatrixTransform, and is deprecated CommandManager is shell class that just sets values directly on Dragger, and is deprecated Dragger now has list of DraggerCallback that takes over the roll of tracking changes to the Dragger, and allows users to track the dragger in any way they wish. Dragger now has a convinience method making MatrixTransforms track a dragger. Selection and CommandManager are no longer required for use of osgManipulator and are kept around for backwards compatibility.
This commit is contained in:
@@ -16,7 +16,6 @@
|
||||
#define OSGMANIPULATOR_COMMAND 1
|
||||
|
||||
#include <osgManipulator/Export>
|
||||
#include <osgManipulator/Selection>
|
||||
|
||||
#include <osg/LineSegment>
|
||||
#include <osg/Plane>
|
||||
@@ -55,7 +54,7 @@ class OSGMANIPULATOR_EXPORT MotionCommand : public osg::Referenced
|
||||
virtual MotionCommand* createCommandInverse() = 0;
|
||||
|
||||
/**
|
||||
* Gets the matrix for transforming the Selection. This matrix is in the
|
||||
* Gets the matrix for transforming the object being dragged. This matrix is in the
|
||||
* command's coordinate systems.
|
||||
*/
|
||||
virtual osg::Matrix getMotionMatrix() const = 0;
|
||||
|
||||
@@ -22,29 +22,55 @@
|
||||
namespace osgManipulator {
|
||||
|
||||
/**
|
||||
* Deprecated. CommandManager class is now no longer required as Dragger now matains all references to Constraints and Selections.
|
||||
* Deprecated.
|
||||
* CommandManager class is now no longer required as Dragger now matains all references to Constraints and Selections (now just generic MatrixTransforms).
|
||||
* To replace CommandManager usage simple replace cmdMgr->connect(*dragger, *selection) with dragger->addTransformUpdating(selection) and
|
||||
* cmdMgr->connect(*dragger, *selection) with dragger->addConstaint(constraint).
|
||||
*/
|
||||
class OSGMANIPULATOR_EXPORT CommandManager : public osg::Referenced
|
||||
class CommandManager : public osg::Referenced
|
||||
{
|
||||
public:
|
||||
CommandManager();
|
||||
|
||||
/**
|
||||
* Connect a dragger to a selection. The selection will begin listening
|
||||
* to commands generated by the dragger. This can be called multiple
|
||||
* times to connect many selections to a dragger.
|
||||
*/
|
||||
virtual bool connect(Dragger& dragger, Selection& selection);
|
||||
bool connect(Dragger& dragger, Selection& selection)
|
||||
{
|
||||
dragger.addTransformUpdating(&selection);
|
||||
|
||||
virtual bool connect(Dragger& dragger, Constraint& constrain);
|
||||
return true;
|
||||
}
|
||||
|
||||
/** Disconnect the selections from a dragger. */
|
||||
virtual bool disconnect(Dragger& dragger);
|
||||
bool connect(Dragger& dragger, Constraint& constraint)
|
||||
{
|
||||
dragger.addConstraint(&constraint);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool disconnect(Dragger& dragger)
|
||||
{
|
||||
dragger.getConstraints().clear();
|
||||
dragger.getDraggerCallbacks().clear();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
typedef std::list< osg::ref_ptr<Selection> > Selections;
|
||||
|
||||
/** Returns the selections connected to the dragger */
|
||||
Selections getConnectedSelections(Dragger& dragger);
|
||||
Selections getConnectedSelections(Dragger& dragger)
|
||||
{
|
||||
Selections selections;
|
||||
|
||||
for(Dragger::DraggerCallbacks::iterator itr = dragger.getDraggerCallbacks().begin();
|
||||
itr != dragger.getDraggerCallbacks().end();
|
||||
++itr)
|
||||
{
|
||||
DraggerCallback* dc = itr->get();
|
||||
DraggerTransformCallback* dtc = dynamic_cast<DraggerTransformCallback*>(dc);
|
||||
if (dtc && dtc->getTransform()) selections.push_back(dtc->getTransform());
|
||||
}
|
||||
|
||||
return selections;
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
|
||||
@@ -15,11 +15,11 @@
|
||||
#ifndef OSGMANIPULATOR_DRAGGER
|
||||
#define OSGMANIPULATOR_DRAGGER 1
|
||||
|
||||
#include <osgManipulator/Selection>
|
||||
#include <osgManipulator/Constraint>
|
||||
#include <osgManipulator/Command>
|
||||
|
||||
#include <osg/BoundingSphere>
|
||||
#include <osg/MatrixTransform>
|
||||
#include <osgUtil/SceneView>
|
||||
#include <osgUtil/IntersectVisitor>
|
||||
#include <osgGA/GUIEventAdapter>
|
||||
@@ -29,6 +29,57 @@ namespace osgManipulator
|
||||
{
|
||||
|
||||
class CompositeDragger;
|
||||
class MotionCommand;
|
||||
class TranslateInLineCommand;
|
||||
class TranslateInPlaneCommand;
|
||||
class Scale1DCommand;
|
||||
class Scale2DCommand;
|
||||
class ScaleUniformCommand;
|
||||
class Rotate3DCommand;
|
||||
|
||||
/** Computes the nodepath from the given node all the way upto the root. */
|
||||
extern OSGMANIPULATOR_EXPORT void computeNodePathToRoot(osg::Node& node, osg::NodePath& np);
|
||||
|
||||
class DraggerCallback : virtual public osg::Object
|
||||
{
|
||||
public:
|
||||
DraggerCallback() {}
|
||||
DraggerCallback(const DraggerCallback&, const osg::CopyOp& copyop = osg::CopyOp::SHALLOW_COPY) {}
|
||||
|
||||
META_Object(osgManipulator, DraggerCallback);
|
||||
|
||||
/**
|
||||
* Receive motion commands. Returns true on success.
|
||||
*/
|
||||
virtual bool receive(const MotionCommand&) { return false; }
|
||||
virtual bool receive(const TranslateInLineCommand& command) { return receive((MotionCommand&)command); }
|
||||
virtual bool receive(const TranslateInPlaneCommand& command) { return receive((MotionCommand&)command); }
|
||||
virtual bool receive(const Scale1DCommand& command) { return receive((MotionCommand&)command); }
|
||||
virtual bool receive(const Scale2DCommand& command) { return receive((MotionCommand&)command); }
|
||||
virtual bool receive(const ScaleUniformCommand& command) { return receive((MotionCommand&)command); }
|
||||
virtual bool receive(const Rotate3DCommand& command) { return receive((MotionCommand&)command); }
|
||||
};
|
||||
|
||||
class OSGMANIPULATOR_EXPORT DraggerTransformCallback : public DraggerCallback
|
||||
{
|
||||
public:
|
||||
|
||||
DraggerTransformCallback(osg::MatrixTransform* transform);
|
||||
|
||||
virtual bool receive(const MotionCommand&);
|
||||
|
||||
osg::MatrixTransform* getTransform() { return _transform.get(); }
|
||||
const osg::MatrixTransform* getTransform() const { return _transform.get(); }
|
||||
|
||||
protected:
|
||||
|
||||
osg::observer_ptr<osg::MatrixTransform> _transform;
|
||||
osg::Matrix _startMotionMatrix;
|
||||
|
||||
osg::Matrix _localToWorld;
|
||||
osg::Matrix _worldToLocal;
|
||||
};
|
||||
|
||||
|
||||
class OSGMANIPULATOR_EXPORT PointerInfo
|
||||
{
|
||||
@@ -137,14 +188,15 @@ class OSGMANIPULATOR_EXPORT PointerInfo
|
||||
/**
|
||||
* Base class for draggers. Concrete draggers implement the pick event handler
|
||||
* and generate motion commands (translate, rotate, ...) and sends these
|
||||
* command to all the Selections that are connected to the Dragger that generates the
|
||||
* command to all the DraggerCallbacks & Transforms that are connected to the Dragger that generates the
|
||||
* commands.
|
||||
*/
|
||||
class OSGMANIPULATOR_EXPORT Dragger : public Selection, public osg::Observer
|
||||
class OSGMANIPULATOR_EXPORT Dragger : public osg::MatrixTransform
|
||||
{
|
||||
public:
|
||||
|
||||
META_OSGMANIPULATOR_Object(osgManipulator,Dragger)
|
||||
|
||||
META_Node(osgManipulator,Dragger)
|
||||
|
||||
/**
|
||||
* Set/Get parent dragger. For simple draggers parent points to itself.
|
||||
@@ -184,20 +236,26 @@ class OSGMANIPULATOR_EXPORT Dragger : public Selection, public osg::Observer
|
||||
const Constraints& getConstraints() const { return _constraints; }
|
||||
|
||||
|
||||
typedef std::vector< Selection* > Selections;
|
||||
void addSelection(Selection* selection);
|
||||
void removeSelection(Selection* selection);
|
||||
typedef std::vector< osg::ref_ptr<DraggerCallback> > DraggerCallbacks;
|
||||
|
||||
Selections& getSelections() { return _selections; }
|
||||
const Selections& getSelections() const { return _selections; }
|
||||
void addDraggerCallback(DraggerCallback* dc);
|
||||
void removeDraggerCallback(DraggerCallback* dc);
|
||||
|
||||
DraggerCallbacks& getDraggerCallbacks() { return _draggerCallbacks; }
|
||||
const DraggerCallbacks& getDraggerCallbacks() const { return _draggerCallbacks; }
|
||||
|
||||
void addTransformUpdating(MatrixTransform* transform);
|
||||
void removeTransformUpdating(MatrixTransform* transform);
|
||||
|
||||
protected:
|
||||
|
||||
Dragger();
|
||||
Dragger(const Dragger& rhs, const osg::CopyOp& copyop = osg::CopyOp::SHALLOW_COPY);
|
||||
|
||||
virtual ~Dragger();
|
||||
|
||||
virtual bool receive(const MotionCommand& command);
|
||||
void dispatch(MotionCommand& command);
|
||||
virtual void objectDeleted(void* object);
|
||||
|
||||
bool _handleEvents;
|
||||
bool _draggerActive;
|
||||
@@ -205,8 +263,9 @@ class OSGMANIPULATOR_EXPORT Dragger : public Selection, public osg::Observer
|
||||
|
||||
Dragger* _parentDragger;
|
||||
|
||||
osg::ref_ptr<DraggerCallback> _selfUpdater;
|
||||
Constraints _constraints;
|
||||
Selections _selections;
|
||||
DraggerCallbacks _draggerCallbacks;
|
||||
|
||||
};
|
||||
|
||||
@@ -219,7 +278,7 @@ class OSGMANIPULATOR_EXPORT CompositeDragger : public Dragger
|
||||
{
|
||||
public:
|
||||
|
||||
META_OSGMANIPULATOR_Object(osgManipulator,CompositeDragger)
|
||||
META_Node(osgManipulator,CompositeDragger)
|
||||
|
||||
typedef std::vector< osg::ref_ptr<Dragger> > DraggerList;
|
||||
|
||||
@@ -242,6 +301,8 @@ class OSGMANIPULATOR_EXPORT CompositeDragger : public Dragger
|
||||
protected:
|
||||
|
||||
CompositeDragger() {}
|
||||
CompositeDragger(const CompositeDragger& rhs, const osg::CopyOp& copyop = osg::CopyOp::SHALLOW_COPY);
|
||||
|
||||
virtual ~CompositeDragger() {}
|
||||
|
||||
DraggerList _draggerList;
|
||||
|
||||
@@ -27,6 +27,12 @@
|
||||
# define OSGMANIPULATOR_EXPORT
|
||||
#endif
|
||||
|
||||
#define META_OSGMANIPULATOR_Object(library,name) \
|
||||
virtual bool isSameKindAs(const osg::Object* obj) const { return dynamic_cast<const name *>(obj)!=NULL; } \
|
||||
virtual const char* libraryName() const { return #library; }\
|
||||
virtual const char* className() const { return #name; }
|
||||
|
||||
|
||||
/**
|
||||
|
||||
\namespace osgManipulator
|
||||
|
||||
@@ -20,71 +20,8 @@
|
||||
|
||||
namespace osgManipulator {
|
||||
|
||||
class MotionCommand;
|
||||
class TranslateInLineCommand;
|
||||
class TranslateInPlaneCommand;
|
||||
class Scale1DCommand;
|
||||
class Scale2DCommand;
|
||||
class ScaleUniformCommand;
|
||||
class Rotate3DCommand;
|
||||
|
||||
/** Computes the nodepath from the given node all the way upto the root. */
|
||||
extern OSGMANIPULATOR_EXPORT void computeNodePathToRoot(osg::Node& node, osg::NodePath& np);
|
||||
|
||||
|
||||
|
||||
#define META_OSGMANIPULATOR_Object(library,name) \
|
||||
virtual bool isSameKindAs(const osg::Object* obj) const { return dynamic_cast<const name *>(obj)!=NULL; } \
|
||||
virtual const char* libraryName() const { return #library; }\
|
||||
virtual const char* className() const { return #name; }
|
||||
|
||||
|
||||
|
||||
class CommandProcessor
|
||||
{
|
||||
public:
|
||||
virtual bool receive(const MotionCommand&) = 0;
|
||||
virtual bool receive(const TranslateInLineCommand& command) = 0;
|
||||
virtual bool receive(const TranslateInPlaneCommand& command) = 0;
|
||||
virtual bool receive(const Scale1DCommand& command) = 0;
|
||||
virtual bool receive(const Scale2DCommand& command) = 0;
|
||||
virtual bool receive(const ScaleUniformCommand& command) = 0;
|
||||
virtual bool receive(const Rotate3DCommand& command) = 0;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Selection listens to motion commands generated by draggers.
|
||||
*/
|
||||
class OSGMANIPULATOR_EXPORT Selection : public osg::MatrixTransform
|
||||
{
|
||||
public:
|
||||
|
||||
Selection();
|
||||
|
||||
META_OSGMANIPULATOR_Object(osgManipulator,Selection)
|
||||
|
||||
/**
|
||||
* Receive motion commands and set the MatrixTransform accordingly to
|
||||
* transform selections. Returns true on success.
|
||||
*/
|
||||
virtual bool receive(const MotionCommand&);
|
||||
virtual bool receive(const TranslateInLineCommand& command) { return receive((MotionCommand&)command); }
|
||||
virtual bool receive(const TranslateInPlaneCommand& command) { return receive((MotionCommand&)command); }
|
||||
virtual bool receive(const Scale1DCommand& command) { return receive((MotionCommand&)command); }
|
||||
virtual bool receive(const Scale2DCommand& command) { return receive((MotionCommand&)command); }
|
||||
virtual bool receive(const ScaleUniformCommand& command) { return receive((MotionCommand&)command); }
|
||||
virtual bool receive(const Rotate3DCommand& command) { return receive((MotionCommand&)command); }
|
||||
|
||||
protected:
|
||||
|
||||
virtual ~Selection();
|
||||
|
||||
osg::Matrix _startMotionMatrix;
|
||||
|
||||
osg::Matrix _localToWorld;
|
||||
osg::Matrix _worldToLocal;
|
||||
};
|
||||
typedef osg::MatrixTransform Selection;
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user