From Vivek Rajan, new osgManipulator library, with a few minor tweaks and rename for osgDragger to osgManipulator for build by Robert Osfield.

Vivek's email to osg-submissions:

"I'm happy to release the osgdragger nodekit to the OSG community. I
implemented the nodekit for my company, Fugro-Jason Inc., and they
have kindly agreed to open source it.

The nodekit contains a few draggers but it should be easy to build new
draggers on top of it. The design of the nodekit is based on a
SIGGRAPH 2002 course - "Design and Implementation of Direct
Manipulation in 3D". You can find the course notes at
http://www.pauliface.com/Sigg02/index.html. Reading pages 20 - 29 of
the course notes should give you a fair understanding of how the
nodekit works.

The source code also contains an example of how to use the draggers."
This commit is contained in:
Robert Osfield
2007-02-11 10:33:59 +00:00
parent f1a82f35b2
commit 19db0c1674
49 changed files with 6774 additions and 1 deletions

View File

@@ -0,0 +1,84 @@
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
*
* This library is open source and may be redistributed and/or modified under
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
* (at your option) any later version. The full license is in LICENSE file
* included with this distribution, and on the openscenegraph.org website.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* OpenSceneGraph Public License for more details.
*/
//osgDragger - Copyright (C) 2007 Fugro-Jason B.V.
#ifndef _OSG_ANTISQUISH_
#define _OSG_ANTISQUISH_ 1
#include <osgManipulator/Export>
#include <osg/Matrix>
#include <osg/CopyOp>
#include <osg/NodeVisitor>
#include <osg/NodeCallback>
#include <osg/MatrixTransform>
#include <osg/Quat>
#include <osg/Vec3>
namespace osgManipulator {
/**
* Class that performs the Anti Squish by making the scaling uniform along all axes.
*/
class OSGMANIPULATOR_EXPORT AntiSquish: public osg::MatrixTransform
{
public :
AntiSquish();
AntiSquish(const osg::Vec3& pivot);
AntiSquish(const osg::Vec3& pivot, const osg::Vec3& position);
AntiSquish(const AntiSquish& pat, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
virtual osg::Object* cloneType() const { return new AntiSquish(); }
virtual osg::Object* clone(const osg::CopyOp& copyop) const { return new AntiSquish (*this,copyop); }
virtual bool isSameKindAs(const osg::Object* obj) const { return dynamic_cast<const AntiSquish *>(obj)!=NULL; }
void setPivot(const osg::Vec3& pvt)
{
_pivot = pvt;
_usePivot = true;
_dirty = true;
}
const osg::Vec3& getPivot() { return _pivot; }
void setPosition(const osg::Vec3& pos)
{
_position = pos;
_usePosition = true;
_dirty = true;
}
const osg::Vec3& getPosition() { return _position; }
virtual ~AntiSquish();
osg::Matrix computeUnSquishedMatrix(const osg::Matrix&, bool& flag);
protected:
osg::NodeCallback* _asqCallback;
osg::Vec3 _pivot;
bool _usePivot;
osg::Vec3 _position;
bool _usePosition;
bool _dirty;
osg::Matrix _cachedLocalToWorld;
};
}
#endif

View File

@@ -0,0 +1,352 @@
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
*
* This library is open source and may be redistributed and/or modified under
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
* (at your option) any later version. The full license is in LICENSE file
* included with this distribution, and on the openscenegraph.org website.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* OpenSceneGraph Public License for more details.
*/
//osgManipulator - Copyright (C) 2007 Fugro-Jason B.V.
#ifndef OSGMANIPULATOR_COMMAND
#define OSGMANIPULATOR_COMMAND 1
#include <osgManipulator/Export>
#include <osgManipulator/Selection>
#include <osg/LineSegment>
#include <osg/Plane>
#include <osg/Vec2>
#include <vector>
namespace osgManipulator {
class Constraint;
/** Base class for motion commands that are generated by draggers. */
class OSGMANIPULATOR_EXPORT MotionCommand : public osg::Referenced
{
public:
/**
* Motion command are based on click-drag-release actions. So each
* command needs to indicate which stage of the motion the command
* represents.
*/
enum Stage
{
NONE,
/** Click or pick start. */
START,
/** Drag or pick move. */
MOVE,
/** Release or pick finish. */
FINISH
};
MotionCommand();
/** Execute the command. */
virtual bool execute() = 0;
/** Undo the command. The inverse of this command is executed. */
virtual bool unexecute() = 0;
/** Apply a constraint to the command. */
virtual void applyConstraint(const Constraint*) = 0;
/**
* Add Selection (receiver) to the command. The command will be
* executed on all the selections.
*/
void addSelection(Selection*);
/** Remove Selection (receiver) from the command. */
void removeSelection(Selection*);
/**
* Gets the matrix for transforming the Selection. This matrix is in the
* command's coordinate systems.
*/
virtual osg::Matrix getMotionMatrix() const = 0;
/**
* Sets the matrix for transforming the command's local coordinate
* system to the world/object coordinate system.
*/
void setLocalToWorldAndWorldToLocal(const osg::Matrix& localToWorld, const osg::Matrix& worldToLocal)
{
_localToWorld = localToWorld;
_worldToLocal = worldToLocal;
}
/**
* Gets the matrix for transforming the command's local coordinate
* system to the world/object coordinate system.
*/
inline const osg::Matrix& getLocalToWorld() const { return _localToWorld; }
/**
* Gets the matrix for transforming the command's world/object
* coordinate system to the command's local coordinate system.
*/
inline const osg::Matrix& getWorldToLocal() const { return _worldToLocal; }
void setStage(const Stage s) { _stage = s; }
Stage getStage() const { return _stage; }
protected:
virtual ~MotionCommand();
typedef std::vector< osg::ref_ptr<Selection> > SelectionList;
SelectionList& getSelectionList() { return _selectionList; }
const SelectionList& getSelectionList() const { return _selectionList; }
private:
osg::Matrix _localToWorld;
osg::Matrix _worldToLocal;
Stage _stage;
SelectionList _selectionList;
};
/**
* Command for translating in a line.
*/
class OSGMANIPULATOR_EXPORT TranslateInLineCommand : public MotionCommand
{
public:
TranslateInLineCommand();
TranslateInLineCommand(const osg::Vec3& s, const osg::Vec3& e);
virtual bool execute();
virtual bool unexecute();
virtual void applyConstraint(const Constraint*);
inline void setLine(const osg::Vec3& s, const osg::Vec3& e) { _line->start() = s; _line->end() = e; }
inline const osg::Vec3& getLineStart() const { return _line->start(); }
inline const osg::Vec3& getLineEnd() const { return _line->end(); }
inline void setTranslation(const osg::Vec3& t) { _translation = t; }
inline const osg::Vec3& getTranslation() const { return _translation; }
virtual osg::Matrix getMotionMatrix() const
{
return osg::Matrix::translate(_translation);
}
protected:
virtual ~TranslateInLineCommand();
private:
osg::ref_ptr<osg::LineSegment> _line;
osg::Vec3 _translation;
};
/**
* Command for translating in a plane.
*/
class OSGMANIPULATOR_EXPORT TranslateInPlaneCommand : public MotionCommand
{
public:
TranslateInPlaneCommand();
TranslateInPlaneCommand(const osg::Plane& plane);
virtual bool execute();
virtual bool unexecute();
virtual void applyConstraint(const Constraint*);
inline void setPlane(const osg::Plane& plane) { _plane = plane; }
inline const osg::Plane& getPlane() const { return _plane; }
inline void setTranslation(const osg::Vec3& t) { _translation = t; }
inline const osg::Vec3& getTranslation() const { return _translation; }
/** ReferencePoint is used only for snapping. */
inline void setReferencePoint(const osg::Vec3& rp) { _referencePoint = rp; }
inline const osg::Vec3& getReferencePoint() const { return _referencePoint; }
virtual osg::Matrix getMotionMatrix() const
{
return osg::Matrix::translate(_translation);
}
protected:
virtual ~TranslateInPlaneCommand();
private:
osg::Plane _plane;
osg::Vec3 _translation;
osg::Vec3 _referencePoint;
};
/**
* Command for 1D scaling.
*/
class OSGMANIPULATOR_EXPORT Scale1DCommand : public MotionCommand
{
public:
Scale1DCommand();
virtual bool execute();
virtual bool unexecute();
virtual void applyConstraint(const Constraint*);
inline void setScale(float s) { _scale = s; }
inline float getScale() const { return _scale; }
inline void setScaleCenter(float center) { _scaleCenter = center; }
inline float getScaleCenter() const { return _scaleCenter; }
/** ReferencePoint is used only for snapping. */
inline void setReferencePoint(float rp) { _referencePoint = rp; }
inline float getReferencePoint() const { return _referencePoint; }
inline void setMinScale(float min) { _minScale = min; }
inline float getMinScale() const { return _minScale; }
virtual osg::Matrix getMotionMatrix() const
{
return (osg::Matrix::translate(-_scaleCenter,0.0,0.0)
* osg::Matrix::scale(_scale,1.0,1.0)
* osg::Matrix::translate(_scaleCenter,0.0,0.0));
}
protected:
virtual ~Scale1DCommand();
private:
float _scale;
float _scaleCenter;
float _referencePoint;
float _minScale;
};
/**
* Command for 2D scaling.
*/
class OSGMANIPULATOR_EXPORT Scale2DCommand : public MotionCommand
{
public:
Scale2DCommand();
virtual bool execute();
virtual bool unexecute();
virtual void applyConstraint(const Constraint*);
inline void setScale(const osg::Vec2& s) { _scale = s; }
inline const osg::Vec2& getScale() const { return _scale; }
inline void setScaleCenter(const osg::Vec2& center) { _scaleCenter = center; }
inline const osg::Vec2& getScaleCenter() const { return _scaleCenter; }
/** ReferencePoint is used only for snapping. */
inline void setReferencePoint(const osg::Vec2& rp) { _referencePoint = rp; }
inline const osg::Vec2& getReferencePoint() const { return _referencePoint; }
inline void setMinScale(const osg::Vec2& min) { _minScale = min; }
inline const osg::Vec2& getMinScale() const { return _minScale; }
virtual osg::Matrix getMotionMatrix() const
{
return (osg::Matrix::translate(-_scaleCenter[0],0.0,-_scaleCenter[1])
* osg::Matrix::scale(_scale[0],1.0,_scale[1])
* osg::Matrix::translate(_scaleCenter[0],0.0,_scaleCenter[1]));
}
protected:
virtual ~Scale2DCommand();
private:
osg::Vec2 _scale;
osg::Vec2 _scaleCenter;
osg::Vec2 _referencePoint;
osg::Vec2 _minScale;
};
/**
* Command for uniform 3D scaling.
*/
class OSGMANIPULATOR_EXPORT ScaleUniformCommand : public MotionCommand
{
public:
ScaleUniformCommand();
virtual bool execute();
virtual bool unexecute();
virtual void applyConstraint(const Constraint*);
inline void setScale(float s) { _scale = s; }
inline float getScale() const { return _scale; }
inline void setScaleCenter(const osg::Vec3& center) { _scaleCenter = center; }
inline const osg::Vec3& getScaleCenter() const { return _scaleCenter; }
virtual osg::Matrix getMotionMatrix() const
{
return (osg::Matrix::translate(-_scaleCenter)
* osg::Matrix::scale(_scale,_scale,_scale)
* osg::Matrix::translate(_scaleCenter));
}
protected:
virtual ~ScaleUniformCommand();
private:
float _scale;
osg::Vec3 _scaleCenter;
};
/**
* Command for rotation in 3D.
*/
class OSGMANIPULATOR_EXPORT Rotate3DCommand : public MotionCommand
{
public:
Rotate3DCommand();
virtual bool execute();
virtual bool unexecute();
virtual void applyConstraint(const Constraint*);
inline void setRotation(const osg::Quat& rotation) { _rotation = rotation; }
inline const osg::Quat& getRotation() const { return _rotation; }
virtual osg::Matrix getMotionMatrix() const
{
return osg::Matrix::rotate(_rotation);
}
protected:
virtual ~Rotate3DCommand();
private:
osg::Quat _rotation;
};
}
#endif

View File

@@ -0,0 +1,64 @@
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
*
* This library is open source and may be redistributed and/or modified under
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
* (at your option) any later version. The full license is in LICENSE file
* included with this distribution, and on the openscenegraph.org website.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* OpenSceneGraph Public License for more details.
*/
//osgManipulator - Copyright (C) 2007 Fugro-Jason B.V.
#ifndef OSGMANIPULATOR_COMMANDMANAGER
#define OSGMANIPULATOR_COMMANDMANAGER 1
#include <osgManipulator/Dragger>
#include <osgManipulator/Selection>
#include <osgManipulator/Constraint>
namespace osgManipulator {
/**
* Command manager receives commands from draggers and dispatches them to selections.
*/
class OSGMANIPULATOR_EXPORT 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);
virtual bool connect(Dragger& dragger, Constraint& constrain);
/** Disconnect the selections from a dragger. */
virtual bool disconnect(Dragger& dragger);
/** Dispatches a command. Usually called from a dragger. */
virtual void dispatch(MotionCommand& command);
/** Add all selections connected to the dragger to the command. */
void addSelectionsToCommand(MotionCommand& command, Dragger& dragger);
protected:
virtual ~CommandManager();
typedef std::multimap< osg::ref_ptr<Dragger>, osg::ref_ptr<Selection> > DraggerSelectionMap;
DraggerSelectionMap _draggerSelectionMap;
typedef std::multimap< osg::ref_ptr<Dragger>, osg::ref_ptr<Constraint> > DraggerConstraintMap;
DraggerConstraintMap _draggerConstraintMap;
};
}
#endif

