Command
Go to the documentation of this file.
/* -*-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/Constraint>
#include <osg/LineSegment>
#include <osg/Plane>
#include <osg/Vec2>
#include <vector>
namespace osgManipulator {
class OSGMANIPULATOR_EXPORT MotionCommand : public osg::Referenced
{
public:
enum Stage
{
NONE,
START,
MOVE,
FINISH
};
MotionCommand();
virtual MotionCommand* createCommandInverse() = 0;
virtual osg::Matrix getMotionMatrix() const = 0;
virtual void accept(const Constraint& constraint) { constraint.constrain(*this); }
virtual void accept(DraggerCallback& callback) { callback.receive(*this); }
void setLocalToWorldAndWorldToLocal(const osg::Matrix& localToWorld, const osg::Matrix& worldToLocal)
{
_localToWorld = localToWorld;
_worldToLocal = worldToLocal;
}
inline const osg::Matrix& getLocalToWorld() const { return _localToWorld; }
inline const osg::Matrix& getWorldToLocal() const { return _worldToLocal; }
void setStage(const Stage s) { _stage = s; }
Stage getStage() const { return _stage; }
protected:
virtual ~MotionCommand();
private:
osg::Matrix _localToWorld;
osg::Matrix _worldToLocal;
Stage _stage;
};
class OSGMANIPULATOR_EXPORT TranslateInLineCommand : public MotionCommand
{
public:
TranslateInLineCommand();
TranslateInLineCommand(const osg::LineSegment::vec_type& s, const osg::LineSegment::vec_type& e);
virtual void accept(const Constraint& constraint) {constraint.constrain(*this); }
virtual void accept(DraggerCallback& callback) { callback.receive(*this); }
virtual MotionCommand* createCommandInverse();
inline void setLine(const osg::LineSegment::vec_type& s, const osg::LineSegment::vec_type& e) { _line->start() = s; _line->end() = e; }
inline const osg::LineSegment::vec_type& getLineStart() const { return _line->start(); }
inline const osg::LineSegment::vec_type& getLineEnd() const { return _line->end(); }
inline void setTranslation(const osg::Vec3d& t) { _translation = t; }
inline const osg::Vec3d& 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::Vec3d _translation;
};
class OSGMANIPULATOR_EXPORT TranslateInPlaneCommand : public MotionCommand
{
public:
TranslateInPlaneCommand();
TranslateInPlaneCommand(const osg::Plane& plane);
virtual void accept(const Constraint& constraint) {constraint.constrain(*this); }
virtual void accept(DraggerCallback& callback) { callback.receive(*this); }
virtual MotionCommand* createCommandInverse();
inline void setPlane(const osg::Plane& plane) { _plane = plane; }
inline const osg::Plane& getPlane() const { return _plane; }
inline void setTranslation(const osg::Vec3d& t) { _translation = t; }
inline const osg::Vec3d& getTranslation() const { return _translation; }
inline void setReferencePoint(const osg::Vec3d& rp) { _referencePoint = rp; }
inline const osg::Vec3d& getReferencePoint() const { return _referencePoint; }
virtual osg::Matrix getMotionMatrix() const
{
return osg::Matrix::translate(_translation);
}
protected:
virtual ~TranslateInPlaneCommand();
private:
osg::Plane _plane;
osg::Vec3d _translation;
osg::Vec3d _referencePoint;
};
class OSGMANIPULATOR_EXPORT Scale1DCommand : public MotionCommand
{
public:
Scale1DCommand();
virtual void accept(const Constraint& constraint) {constraint.constrain(*this); }
virtual void accept(DraggerCallback& callback) { callback.receive(*this); }
virtual MotionCommand* createCommandInverse();
inline void setScale(double s) { _scale = s; }
inline double getScale() const { return _scale; }
inline void setScaleCenter(double center) { _scaleCenter = center; }
inline double getScaleCenter() const { return _scaleCenter; }
inline void setReferencePoint(double rp) { _referencePoint = rp; }
inline double getReferencePoint() const { return _referencePoint; }
inline void setMinScale(double min) { _minScale = min; }
inline double 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:
double _scale;
double _scaleCenter;
double _referencePoint;
double _minScale;
};
class OSGMANIPULATOR_EXPORT Scale2DCommand : public MotionCommand
{
public:
Scale2DCommand();
virtual void accept(const Constraint& constraint) {constraint.constrain(*this); }
virtual void accept(DraggerCallback& callback) { callback.receive(*this); }
virtual MotionCommand* createCommandInverse();
inline void setScale(const osg::Vec2d& s) { _scale = s; }
inline const osg::Vec2d& getScale() const { return _scale; }
inline void setScaleCenter(const osg::Vec2d& center) { _scaleCenter = center; }
inline const osg::Vec2d& getScaleCenter() const { return _scaleCenter; }
inline void setReferencePoint(const osg::Vec2d& rp) { _referencePoint = rp; }
inline const osg::Vec2d& getReferencePoint() const { return _referencePoint; }
inline void setMinScale(const osg::Vec2d& min) { _minScale = min; }
inline const osg::Vec2d& 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::Vec2d _scale;
osg::Vec2d _scaleCenter;
osg::Vec2d _referencePoint;
osg::Vec2d _minScale;
};
class OSGMANIPULATOR_EXPORT ScaleUniformCommand : public MotionCommand
{
public:
ScaleUniformCommand();
virtual void accept(const Constraint& constraint) {constraint.constrain(*this); }
virtual void accept(DraggerCallback& callback) { callback.receive(*this); }
virtual MotionCommand* createCommandInverse();
inline void setScale(double s) { _scale = s; }
inline double getScale() const { return _scale; }
inline void setScaleCenter(const osg::Vec3d& center) { _scaleCenter = center; }
inline const osg::Vec3d& 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:
double _scale;
osg::Vec3d _scaleCenter;
};
class OSGMANIPULATOR_EXPORT Rotate3DCommand : public MotionCommand
{
public:
Rotate3DCommand();
virtual void accept(const Constraint& constraint) {constraint.constrain(*this); }
virtual void accept(DraggerCallback& callback) { callback.receive(*this); }
virtual MotionCommand* createCommandInverse();
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
Constraint
LineSegment
Plane
Vec2
osgManipulator::Constraint
Definition Constraint:60
osgManipulator::Constraint::constrain
virtual bool constrain(MotionCommand &) const
Definition Constraint:63
osgManipulator::DraggerCallback
Definition Constraint:36
osgManipulator::DraggerCallback::receive
virtual bool receive(const MotionCommand &)
Definition Constraint:49
osgManipulator::MotionCommand::Stage
Stage
Definition Command:40
osgManipulator::MotionCommand::FINISH
@ FINISH
Definition Command:47
osgManipulator::MotionCommand::NONE
@ NONE
Definition Command:41
osgManipulator::MotionCommand::MOVE
@ MOVE
Definition Command:45
osgManipulator::MotionCommand::START
@ START
Definition Command:43
osgManipulator::MotionCommand::accept
virtual void accept(const Constraint &constraint)
Definition Command:61
osgManipulator::MotionCommand::setLocalToWorldAndWorldToLocal
void setLocalToWorldAndWorldToLocal(const osg::Matrix &localToWorld, const osg::Matrix &worldToLocal)
Definition Command:68
osgManipulator::MotionCommand::getStage
Stage getStage() const
Definition Command:87
osgManipulator::MotionCommand::setStage
void setStage(const Stage s)
Definition Command:86
osgManipulator::MotionCommand::accept
virtual void accept(DraggerCallback &callback)
Definition Command:62
osgManipulator::MotionCommand::~MotionCommand
virtual ~MotionCommand()
osgManipulator::MotionCommand::getWorldToLocal
const osg::Matrix & getWorldToLocal() const
Definition Command:84
osgManipulator::MotionCommand::getMotionMatrix
virtual osg::Matrix getMotionMatrix() const =0
osgManipulator::MotionCommand::getLocalToWorld
const osg::Matrix & getLocalToWorld() const
Definition Command:78
osgManipulator::MotionCommand::MotionCommand
MotionCommand()
osgManipulator::MotionCommand::createCommandInverse
virtual MotionCommand * createCommandInverse()=0
osgManipulator::Rotate3DCommand::getRotation
const osg::Quat & getRotation() const
Definition Command:320
osgManipulator::Rotate3DCommand::setRotation
void setRotation(const osg::Quat &rotation)
Definition Command:319
osgManipulator::Rotate3DCommand::~Rotate3DCommand
virtual ~Rotate3DCommand()
osgManipulator::Rotate3DCommand::createCommandInverse
virtual MotionCommand * createCommandInverse()
osgManipulator::Rotate3DCommand::getMotionMatrix
virtual osg::Matrix getMotionMatrix() const
Definition Command:322
osgManipulator::Rotate3DCommand::Rotate3DCommand
Rotate3DCommand()
osgManipulator::Rotate3DCommand::accept
virtual void accept(DraggerCallback &callback)
Definition Command:315
osgManipulator::Rotate3DCommand::accept
virtual void accept(const Constraint &constraint)
Definition Command:314
osgManipulator::Scale1DCommand::setReferencePoint
void setReferencePoint(double rp)
Definition Command:200
osgManipulator::Scale1DCommand::accept
virtual void accept(DraggerCallback &callback)
Definition Command:189
osgManipulator::Scale1DCommand::setMinScale
void setMinScale(double min)
Definition Command:203
osgManipulator::Scale1DCommand::getScaleCenter
double getScaleCenter() const
Definition Command:197
osgManipulator::Scale1DCommand::Scale1DCommand
Scale1DCommand()
osgManipulator::Scale1DCommand::getMotionMatrix
virtual osg::Matrix getMotionMatrix() const
Definition Command:206
osgManipulator::Scale1DCommand::~Scale1DCommand
virtual ~Scale1DCommand()
osgManipulator::Scale1DCommand::setScaleCenter
void setScaleCenter(double center)
Definition Command:196
osgManipulator::Scale1DCommand::accept
virtual void accept(const Constraint &constraint)
Definition Command:188
osgManipulator::Scale1DCommand::createCommandInverse
virtual MotionCommand * createCommandInverse()
osgManipulator::Scale1DCommand::getReferencePoint
double getReferencePoint() const
Definition Command:201
osgManipulator::Scale1DCommand::setScale
void setScale(double s)
Definition Command:193
osgManipulator::Scale1DCommand::getMinScale
double getMinScale() const
Definition Command:204
osgManipulator::Scale1DCommand::getScale
double getScale() const
Definition Command:194
osgManipulator::Scale2DCommand::getScale
const osg::Vec2d & getScale() const
Definition Command:239
osgManipulator::Scale2DCommand::~Scale2DCommand
virtual ~Scale2DCommand()
osgManipulator::Scale2DCommand::setMinScale
void setMinScale(const osg::Vec2d &min)
Definition Command:248
osgManipulator::Scale2DCommand::setScaleCenter
void setScaleCenter(const osg::Vec2d &center)
Definition Command:241
osgManipulator::Scale2DCommand::accept
virtual void accept(const Constraint &constraint)
Definition Command:233
osgManipulator::Scale2DCommand::createCommandInverse
virtual MotionCommand * createCommandInverse()
osgManipulator::Scale2DCommand::getReferencePoint
const osg::Vec2d & getReferencePoint() const
Definition Command:246
osgManipulator::Scale2DCommand::Scale2DCommand
Scale2DCommand()
osgManipulator::Scale2DCommand::getScaleCenter
const osg::Vec2d & getScaleCenter() const
Definition Command:242
osgManipulator::Scale2DCommand::getMotionMatrix
virtual osg::Matrix getMotionMatrix() const
Definition Command:251
osgManipulator::Scale2DCommand::getMinScale
const osg::Vec2d & getMinScale() const
Definition Command:249
osgManipulator::Scale2DCommand::setScale
void setScale(const osg::Vec2d &s)
Definition Command:238
osgManipulator::Scale2DCommand::accept
virtual void accept(DraggerCallback &callback)
Definition Command:234
osgManipulator::Scale2DCommand::setReferencePoint
void setReferencePoint(const osg::Vec2d &rp)
Definition Command:245
osgManipulator::ScaleUniformCommand::getScaleCenter
const osg::Vec3d & getScaleCenter() const
Definition Command:287
osgManipulator::ScaleUniformCommand::getMotionMatrix
virtual osg::Matrix getMotionMatrix() const
Definition Command:289
osgManipulator::ScaleUniformCommand::accept
virtual void accept(const Constraint &constraint)
Definition Command:278
osgManipulator::ScaleUniformCommand::accept
virtual void accept(DraggerCallback &callback)
Definition Command:279
osgManipulator::ScaleUniformCommand::createCommandInverse
virtual MotionCommand * createCommandInverse()
osgManipulator::ScaleUniformCommand::setScaleCenter
void setScaleCenter(const osg::Vec3d &center)
Definition Command:286
osgManipulator::ScaleUniformCommand::setScale
void setScale(double s)
Definition Command:283
osgManipulator::ScaleUniformCommand::ScaleUniformCommand
ScaleUniformCommand()
osgManipulator::ScaleUniformCommand::getScale
double getScale() const
Definition Command:284
osgManipulator::ScaleUniformCommand::~ScaleUniformCommand
virtual ~ScaleUniformCommand()
osgManipulator::TranslateInLineCommand::setLine
void setLine(const osg::LineSegment::vec_type &s, const osg::LineSegment::vec_type &e)
Definition Command:117
osgManipulator::TranslateInLineCommand::getTranslation
const osg::Vec3d & getTranslation() const
Definition Command:122
osgManipulator::TranslateInLineCommand::accept
virtual void accept(const Constraint &constraint)
Definition Command:112
osgManipulator::TranslateInLineCommand::setTranslation
void setTranslation(const osg::Vec3d &t)
Definition Command:121
osgManipulator::TranslateInLineCommand::~TranslateInLineCommand
virtual ~TranslateInLineCommand()
osgManipulator::TranslateInLineCommand::TranslateInLineCommand
TranslateInLineCommand()
osgManipulator::TranslateInLineCommand::getLineEnd
const osg::LineSegment::vec_type & getLineEnd() const
Definition Command:119
osgManipulator::TranslateInLineCommand::getMotionMatrix
virtual osg::Matrix getMotionMatrix() const
Definition Command:124
osgManipulator::TranslateInLineCommand::TranslateInLineCommand
TranslateInLineCommand(const osg::LineSegment::vec_type &s, const osg::LineSegment::vec_type &e)
osgManipulator::TranslateInLineCommand::createCommandInverse
virtual MotionCommand * createCommandInverse()
osgManipulator::TranslateInLineCommand::getLineStart
const osg::LineSegment::vec_type & getLineStart() const
Definition Command:118
osgManipulator::TranslateInLineCommand::accept
virtual void accept(DraggerCallback &callback)
Definition Command:113
osgManipulator::TranslateInPlaneCommand::accept
virtual void accept(DraggerCallback &callback)
Definition Command:150
osgManipulator::TranslateInPlaneCommand::setReferencePoint
void setReferencePoint(const osg::Vec3d &rp)
Definition Command:161
osgManipulator::TranslateInPlaneCommand::~TranslateInPlaneCommand
virtual ~TranslateInPlaneCommand()
osgManipulator::TranslateInPlaneCommand::TranslateInPlaneCommand
TranslateInPlaneCommand()
osgManipulator::TranslateInPlaneCommand::TranslateInPlaneCommand
TranslateInPlaneCommand(const osg::Plane &plane)
osgManipulator::TranslateInPlaneCommand::getMotionMatrix
virtual osg::Matrix getMotionMatrix() const
Definition Command:164
osgManipulator::TranslateInPlaneCommand::getTranslation
const osg::Vec3d & getTranslation() const
Definition Command:158
osgManipulator::TranslateInPlaneCommand::setTranslation
void setTranslation(const osg::Vec3d &t)
Definition Command:157
osgManipulator::TranslateInPlaneCommand::getReferencePoint
const osg::Vec3d & getReferencePoint() const
Definition Command:162
osgManipulator::TranslateInPlaneCommand::getPlane
const osg::Plane & getPlane() const
Definition Command:155
osgManipulator::TranslateInPlaneCommand::accept
virtual void accept(const Constraint &constraint)
Definition Command:149
osgManipulator::TranslateInPlaneCommand::setPlane
void setPlane(const osg::Plane &plane)
Definition Command:154
osgManipulator::TranslateInPlaneCommand::createCommandInverse
virtual MotionCommand * createCommandInverse()
osg::LineSegment::vec_type
Vec3d vec_type
Definition LineSegment:28
osg::Matrixd::scale
static Matrixd scale(const Vec3f &sv)
Definition Matrixd:458
osg::Matrixd::rotate
static Matrixd rotate(const Vec3f &from, const Vec3f &to)
Definition Matrixd:523
osg::Matrixd::translate
static Matrixd translate(const Vec3f &dv)
Definition Matrixd:475
osg::Plane
A plane class. It can be used to represent an infinite plane.
Definition Plane:34
osg::Quat
Definition Quat:30
osg::Referenced
Definition Referenced:44
osg::Vec2d
Definition Vec2d:29
osg::Vec3d
Definition Vec3d:30
osg::ref_ptr
Definition ref_ptr:32
osgManipulator
Definition AntiSquish:23
osg::Matrix
Matrixd Matrix
Definition Matrix:27
OSGMANIPULATOR_EXPORT
#define OSGMANIPULATOR_EXPORT
Definition osgManipulator/Export:27