OSG  3.4.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Command.h
Go to the documentation of this file.
1 /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
2  *
3  * This library is open source and may be redistributed and/or modified under
4  * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
5  * (at your option) any later version. The full license is in LICENSE file
6  * included with this distribution, and on the openscenegraph.org website.
7  *
8  * This library is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * OpenSceneGraph Public License for more details.
12 */
13 //osgManipulator - Copyright (C) 2007 Fugro-Jason B.V.
14 
15 #ifndef OSGMANIPULATOR_COMMAND
16 #define OSGMANIPULATOR_COMMAND 1
17 
18 #include <osgManipulator/Constraint>
19 
20 #include <osg/LineSegment>
21 #include <osg/Plane>
22 #include <osg/Vec2>
23 
24 #include <vector>
25 
26 namespace osgManipulator {
27 
28 
31 {
32  public:
33 
39  enum Stage
40  {
47  FINISH
48  };
49 
50  MotionCommand();
51 
53  virtual MotionCommand* createCommandInverse() = 0;
54 
59  virtual osg::Matrix getMotionMatrix() const = 0;
60 
61  virtual void accept(const Constraint& constraint) { constraint.constrain(*this); }
62  virtual void accept(DraggerCallback& callback) { callback.receive(*this); }
63 
68  void setLocalToWorldAndWorldToLocal(const osg::Matrix& localToWorld, const osg::Matrix& worldToLocal)
69  {
70  _localToWorld = localToWorld;
71  _worldToLocal = worldToLocal;
72  }
73 
78  inline const osg::Matrix& getLocalToWorld() const { return _localToWorld; }
79 
84  inline const osg::Matrix& getWorldToLocal() const { return _worldToLocal; }
85 
86  void setStage(const Stage s) { _stage = s; }
87  Stage getStage() const { return _stage; }
88 
89  protected:
90 
91  virtual ~MotionCommand();
92 
93  private:
94  osg::Matrix _localToWorld;
95  osg::Matrix _worldToLocal;
96 
97  Stage _stage;
98 };
99 
100 
105 {
106  public:
107 
109 
111 
112  virtual void accept(const Constraint& constraint) {constraint.constrain(*this); }
113  virtual void accept(DraggerCallback& callback) { callback.receive(*this); }
114 
115  virtual MotionCommand* createCommandInverse();
116 
117  inline void setLine(const osg::LineSegment::vec_type& s, const osg::LineSegment::vec_type& e) { _line->start() = s; _line->end() = e; }
118  inline const osg::LineSegment::vec_type& getLineStart() const { return _line->start(); }
119  inline const osg::LineSegment::vec_type& getLineEnd() const { return _line->end(); }
120 
121  inline void setTranslation(const osg::Vec3& t) { _translation = t; }
122  inline const osg::Vec3d& getTranslation() const { return _translation; }
123 
124  virtual osg::Matrix getMotionMatrix() const
125  {
126  return osg::Matrix::translate(_translation);
127  }
128 
129  protected:
130 
131  virtual ~TranslateInLineCommand();
132 
133  private:
135  osg::Vec3d _translation;
136 };
137 
142 {
143  public:
144 
146 
147  TranslateInPlaneCommand(const osg::Plane& plane);
148 
149  virtual void accept(const Constraint& constraint) {constraint.constrain(*this); }
150  virtual void accept(DraggerCallback& callback) { callback.receive(*this); }
151 
152  virtual MotionCommand* createCommandInverse();
153 
154  inline void setPlane(const osg::Plane& plane) { _plane = plane; }
155  inline const osg::Plane& getPlane() const { return _plane; }
156 
157  inline void setTranslation(const osg::Vec3d& t) { _translation = t; }
158  inline const osg::Vec3d& getTranslation() const { return _translation; }
159 
161  inline void setReferencePoint(const osg::Vec3d& rp) { _referencePoint = rp; }
162  inline const osg::Vec3d& getReferencePoint() const { return _referencePoint; }
163 
164  virtual osg::Matrix getMotionMatrix() const
165  {
166  return osg::Matrix::translate(_translation);
167  }
168 
169  protected:
170 
171  virtual ~TranslateInPlaneCommand();
172 
173  private:
174  osg::Plane _plane;
175  osg::Vec3d _translation;
176  osg::Vec3d _referencePoint;
177 };
178 
183 {
184  public:
185 
186  Scale1DCommand();
187 
188  virtual void accept(const Constraint& constraint) {constraint.constrain(*this); }
189  virtual void accept(DraggerCallback& callback) { callback.receive(*this); }
190 
191  virtual MotionCommand* createCommandInverse();
192 
193  inline void setScale(double s) { _scale = s; }
194  inline double getScale() const { return _scale; }
195 
196  inline void setScaleCenter(double center) { _scaleCenter = center; }
197  inline double getScaleCenter() const { return _scaleCenter; }
198 
200  inline void setReferencePoint(double rp) { _referencePoint = rp; }
201  inline double getReferencePoint() const { return _referencePoint; }
202 
203  inline void setMinScale(double min) { _minScale = min; }
204  inline double getMinScale() const { return _minScale; }
205 
206  virtual osg::Matrix getMotionMatrix() const
207  {
208  return (osg::Matrix::translate(-_scaleCenter,0.0,0.0)
209  * osg::Matrix::scale(_scale,1.0,1.0)
210  * osg::Matrix::translate(_scaleCenter,0.0,0.0));
211  }
212 
213  protected:
214 
215  virtual ~Scale1DCommand();
216 
217  private:
218  double _scale;
219  double _scaleCenter;
220  double _referencePoint;
221  double _minScale;
222 };
223 
228 {
229  public:
230 
231  Scale2DCommand();
232 
233  virtual void accept(const Constraint& constraint) {constraint.constrain(*this); }
234  virtual void accept(DraggerCallback& callback) { callback.receive(*this); }
235 
236  virtual MotionCommand* createCommandInverse();
237 
238  inline void setScale(const osg::Vec2d& s) { _scale = s; }
239  inline const osg::Vec2d& getScale() const { return _scale; }
240 
241  inline void setScaleCenter(const osg::Vec2d& center) { _scaleCenter = center; }
242  inline const osg::Vec2d& getScaleCenter() const { return _scaleCenter; }
243 
245  inline void setReferencePoint(const osg::Vec2d& rp) { _referencePoint = rp; }
246  inline const osg::Vec2d& getReferencePoint() const { return _referencePoint; }
247 
248  inline void setMinScale(const osg::Vec2d& min) { _minScale = min; }
249  inline const osg::Vec2d& getMinScale() const { return _minScale; }
250 
251  virtual osg::Matrix getMotionMatrix() const
252  {
253  return (osg::Matrix::translate(-_scaleCenter[0],0.0,-_scaleCenter[1])
254  * osg::Matrix::scale(_scale[0],1.0,_scale[1])
255  * osg::Matrix::translate(_scaleCenter[0],0.0,_scaleCenter[1]));
256  }
257 
258  protected:
259 
260  virtual ~Scale2DCommand();
261 
262  private:
263  osg::Vec2d _scale;
264  osg::Vec2d _scaleCenter;
265  osg::Vec2d _referencePoint;
266  osg::Vec2d _minScale;
267 };
268 
273 {
274  public:
275 
277 
278  virtual void accept(const Constraint& constraint) {constraint.constrain(*this); }
279  virtual void accept(DraggerCallback& callback) { callback.receive(*this); }
280 
281  virtual MotionCommand* createCommandInverse();
282 
283  inline void setScale(double s) { _scale = s; }
284  inline double getScale() const { return _scale; }
285 
286  inline void setScaleCenter(const osg::Vec3d& center) { _scaleCenter = center; }
287  inline const osg::Vec3d& getScaleCenter() const { return _scaleCenter; }
288 
289  virtual osg::Matrix getMotionMatrix() const
290  {
291  return (osg::Matrix::translate(-_scaleCenter)
292  * osg::Matrix::scale(_scale,_scale,_scale)
293  * osg::Matrix::translate(_scaleCenter));
294  }
295 
296  protected:
297 
298  virtual ~ScaleUniformCommand();
299 
300  private:
301  double _scale;
302  osg::Vec3d _scaleCenter;
303 };
304 
309 {
310  public:
311 
312  Rotate3DCommand();
313 
314  virtual void accept(const Constraint& constraint) {constraint.constrain(*this); }
315  virtual void accept(DraggerCallback& callback) { callback.receive(*this); }
316 
317  virtual MotionCommand* createCommandInverse();
318 
319  inline void setRotation(const osg::Quat& rotation) { _rotation = rotation; }
320  inline const osg::Quat& getRotation() const { return _rotation; }
321 
322  virtual osg::Matrix getMotionMatrix() const
323  {
324  return osg::Matrix::rotate(_rotation);
325  }
326 
327  protected:
328 
329  virtual ~Rotate3DCommand();
330 
331  private:
332  osg::Quat _rotation;
333 };
334 
335 
336 }
337 
338 #endif
void setTranslation(const osg::Vec3 &t)
Definition: Command.h:121
void setReferencePoint(const osg::Vec3d &rp)
Definition: Command.h:161
virtual osg::Matrix getMotionMatrix() const
Definition: Command.h:251
const osg::Matrix & getWorldToLocal() const
Definition: Command.h:84
virtual void accept(const Constraint &constraint)
Definition: Command.h:278
void setScale(const osg::Vec2d &s)
Definition: Command.h:238
static Matrixd translate(const Vec3f &dv)
Definition: Matrixd.h:469
virtual bool receive(const MotionCommand &)
Definition: Constraint.h:49
#define OSGMANIPULATOR_EXPORT
Definition: Export.h:27
double getScaleCenter() const
Definition: Command.h:197
virtual osg::Matrix getMotionMatrix() const
Definition: Command.h:124
virtual void accept(const Constraint &constraint)
Definition: Command.h:188
virtual void accept(DraggerCallback &callback)
Definition: Command.h:279
void setStage(const Stage s)
Definition: Command.h:86
virtual void accept(DraggerCallback &callback)
Definition: Command.h:315
virtual void accept(DraggerCallback &callback)
Definition: Command.h:62
void setScaleCenter(double center)
Definition: Command.h:196
void setScaleCenter(const osg::Vec3d &center)
Definition: Command.h:286
double getScale() const
Definition: Command.h:194
void setLine(const osg::LineSegment::vec_type &s, const osg::LineSegment::vec_type &e)
Definition: Command.h:117
void setMinScale(const osg::Vec2d &min)
Definition: Command.h:248
const osg::LineSegment::vec_type & getLineEnd() const
Definition: Command.h:119
static Matrixd rotate(const Vec3f &from, const Vec3f &to)
Definition: Matrixd.h:517
const osg::Matrix & getLocalToWorld() const
Definition: Command.h:78
virtual void accept(DraggerCallback &callback)
Definition: Command.h:113
const osg::LineSegment::vec_type & getLineStart() const
Definition: Command.h:118
void setTranslation(const osg::Vec3d &t)
Definition: Command.h:157
void setMinScale(double min)
Definition: Command.h:203
void setReferencePoint(double rp)
Definition: Command.h:200
virtual osg::Matrix getMotionMatrix() const
Definition: Command.h:322
double getMinScale() const
Definition: Command.h:204
const osg::Vec2d & getMinScale() const
Definition: Command.h:249
virtual void accept(const Constraint &constraint)
Definition: Command.h:112
const osg::Vec2d & getReferencePoint() const
Definition: Command.h:246
virtual void accept(DraggerCallback &callback)
Definition: Command.h:189
virtual void accept(const Constraint &constraint)
Definition: Command.h:233
virtual void accept(DraggerCallback &callback)
Definition: Command.h:234
A plane class. It can be used to represent an infinite plane.
Definition: Plane.h:33
virtual void accept(const Constraint &constraint)
Definition: Command.h:314
void setScaleCenter(const osg::Vec2d &center)
Definition: Command.h:241
const osg::Vec3d & getReferencePoint() const
Definition: Command.h:162
void setReferencePoint(const osg::Vec2d &rp)
Definition: Command.h:245
virtual void accept(const Constraint &constraint)
Definition: Command.h:61
const osg::Vec3d & getTranslation() const
Definition: Command.h:122
virtual void accept(DraggerCallback &callback)
Definition: Command.h:150
static Matrixd scale(const Vec3f &sv)
Definition: Matrixd.h:452
virtual osg::Matrix getMotionMatrix() const
Definition: Command.h:206
void setRotation(const osg::Quat &rotation)
Definition: Command.h:319
const osg::Plane & getPlane() const
Definition: Command.h:155
virtual void accept(const Constraint &constraint)
Definition: Command.h:149
double getReferencePoint() const
Definition: Command.h:201
const osg::Vec3d & getTranslation() const
Definition: Command.h:158
Stage getStage() const
Definition: Command.h:87
virtual bool constrain(MotionCommand &) const
Definition: Constraint.h:63
void setPlane(const osg::Plane &plane)
Definition: Command.h:154
Definition: Quat.h:29
const osg::Vec3d & getScaleCenter() const
Definition: Command.h:287
const osg::Vec2d & getScaleCenter() const
Definition: Command.h:242
const osg::Quat & getRotation() const
Definition: Command.h:320
void setLocalToWorldAndWorldToLocal(const osg::Matrix &localToWorld, const osg::Matrix &worldToLocal)
Definition: Command.h:68
const osg::Vec2d & getScale() const
Definition: Command.h:239
virtual osg::Matrix getMotionMatrix() const
Definition: Command.h:289
virtual osg::Matrix getMotionMatrix() const
Definition: Command.h:164