View File

@@ -0,0 +1,95 @@
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
*
* This library is open source and may be redistributed and/or modified under
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
* (at your option) any later version. The full license is in LICENSE file
* included with this distribution, and on the openscenegraph.org website.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* OpenSceneGraph Public License for more details.
*/
//osgManipulator - Copyright (C) 2007 Fugro-Jason B.V.
#ifndef OSGMANIPULATOR_CONSTRAINT
#define OSGMANIPULATOR_CONSTRAINT 1
#include <osgManipulator/Export>
#include <osg/Node>
#include <osg/Matrix>
namespace osgManipulator {
class MotionCommand;
class TranslateInLineCommand;
class TranslateInPlaneCommand;
class Scale1DCommand;
class Scale2DCommand;
class ScaleUniformCommand;
class OSGMANIPULATOR_EXPORT Constraint : public osg::Referenced
{
public:
virtual bool constrain(MotionCommand&) const { return false; }
virtual bool constrain(TranslateInLineCommand& command) const { return constrain((MotionCommand&)command); }
virtual bool constrain(TranslateInPlaneCommand& command) const { return constrain((MotionCommand&)command); }
virtual bool constrain(Scale1DCommand& command) const { return constrain((MotionCommand&)command); }
virtual bool constrain(Scale2DCommand& command) const { return constrain((MotionCommand&)command); }
virtual bool constrain(ScaleUniformCommand& command) const { return constrain((MotionCommand&)command); }
protected:
Constraint(osg::Node& refNode) : _refNode(&refNode) {}
virtual ~Constraint() {}
osg::Node& getReferenceNode() { return *_refNode; }
const osg::Node& getReferenceNode() const { return *_refNode; }
const osg::Matrix& getLocalToWorld() const { return _localToWorld; }
const osg::Matrix& getWorldToLocal() const { return _worldToLocal; }
void computeLocalToWorldAndWorldToLocal() const;
private:
osg::ref_ptr<osg::Node> _refNode;
mutable osg::Matrix _localToWorld;
mutable osg::Matrix _worldToLocal;
};
/**
* Constraint to snap motion commands to a sugar cube grid.
*/
class OSGMANIPULATOR_EXPORT GridConstraint : public Constraint
{
public:
GridConstraint(osg::Node& refNode, const osg::Vec3d& origin, const osg::Vec3d& spacing);
void setOrigin(const osg::Vec3d origin) { _origin = origin; }
void setSpacing(const osg::Vec3d spacing) { _spacing = spacing; }
virtual bool constrain(TranslateInLineCommand& command) const;
virtual bool constrain(TranslateInPlaneCommand& command) const;
virtual bool constrain(Scale1DCommand& command) const;
virtual bool constrain(Scale2DCommand& command) const;
virtual bool constrain(ScaleUniformCommand& command) const;
protected:
virtual ~GridConstraint() {}
private:
osg::Vec3d _origin;
osg::Vec3d _spacing;
mutable osg::Matrix _startMatrix;
mutable osg::Matrix _matrix;
};
}
#endif

