OSG  3.4.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Constraint.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_CONSTRAINT
16 #define OSGMANIPULATOR_CONSTRAINT 1
17 
18 #include <osgManipulator/Export>
19 
20 #include <osg/observer_ptr>
21 #include <osg/Node>
22 #include <osg/Matrix>
23 
24 namespace osgManipulator {
25 
26 class MotionCommand;
27 class TranslateInLineCommand;
28 class TranslateInPlaneCommand;
29 class Scale1DCommand;
30 class Scale2DCommand;
31 class ScaleUniformCommand;
32 class Rotate3DCommand;
33 
34 
35 class DraggerCallback : virtual public osg::Object
36 {
37  public:
39  osg::Object(true) {}
40 
42  osg::Object(true) {}
43 
45 
49  virtual bool receive(const MotionCommand&) { return false; }
50  virtual bool receive(const TranslateInLineCommand& command) { return receive((MotionCommand&)command); }
51  virtual bool receive(const TranslateInPlaneCommand& command) { return receive((MotionCommand&)command); }
52  virtual bool receive(const Scale1DCommand& command) { return receive((MotionCommand&)command); }
53  virtual bool receive(const Scale2DCommand& command) { return receive((MotionCommand&)command); }
54  virtual bool receive(const ScaleUniformCommand& command) { return receive((MotionCommand&)command); }
55  virtual bool receive(const Rotate3DCommand& command) { return receive((MotionCommand&)command); }
56 };
57 
58 
60 {
61  public:
62 
63  virtual bool constrain(MotionCommand&) const { return false; }
64  virtual bool constrain(TranslateInLineCommand& command) const { return constrain((MotionCommand&)command); }
65  virtual bool constrain(TranslateInPlaneCommand& command) const { return constrain((MotionCommand&)command); }
66  virtual bool constrain(Scale1DCommand& command) const { return constrain((MotionCommand&)command); }
67  virtual bool constrain(Scale2DCommand& command) const { return constrain((MotionCommand&)command); }
68  virtual bool constrain(ScaleUniformCommand& command) const { return constrain((MotionCommand&)command); }
69  virtual bool constrain(Rotate3DCommand& command) const { return constrain((MotionCommand&)command); }
70 
71 protected:
72 
74  Constraint(osg::Node& refNode) : _refNode(&refNode) {}
75  virtual ~Constraint() {}
76 
77  osg::Node& getReferenceNode() { return *_refNode; }
78  const osg::Node& getReferenceNode() const { return *_refNode; }
79 
80  const osg::Matrix& getLocalToWorld() const { return _localToWorld; }
81  const osg::Matrix& getWorldToLocal() const { return _worldToLocal; }
82 
83  void computeLocalToWorldAndWorldToLocal() const;
84 
85  private:
86 
88  mutable osg::Matrix _localToWorld;
89  mutable osg::Matrix _worldToLocal;
90 };
91 
96 {
97  public:
98 
99  GridConstraint(osg::Node& refNode, const osg::Vec3d& origin, const osg::Vec3d& spacing);
100 
101  void setOrigin(const osg::Vec3d& origin) { _origin = origin; }
102  const osg::Vec3d& getOrigin() const { return _origin; }
103 
104  void setSpacing(const osg::Vec3d& spacing) { _spacing = spacing; }
105  const osg::Vec3d& getSpacing() const { return _spacing; }
106 
107  virtual bool constrain(TranslateInLineCommand& command) const;
108  virtual bool constrain(TranslateInPlaneCommand& command) const;
109  virtual bool constrain(Scale1DCommand& command) const;
110  virtual bool constrain(Scale2DCommand& command) const;
111  virtual bool constrain(ScaleUniformCommand& command) const;
112 
113  protected:
114 
115  virtual ~GridConstraint() {}
116 
117  private:
118 
119  osg::Vec3d _origin;
120  osg::Vec3d _spacing;
121  mutable osg::Matrix _startMatrix;
122  mutable osg::Matrix _matrix;
123 };
124 
125 }
126 
127 #endif
Constraint(osg::Node &refNode)
Definition: Constraint.h:74
const osg::Matrix & getWorldToLocal() const
Definition: Constraint.h:81
virtual bool receive(const Scale1DCommand &command)
Definition: Constraint.h:52
virtual bool receive(const MotionCommand &)
Definition: Constraint.h:49
virtual bool constrain(Rotate3DCommand &command) const
Definition: Constraint.h:69
#define OSGMANIPULATOR_EXPORT
Definition: Export.h:27
virtual bool constrain(Scale1DCommand &command) const
Definition: Constraint.h:66
const osg::Vec3d & getSpacing() const
Definition: Constraint.h:105
const osg::Vec3d & getOrigin() const
Definition: Constraint.h:102
void setSpacing(const osg::Vec3d &spacing)
Definition: Constraint.h:104
META_Object(osgManipulator, DraggerCallback)
virtual bool receive(const Scale2DCommand &command)
Definition: Constraint.h:53
virtual bool constrain(TranslateInLineCommand &command) const
Definition: Constraint.h:64
Object()
Definition: Object.h:65
osg::Node & getReferenceNode()
Definition: Constraint.h:77
virtual bool receive(const TranslateInPlaneCommand &command)
Definition: Constraint.h:51
void setOrigin(const osg::Vec3d &origin)
Definition: Constraint.h:101
const osg::Node & getReferenceNode() const
Definition: Constraint.h:78
DraggerCallback(const DraggerCallback &, const osg::CopyOp &=osg::CopyOp::SHALLOW_COPY)
Definition: Constraint.h:41
Definition: Node.h:71
Definition: AlphaFunc.h:19
virtual bool receive(const ScaleUniformCommand &command)
Definition: Constraint.h:54
virtual bool constrain(MotionCommand &) const
Definition: Constraint.h:63
virtual bool constrain(ScaleUniformCommand &command) const
Definition: Constraint.h:68
virtual bool receive(const TranslateInLineCommand &command)
Definition: Constraint.h:50
const osg::Matrix & getLocalToWorld() const
Definition: Constraint.h:80
virtual bool receive(const Rotate3DCommand &command)
Definition: Constraint.h:55
virtual bool constrain(TranslateInPlaneCommand &command) const
Definition: Constraint.h:65
virtual bool constrain(Scale2DCommand &command) const
Definition: Constraint.h:67