View File

@@ -0,0 +1,134 @@
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
*
* This library is open source and may be redistributed and/or modified under
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
* (at your option) any later version. The full license is in LICENSE file
* included with this distribution, and on the openscenegraph.org website.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* OpenSceneGraph Public License for more details.
*/
//osgManipulator - Copyright (C) 2007 Fugro-Jason B.V.
#ifndef OSGMANIPULATOR_DRAGGER
#define OSGMANIPULATOR_DRAGGER 1
#include <osgManipulator/Selection>
#include <osg/BoundingSphere>
#include <osgUtil/SceneView>
#include <osgUtil/IntersectVisitor>
#include <osgGA/GUIEventAdapter>
#include <osgGA/GUIActionAdapter>
namespace osgManipulator
{
class CommandManager;
class CompositeDragger;
/**
* Base class for draggers. Concrete draggers implement the pick event handler
* and generate motion commands (translate, rotate, ...) and sends these
* command to the CommandManager. The CommandManager dispatches the commands
* to all the Selections that are connected to the Dragger that generates the
* commands.
*/
class OSGMANIPULATOR_EXPORT Dragger : public Selection
{
public:
/** Set/Get the CommandManager. Draggers use CommandManager to dispatch commands. */
virtual void setCommandManager(CommandManager* cm) { _commandManager = cm; }
CommandManager* getCommandManager() { return _commandManager; }
const CommandManager* getCommandManager() const { return _commandManager; }
/**
* Set/Get parent dragger. For simple draggers parent points to itself.
* For composite draggers parent points to the parent dragger that uses
* this dragger.
*/
virtual void setParentDragger(Dragger* parent) { _parentDragger = parent; }
Dragger* getParentDragger() { return _parentDragger; }
const Dragger* getParentDragger() const { return _parentDragger; }
/** Returns 0 if this Dragger is not a CompositeDragger. */
virtual const CompositeDragger* getComposite() const { return 0; }
/** Returns 0 if this Dragger is not a CompositeDragger. */
virtual CompositeDragger* getComposite() { return 0; }
virtual bool handle(int, int, const osgUtil::SceneView&,
const osgUtil::IntersectVisitor::HitList&,
const osgUtil::IntersectVisitor::HitList::iterator&,
const osgGA::GUIEventAdapter&, osgGA::GUIActionAdapter&) { return false; }
protected:
Dragger();
virtual ~Dragger();
CommandManager* _commandManager;
Dragger* _parentDragger;
};
/**
* CompositeDragger allows to create complex draggers that are composed of a
* hierarchy of Draggers.
*/
class OSGMANIPULATOR_EXPORT CompositeDragger : public Dragger
{
public:
typedef std::vector< osg::ref_ptr<Dragger> > DraggerList;
virtual const CompositeDragger* getComposite() const { return this; }
virtual CompositeDragger* getComposite() { return this; }
virtual void setCommandManager(CommandManager* cm);
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);
// Composite-specific methods below
virtual bool addDragger(Dragger* dragger);
virtual bool removeDragger(Dragger* dragger);
unsigned int getNumDraggers() const { return _draggerList.size(); }
Dragger* getDragger(unsigned int i) { return _draggerList[i].get(); }
const Dragger* getDragger(unsigned int i) const { return _draggerList[i].get(); }
bool containsDragger(const Dragger* dragger) const;
DraggerList::iterator findDragger(const Dragger* dragger);
protected:
CompositeDragger() {}
virtual ~CompositeDragger() {}
DraggerList _draggerList;
};
/**
* Culls the drawable all the time. Used by draggers to have invisible geometry
* around lines and points so that they can be picked. For example, a dragger
* could have a line with an invisible cylinder around it to enable picking on
* that line.
*/
void setDrawableToAlwaysCull(osg::Drawable& drawable);
/**
* Convenience function for setting the material color on a node.
*/
void setMaterialColor(const osg::Vec4& color, osg::Node& node);
}
#endif

View File

@@ -0,0 +1,28 @@
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
*
* This library is open source and may be redistributed and/or modified under
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
* (at your option) any later version. The full license is in LICENSE file
* included with this distribution, and on the openscenegraph.org website.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* OpenSceneGraph Public License for more details.
*/
//osgManipulator - Copyright (C) 2007 Fugro-Jason B.V.
#ifndef OSGMANIPULATOR_EXPORT_
#define OSGMANIPULATOR_EXPORT_ 1
#if defined(_MSC_VER) || defined(__CYGWIN__) || defined(__MINGW32__) || defined( __BCPLUSPLUS__) || defined( __MWERKS__)
# ifdef OSGMANIPULATOR_LIBRARY
# define OSGMANIPULATOR_EXPORT __declspec(dllexport)
# else
# define OSGMANIPULATOR_EXPORT __declspec(dllimport)
# endif /* OSGMANIPULATOR_LIBRARY */
#else
# define OSGMANIPULATOR_EXPORT
#endif
#endif

View File

@@ -0,0 +1,298 @@
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
*
* This library is open source and may be redistributed and/or modified under
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
* (at your option) any later version. The full license is in LICENSE file
* included with this distribution, and on the openscenegraph.org website.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* OpenSceneGraph Public License for more details.
*/
//osgManipulator - Copyright (C) 2007 Fugro-Jason B.V.
#ifndef OSGMANIPULATOR_PROJECTOR
#define OSGMANIPULATOR_PROJECTOR 1
#include <osgManipulator/Export>
#include <osg/LineSegment>
#include <osgUtil/SceneView>
namespace osgManipulator {
/**
* Base class for Projectors. Projectors maps 2D cursor motions to 3D motions.
*/
class OSGMANIPULATOR_EXPORT Projector : public osg::Referenced
{
public:
Projector();
/**
* Calculates the object/world coordinates (projectedPoint) of a window
* coordinate (pointToProject) when projected onto some shape or
* geometry (implemented in derived classes). SceneView in used for i
* 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;
/**
* Sets the matrix for transforming the projector's local coordinate
* system to the world/object coordinate system.
*/
void setLocalToWorld(const osg::Matrix& localToWorld)
{
_localToWorld = localToWorld;
_worldToLocalDirty = true;
}
/**
* Gets the matrix for transforming the projector's local coordinate
* system to the world/object coordinate system.
*/
inline const osg::Matrix& getLocalToWorld() const { return _localToWorld; }
/**
* Gets the matrix for transforming the world/object coordinate
* system to the command's local coordinate system.
*/
inline const osg::Matrix& getWorldToLocal() const
{
if (_worldToLocalDirty)
{
_worldToLocal.invert(_localToWorld);
_worldToLocalDirty = false;
}
return _worldToLocal;
}
protected:
virtual ~Projector();
osg::Matrix _localToWorld;
mutable osg::Matrix _worldToLocal;
mutable bool _worldToLocalDirty;
};
/**
* LineProjector projects points onto the closest point on the given line.
*/
class OSGMANIPULATOR_EXPORT LineProjector : public Projector
{
public:
LineProjector();
LineProjector(const osg::Vec3& s, const osg::Vec3& e);
inline void setLine(const osg::Vec3& s, const osg::Vec3& e) { _line->start() = s; _line->end() = e; }
inline const osg::Vec3& getLineStart() const { return _line->start(); }
inline osg::Vec3& getLineStart() { return _line->start(); }
inline const osg::Vec3& getLineEnd() const { return _line->end(); }
inline osg::Vec3& getLineEnd() { return _line->end(); }
/**
* Calculates the object coordinates (projectedPoint) of a window
* 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;
protected:
virtual ~LineProjector();
osg::ref_ptr<osg::LineSegment> _line;
};
/**
* PlaneProjector projects points onto the given line.
*/
class OSGMANIPULATOR_EXPORT PlaneProjector : public Projector
{
public:
PlaneProjector();
PlaneProjector(const osg::Plane& plane);
inline void setPlane(const osg::Plane& plane) { _plane = plane; }
inline const osg::Plane& getPlane() const { return _plane; }
/**
* Calculates the object coordinates (projectedPoint) of a window
* 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;
protected:
virtual ~PlaneProjector();
osg::Plane _plane;
};
/**
* SphereProjector projects points onto the given sphere.
*/
class OSGMANIPULATOR_EXPORT SphereProjector : public Projector
{
public:
SphereProjector();
SphereProjector(osg::Sphere& sphere);
inline void setSphere(osg::Sphere& sphere) { _sphere = &sphere; }
inline const osg::Sphere& getSphere() const { return *_sphere; }
/**
* Calculates the object coordinates (projectedPoint) of a window
* 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;
/**
* 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;
void setFront(bool front) { _front = front; }
protected:
virtual ~SphereProjector();
osg::ref_ptr<osg::Sphere> _sphere;
bool _front;
};
/**
* SpherePlaneProjector projects points onto a sphere, failing which it project
* onto a plane oriented to the viewing direction.
*/
class OSGMANIPULATOR_EXPORT SpherePlaneProjector : public SphereProjector
{
public:
SpherePlaneProjector();
SpherePlaneProjector(osg::Sphere& sphere);
/**
* Calculates the object coordinates (projectedPoint) of a window
* 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;
/**
* Returns true if the previous projection was on the sphere and false
* if the projection was on the plane.
*/
bool isProjectionOnSphere() const { return _onSphere; }
osg::Quat getRotation(const osg::Vec3& p1, bool p1OnSphere,
const osg::Vec3& p2, bool p2OnSphere,
float radialFactor = 0.0f) const;
protected:
virtual ~SpherePlaneProjector();
mutable osg::Plane _plane;
mutable bool _onSphere;
};
/**
* CylinderProjector projects points onto the given cylinder.
*/
class OSGMANIPULATOR_EXPORT CylinderProjector : public Projector
{
public:
CylinderProjector();
CylinderProjector(osg::Cylinder& cylinder);
inline void setCylinder(osg::Cylinder& cylinder)
{
_cylinder = &cylinder;
_cylinderAxis = osg::Vec3(0.0,0.0,1.0) * osg::Matrix(cylinder.getRotation());
_cylinderAxis.normalize();
}
inline const osg::Cylinder& getCylinder() const { return *_cylinder; }
/**
* Calculates the object coordinates (projectedPoint) of a window
* 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;
/**
* 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;
void setFront(bool front) { _front = front; }
protected:
virtual ~CylinderProjector();
osg::ref_ptr<osg::Cylinder> _cylinder;
osg::Vec3 _cylinderAxis;
bool _front;
};
/**
* CylinderPlaneProjector projects points onto the given cylinder.
*/
class OSGMANIPULATOR_EXPORT CylinderPlaneProjector : public CylinderProjector
{
public:
CylinderPlaneProjector();
CylinderPlaneProjector(osg::Cylinder& cylinder);
/**
* Calculates the object coordinates (projectedPoint) of a window
* 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;
/**
* Returns true if the previous projection was on the cylinder and
* false if the projection was on the plane.
*/
bool isProjectionOnCylinder() const { return _onCylinder; }
osg::Quat getRotation(const osg::Vec3& p1, bool p1OnCyl, const osg::Vec3& p2, bool p2OnCyl) const;
protected:
virtual ~CylinderPlaneProjector();
mutable osg::Plane _plane;
mutable bool _onCylinder;
mutable osg::Vec3 _planeLineStart, _planeLineEnd;
};
}
#endif

View File

@@ -0,0 +1,74 @@
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
*
* This library is open source and may be redistributed and/or modified under
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
* (at your option) any later version. The full license is in LICENSE file
* included with this distribution, and on the openscenegraph.org website.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* OpenSceneGraph Public License for more details.
*/
//osgManipulator - Copyright (C) 2007 Fugro-Jason B.V.
#ifndef OSGMANIPULATOR_ROTATECYLINDERDRAGGER
#define OSGMANIPULATOR_ROTATECYLINDERDRAGGER 1
#include <osgManipulator/Dragger>
#include <osgManipulator/Projector>
namespace osgManipulator {
/**
* Dragger for performing 3D rotation on a cylinder.
*/
class OSGMANIPULATOR_EXPORT RotateCylinderDragger : public Dragger
{
public:
RotateCylinderDragger();
/**
* 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);
/** Setup default geometry for dragger. */
void setupDefaultGeometry();
/** Set/Get color for dragger. */
inline void setColor(const osg::Vec4& color) { _color = color; setMaterialColor(_color,*this); }
inline const osg::Vec4 getColor() const { return _color; }
/**
* Set/Get pick color for dragger. Pick color is color of the dragger
* when picked. It gives a visual feedback to show that the dragger has
* been picked.
*/
inline void setPickColor(const osg::Vec4& color) { _pickColor = color; }
inline const osg::Vec4 getPickColor() const { return _pickColor; }
protected:
virtual ~RotateCylinderDragger();
osg::ref_ptr<CylinderPlaneProjector> _projector;
osg::Vec3 _prevWorldProjPt;
bool _prevPtOnCylinder;
osg::Matrix _startLocalToWorld, _startWorldToLocal;
osg::Quat _prevRotation;
osg::Vec4 _color;
osg::Vec4 _pickColor;
};
}
#endif

View File

@@ -0,0 +1,73 @@
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
*
* This library is open source and may be redistributed and/or modified under
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
* (at your option) any later version. The full license is in LICENSE file
* included with this distribution, and on the openscenegraph.org website.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* OpenSceneGraph Public License for more details.
*/
//osgManipulator - Copyright (C) 2007 Fugro-Jason B.V.
#ifndef OSGMANIPULATOR_ROTATESPHEREDRAGGER
#define OSGMANIPULATOR_ROTATESPHEREDRAGGER 1
#include <osgManipulator/Dragger>
#include <osgManipulator/Projector>
namespace osgManipulator {
/**
* Dragger for performing 3D rotation on a sphere.
*/
class OSGMANIPULATOR_EXPORT RotateSphereDragger : public Dragger
{
public:
RotateSphereDragger();
/**
* 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);
/** Setup default geometry for dragger. */
void setupDefaultGeometry();
/** Set/Get color for dragger. */
inline void setColor(const osg::Vec4& color) { _color = color; setMaterialColor(_color,*this); }
inline const osg::Vec4 getColor() const { return _color; }
/**
* Set/Get pick color for dragger. Pick color is color of the dragger
* when picked. It gives a visual feedback to show that the dragger has
* been picked.
*/
inline void setPickColor(const osg::Vec4& color) { _pickColor = color; }
inline const osg::Vec4 getPickColor() const { return _pickColor; }
protected:
virtual ~RotateSphereDragger();
osg::ref_ptr<SpherePlaneProjector> _projector;
osg::Vec3 _prevWorldProjPt;
bool _prevPtOnSphere;
osg::Matrix _startLocalToWorld, _startWorldToLocal;
osg::Quat _prevRotation;
osg::Vec4 _color;
osg::Vec4 _pickColor;
};
}
#endif

View File

@@ -0,0 +1,98 @@
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
*
* This library is open source and may be redistributed and/or modified under
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
* (at your option) any later version. The full license is in LICENSE file
* included with this distribution, and on the openscenegraph.org website.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* OpenSceneGraph Public License for more details.
*/
//osgManipulator - Copyright (C) 2007 Fugro-Jason B.V.
#ifndef OSGMANIPULATOR_SCALE1DDRAGGER
#define OSGMANIPULATOR_SCALE1DDRAGGER 1
#include <osgManipulator/Dragger>
#include <osgManipulator/Projector>
namespace osgManipulator {
/**
* Dragger for performing 1D scaling.
*/
class OSGMANIPULATOR_EXPORT Scale1DDragger : public Dragger
{
public:
enum ScaleMode
{
SCALE_WITH_ORIGIN_AS_PIVOT = 0,
SCALE_WITH_OPPOSITE_HANDLE_AS_PIVOT
};
Scale1DDragger(ScaleMode scaleMode=SCALE_WITH_ORIGIN_AS_PIVOT);
/**
* 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);
/** Setup default geometry for dragger. */
void setupDefaultGeometry();
/** Set/Get min scale for dragger. */
inline void setMinScale(float min) { _minScale = min; }
inline float getMinScale() const { return _minScale; }
/** Set/Get color for dragger. */
inline void setColor(const osg::Vec4& color) { _color = color; setMaterialColor(_color,*this); }
inline const osg::Vec4 getColor() const { return _color; }
/**
* Set/Get pick color for dragger. Pick color is color of the dragger
* when picked. It gives a visual feedback to show that the dragger has
* been picked.
*/
inline void setPickColor(const osg::Vec4& color) { _pickColor = color; }
inline const osg::Vec4 getPickColor() const { return _pickColor; }
/** Set/Get left and right handle nodes for dragger. */
inline void setLeftHandleNode (osg::Node& node) { _leftHandleNode = &node; }
inline void setRightHandleNode(osg::Node& node) { _rightHandleNode = &node; }
inline osg::Node* getLeftHandleNode() { return _leftHandleNode.get(); }
inline osg::Node* getRightHandleNode() { return _rightHandleNode.get(); }
/** Set left/right handle position. */
inline void setLeftHandlePosition(float pos) { _projector->getLineStart() = osg::Vec3(pos,0.0,0.0); }
inline float getLeftHandlePosition() const { return _projector->getLineStart()[0]; }
inline void setRightHandlePosition(float pos) { _projector->getLineEnd() = osg::Vec3(pos,0.0,0.0); }
inline float getRightHandlePosition() { return _projector->getLineEnd()[0]; }
protected:
virtual ~Scale1DDragger();
osg::ref_ptr< LineProjector > _projector;
osg::Vec3 _startProjectedPoint;
float _scaleCenter;
float _minScale;
osg::ref_ptr< osg::Node > _leftHandleNode;
osg::ref_ptr< osg::Node > _rightHandleNode;
osg::Vec4 _color;
osg::Vec4 _pickColor;
ScaleMode _scaleMode;
};
}
#endif

View File

@@ -0,0 +1,114 @@
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
*
* This library is open source and may be redistributed and/or modified under
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
* (at your option) any later version. The full license is in LICENSE file
* included with this distribution, and on the openscenegraph.org website.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* OpenSceneGraph Public License for more details.
*/
//osgManipulator - Copyright (C) 2007 Fugro-Jason B.V.
#ifndef OSGMANIPULATOR_SCALE2DDRAGGER
#define OSGMANIPULATOR_SCALE2DDRAGGER 1
#include <osgManipulator/Dragger>
#include <osgManipulator/Projector>
namespace osgManipulator {
/**
* Dragger for performing 2D scaling.
*/
class OSGMANIPULATOR_EXPORT Scale2DDragger : public Dragger
{
public:
enum ScaleMode
{
SCALE_WITH_ORIGIN_AS_PIVOT = 0,
SCALE_WITH_OPPOSITE_HANDLE_AS_PIVOT
};
Scale2DDragger(ScaleMode scaleMode=SCALE_WITH_ORIGIN_AS_PIVOT);
/**
* 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);
/** Setup default geometry for dragger. */
void setupDefaultGeometry();
/** Set/Get min scale for dragger. */
inline void setMinScale(const osg::Vec2& min) { _minScale = min; }
inline const osg::Vec2& getMinScale() const { return _minScale; }
/** Set/Get color for dragger. */
inline void setColor(const osg::Vec4& color) { _color = color; setMaterialColor(_color,*this); }
inline const osg::Vec4 getColor() const { return _color; }
/**
* Set/Get pick color for dragger. Pick color is color of the dragger
* when picked. It gives a visual feedback to show that the dragger has
* been picked.
*/
inline void setPickColor(const osg::Vec4& color) { _pickColor = color; }
inline const osg::Vec4 getPickColor() const { return _pickColor; }
/** Set/Get the handle nodes for dragger. */
inline void setTopLeftHandleNode (osg::Node& node) { _topLeftHandleNode = &node; }
inline osg::Node* getTopLeftHandleNode() { return _topLeftHandleNode.get(); }
inline void setBottomLeftHandleNode (osg::Node& node) { _bottomLeftHandleNode = &node; }
inline osg::Node* getBottomLeftHandleNode() { return _bottomLeftHandleNode.get(); }
inline void setTopRightHandleNode(osg::Node& node) { _topRightHandleNode = &node; }
inline osg::Node* getTopRightHandleNode() { return _topRightHandleNode.get(); }
inline void setBottomRightHandleNode(osg::Node& node) { _bottomRightHandleNode = &node; }
inline osg::Node* getBottomRightHandleNode() { return _bottomRightHandleNode.get(); }
/** Set/Get the handle nodes postion for dragger. */
inline void setTopLeftHandlePosition(const osg::Vec2& pos) { _topLeftHandlePosition = pos; }
const osg::Vec2& getTopLeftHandlePosition() { return _topLeftHandlePosition; }
inline void setBottomLeftHandlePosition(const osg::Vec2& pos) { _bottomLeftHandlePosition = pos; }
const osg::Vec2& getBottomLeftHandlePosition() { return _bottomLeftHandlePosition; }
inline void setTopRightHandlePosition(const osg::Vec2& pos) { _topRightHandlePosition = pos; }
const osg::Vec2& getTopRightHandlePosition() { return _topRightHandlePosition; }
inline void setBottomRightHandlePosition(const osg::Vec2& pos){ _bottomRightHandlePosition = pos; }
const osg::Vec2& getBottomRightHandlePosition() { return _bottomRightHandlePosition; }
protected:
virtual ~Scale2DDragger();
osg::ref_ptr< PlaneProjector > _projector;
osg::Vec3 _startProjectedPoint;
osg::Vec2 _scaleCenter;
osg::Vec2 _referencePoint;
osg::Vec2 _minScale;
osg::ref_ptr< osg::Node > _topLeftHandleNode;
osg::ref_ptr< osg::Node > _bottomLeftHandleNode;
osg::ref_ptr< osg::Node > _topRightHandleNode;
osg::ref_ptr< osg::Node > _bottomRightHandleNode;
osg::Vec2 _topLeftHandlePosition;
osg::Vec2 _bottomLeftHandlePosition;
osg::Vec2 _topRightHandlePosition;
osg::Vec2 _bottomRightHandlePosition;
osg::Vec4 _color;
osg::Vec4 _pickColor;
ScaleMode _scaleMode;
};
}
#endif

View File

@@ -0,0 +1,46 @@
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
*
* This library is open source and may be redistributed and/or modified under
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
* (at your option) any later version. The full license is in LICENSE file
* included with this distribution, and on the openscenegraph.org website.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* OpenSceneGraph Public License for more details.
*/
//osgManipulator - Copyright (C) 2007 Fugro-Jason B.V.
#ifndef OSGMANIPULATOR_SCALEAXISDRAGGER
#define OSGMANIPULATOR_SCALEAXISDRAGGER 1
#include <osgManipulator/Scale1DDragger>
namespace osgManipulator {
/**
* Dragger for performing scaling on all 3 axes.
*/
class OSGMANIPULATOR_EXPORT ScaleAxisDragger : public CompositeDragger
{
public:
ScaleAxisDragger();
/** Setup default geometry for dragger. */
void setupDefaultGeometry();
protected:
virtual ~ScaleAxisDragger();
osg::ref_ptr< Scale1DDragger > _xDragger;
osg::ref_ptr< Scale1DDragger > _yDragger;
osg::ref_ptr< Scale1DDragger > _zDragger;
};
}
#endif

View File

@@ -0,0 +1,68 @@
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
*
* This library is open source and may be redistributed and/or modified under
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
* (at your option) any later version. The full license is in LICENSE file
* included with this distribution, and on the openscenegraph.org website.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* OpenSceneGraph Public License for more details.
*/
//osgManipulator - Copyright (C) 2007 Fugro-Jason B.V.
#ifndef OSGMANIPULATOR_SELECTION
#define OSGMANIPULATOR_SELECTION 1
#include <osgManipulator/Export>
#include <osg/MatrixTransform>
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);
/**
* Selection listens to motion commands generated by draggers.
*/
class OSGMANIPULATOR_EXPORT Selection : public osg::MatrixTransform
{
public:
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;
};
}
#endif

View File

@@ -0,0 +1,47 @@
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
*
* This library is open source and may be redistributed and/or modified under
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
* (at your option) any later version. The full license is in LICENSE file
* included with this distribution, and on the openscenegraph.org website.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* OpenSceneGraph Public License for more details.
*/
//osgManipulator - Copyright (C) 2007 Fugro-Jason B.V.
#ifndef OSGMANIPULATOR_TABBOXDRAGGER
#define OSGMANIPULATOR_TABBOXDRAGGER 1
#include <osgManipulator/TabPlaneDragger>
namespace osgManipulator {
/**
* TabBoxDragger consists of 6 TabPlaneDraggers to form a box dragger that
* performs translation and scaling.
*/
class OSGMANIPULATOR_EXPORT TabBoxDragger : public CompositeDragger
{
public:
TabBoxDragger();
/** Setup default geometry for dragger. */
void setupDefaultGeometry();
void setPlaneColor(const osg::Vec4& color);
protected:
virtual ~TabBoxDragger();
std::vector< osg::ref_ptr< TabPlaneDragger > > _planeDraggers;
};
}
#endif

View File

@@ -0,0 +1,59 @@
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
*
* This library is open source and may be redistributed and/or modified under
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
* (at your option) any later version. The full license is in LICENSE file
* included with this distribution, and on the openscenegraph.org website.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* OpenSceneGraph Public License for more details.
*/
//osgManipulator - Copyright (C) 2007 Fugro-Jason B.V.
#ifndef OSGMANIPULATOR_TABPLANEDRAGGER
#define OSGMANIPULATOR_TABPLANEDRAGGER 1
#include <osgManipulator/TranslatePlaneDragger>
#include <osgManipulator/Scale2DDragger>
#include <osgManipulator/Scale1DDragger>
namespace osgManipulator {
/**
* Tab plane dragger consists of a plane with tabs on it's corners and edges
* for scaling. And the plane is used as a 2D translate dragger.
*/
class OSGMANIPULATOR_EXPORT TabPlaneDragger : public CompositeDragger
{
public:
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);
/** Setup default geometry for dragger. */
void setupDefaultGeometry(bool twoSidedHandle = true);
void setPlaneColor(const osg::Vec4& color) { _translateDragger->setColor(color); }
protected:
virtual ~TabPlaneDragger();
osg::ref_ptr< TranslatePlaneDragger > _translateDragger;
osg::ref_ptr< Scale2DDragger > _cornerScaleDragger;
osg::ref_ptr< Scale1DDragger > _horzEdgeScaleDragger;
osg::ref_ptr< Scale1DDragger > _vertEdgeScaleDragger;
float _handleScaleFactor;
};
}
#endif

View File

@@ -0,0 +1,48 @@
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
*
* This library is open source and may be redistributed and/or modified under
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
* (at your option) any later version. The full license is in LICENSE file
* included with this distribution, and on the openscenegraph.org website.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* OpenSceneGraph Public License for more details.
*/
//osgManipulator - Copyright (C) 2007 Fugro-Jason B.V.
#ifndef OSGMANIPULATOR_TABPLANETRACKBALLDRAGGER
#define OSGMANIPULATOR_TABPLANETRACKBALLDRAGGER 1
#include <osgManipulator/TrackballDragger>
#include <osgManipulator/TabPlaneDragger>
namespace osgManipulator {
/**
* Dragger for performing rotation in all axes.
*/
class OSGMANIPULATOR_EXPORT TabPlaneTrackballDragger : public CompositeDragger
{
public:
TabPlaneTrackballDragger();
/** Setup default geometry for dragger. */
void setupDefaultGeometry();
void setPlaneColor(const osg::Vec4& color) { _tabPlaneDragger->setPlaneColor(color); }
protected:
virtual ~TabPlaneTrackballDragger();
osg::ref_ptr<TrackballDragger> _trackballDragger;
osg::ref_ptr<TabPlaneDragger> _tabPlaneDragger;
};
}
#endif

View File

@@ -0,0 +1,48 @@
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
*
* This library is open source and may be redistributed and/or modified under
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
* (at your option) any later version. The full license is in LICENSE file
* included with this distribution, and on the openscenegraph.org website.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* OpenSceneGraph Public License for more details.
*/
//osgManipulator - Copyright (C) 2007 Fugro-Jason B.V.
#ifndef OSGMANIPULATOR_TRACKBALLDRAGGER
#define OSGMANIPULATOR_TRACKBALLDRAGGER 1
#include <osgManipulator/RotateCylinderDragger>
#include <osgManipulator/RotateSphereDragger>
namespace osgManipulator {
/**
* Dragger for performing rotation in all axes.
*/
class OSGMANIPULATOR_EXPORT TrackballDragger : public CompositeDragger
{
public:
TrackballDragger(bool useAutoTransform=false);
/** Setup default geometry for dragger. */
void setupDefaultGeometry();
protected:
virtual ~TrackballDragger();
osg::ref_ptr<RotateCylinderDragger> _xDragger;
osg::ref_ptr<RotateCylinderDragger> _yDragger;
osg::ref_ptr<RotateCylinderDragger> _zDragger;
osg::ref_ptr<RotateSphereDragger> _xyzDragger;
};
}
#endif

View File

@@ -0,0 +1,71 @@
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
*
* This library is open source and may be redistributed and/or modified under
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
* (at your option) any later version. The full license is in LICENSE file
* included with this distribution, and on the openscenegraph.org website.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* OpenSceneGraph Public License for more details.
*/
//osgManipulator - Copyright (C) 2007 Fugro-Jason B.V.
#ifndef OSGMANIPULATOR_TRANSLATE1DDRAGGER
#define OSGMANIPULATOR_TRANSLATE1DDRAGGER 1
#include <osgManipulator/Dragger>
#include <osgManipulator/Projector>
namespace osgManipulator {
/**
* Dragger for performing 1D translation.
*/
class OSGMANIPULATOR_EXPORT Translate1DDragger : public Dragger
{
public:
Translate1DDragger();
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);
/** Setup default geometry for dragger. */
void setupDefaultGeometry();
/** Set/Get color for dragger. */
inline void setColor(const osg::Vec4& color) { _color = color; setMaterialColor(_color,*this); }
inline const osg::Vec4 getColor() const { return _color; }
/** Set/Get pick color for dragger. Pick color is color of the dragger when picked.
It gives a visual feedback to show that the dragger has been picked. */
inline void setPickColor(const osg::Vec4& color) { _pickColor = color; }
inline const osg::Vec4 getPickColor() const { return _pickColor; }
inline void setCheckForNodeInNodePath(bool onOff) { _checkForNodeInNodePath = onOff; }
protected:
virtual ~Translate1DDragger();
osg::ref_ptr< LineProjector > _projector;
osg::Vec3 _startProjectedPoint;
osg::Vec4 _color;
osg::Vec4 _pickColor;
bool _checkForNodeInNodePath;
};
}
#endif

View File

@@ -0,0 +1,69 @@
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
*
* This library is open source and may be redistributed and/or modified under
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
* (at your option) any later version. The full license is in LICENSE file
* included with this distribution, and on the openscenegraph.org website.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* OpenSceneGraph Public License for more details.
*/
//osgManipulator - Copyright (C) 2007 Fugro-Jason B.V.
#ifndef OSGMANIPULATOR_TRANSLATE2DDRAGGER
#define OSGMANIPULATOR_TRANSLATE2DDRAGGER 1
#include <osgManipulator/Dragger>
#include <osgManipulator/Projector>
#include <osg/PolygonOffset>
namespace osgManipulator {
/**
* Dragger for performing 2D translation.
*/
class OSGMANIPULATOR_EXPORT Translate2DDragger : public Dragger
{
public:
Translate2DDragger();
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);
/** Setup default geometry for dragger. */
void setupDefaultGeometry();
/** Set/Get color for dragger. */
inline void setColor(const osg::Vec4& color) { _color = color; setMaterialColor(_color,*this); }
inline const osg::Vec4 getColor() const { return _color; }
/** Set/Get pick color for dragger. Pick color is color of the dragger when picked.
It gives a visual feedback to show that the dragger has been picked. */
inline void setPickColor(const osg::Vec4& color) { _pickColor = color; }
inline const osg::Vec4 getPickColor() const { return _pickColor; }
protected:
virtual ~Translate2DDragger();
osg::ref_ptr< PlaneProjector > _projector;
osg::Vec3 _startProjectedPoint;
osg::Vec4 _color;
osg::Vec4 _pickColor;
osg::ref_ptr<osg::PolygonOffset> _polygonOffset;
};
}
#endif

View File

@@ -0,0 +1,46 @@
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
*
* This library is open source and may be redistributed and/or modified under
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
* (at your option) any later version. The full license is in LICENSE file
* included with this distribution, and on the openscenegraph.org website.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* OpenSceneGraph Public License for more details.
*/
//osgManipulator - Copyright (C) 2007 Fugro-Jason B.V.
#ifndef OSGMANIPULATOR_TRANSLATEAXISDRAGGER
#define OSGMANIPULATOR_TRANSLATEAXISDRAGGER 1
#include <osgManipulator/Translate1DDragger>
namespace osgManipulator {
/**
* Dragger for performing translation in all three axes.
*/
class OSGMANIPULATOR_EXPORT TranslateAxisDragger : public CompositeDragger
{
public:
TranslateAxisDragger();
/** Setup default geometry for dragger. */
void setupDefaultGeometry();
protected:
virtual ~TranslateAxisDragger();
osg::ref_ptr< Translate1DDragger > _xDragger;
osg::ref_ptr< Translate1DDragger > _yDragger;
osg::ref_ptr< Translate1DDragger > _zDragger;
};
}
#endif

View File

@@ -0,0 +1,58 @@
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
*
* This library is open source and may be redistributed and/or modified under
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
* (at your option) any later version. The full license is in LICENSE file
* included with this distribution, and on the openscenegraph.org website.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* OpenSceneGraph Public License for more details.
*/
//osgManipulator - Copyright (C) 2007 Fugro-Jason B.V.
#ifndef OSGMANIPULATOR_TRANSLATEPLANEDRAGGER
#define OSGMANIPULATOR_TRANSLATEPLANEDRAGGER 1
#include <osgManipulator/Translate2DDragger>
#include <osgManipulator/Translate1DDragger>
namespace osgManipulator {
/**
* Tab plane dragger consists of a plane with tabs on it's corners and edges
* for scaling. And the plane is used as a 2D translate dragger.
*/
class OSGMANIPULATOR_EXPORT TranslatePlaneDragger : public CompositeDragger
{
public:
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);
/** Setup default geometry for dragger. */
void setupDefaultGeometry();
inline void setColor(const osg::Vec4& color) { if (_translate2DDragger.valid()) _translate2DDragger->setColor(color); }
Translate1DDragger* getTranslate1DDragger() { return _translate1DDragger.get(); }
Translate2DDragger* getTranslate2DDragger() { return _translate2DDragger.get(); }
protected:
virtual ~TranslatePlaneDragger();
osg::ref_ptr< Translate2DDragger > _translate2DDragger;
osg::ref_ptr< Translate1DDragger > _translate1DDragger;
bool _usingTranslate1DDragger;
};
}
#endif