OpenSceneGraph 3.6.5
Dragger
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_DRAGGER
16#define OSGMANIPULATOR_DRAGGER 1
17
20
21#include <osg/BoundingSphere>
22#include <osg/MatrixTransform>
23#include <osgUtil/SceneView>
24#include <osgGA/GUIEventAdapter>
26
27namespace osgManipulator
28{
29
30class CompositeDragger;
31class MotionCommand;
32class TranslateInLineCommand;
33class TranslateInPlaneCommand;
34class Scale1DCommand;
35class Scale2DCommand;
36class ScaleUniformCommand;
37class Rotate3DCommand;
38
41
42
44{
45 public:
46
57
58 DraggerTransformCallback(osg::MatrixTransform* transform, int handleCommandMask = HANDLE_ALL);
59
60 virtual bool receive(const MotionCommand&);
61 virtual bool receive(const TranslateInLineCommand& command);
62 virtual bool receive(const TranslateInPlaneCommand& command);
63 virtual bool receive(const Scale1DCommand& command);
64 virtual bool receive(const Scale2DCommand& command);
65 virtual bool receive(const ScaleUniformCommand& command);
66 virtual bool receive(const Rotate3DCommand& command);
67
69 const osg::MatrixTransform* getTransform() const { return _transform.get(); }
70
71 protected:
72
73 unsigned int _handleCommandMask;
74
77
80};
81
82
84{
85 public:
86
88
90 _hitList(rhs._hitList),
93 _eyeDir(rhs._eyeDir)
94 {
95 _hitIter = _hitList.begin();
96 }
97
98 void reset()
99 {
100 _hitList.clear();
101 _hitIter = _hitList.begin();
102 setCamera(0);
103 }
104
105
106 bool completed() const { return _hitIter==_hitList.end(); }
107
108 void next()
109 {
110 if (!completed()) ++_hitIter;
111 }
112
113 typedef std::pair<osg::NodePath, osg::Vec3d> NodePathIntersectionPair;
114 typedef std::list< NodePathIntersectionPair> IntersectionList;
115
116
117 osg::Vec3d getLocalIntersectPoint() const { return _hitIter->second; }
118
119
120
121 void setNearFarPoints (osg::Vec3d nearPoint, osg::Vec3d farPoint) {
122 _nearPoint = nearPoint;
123 _farPoint=farPoint;
124 _eyeDir = farPoint - nearPoint;
125 }
126
127 const osg::Vec3d& getEyeDir() const {return _eyeDir;}
128
129 void getNearFarPoints( osg::Vec3d& nearPoint, osg::Vec3d& farPoint) const {
130 nearPoint = _nearPoint;
131 farPoint = _farPoint;
132 }
133
134 bool contains(const osg::Node* node) const;
135
136 void setCamera(osg::Camera* camera)
137 {
138
139 if (camera)
140 {
141 _MVPW = camera->getViewMatrix() * camera->getProjectionMatrix();
142 if (camera->getViewport()) _MVPW.postMult(camera->getViewport()->computeWindowMatrix());
143 _inverseMVPW.invert(_MVPW);
144 osg::Vec3d eye, center, up;
145 camera->getViewMatrix().getLookAt(eye, center, up);
146 _eyeDir = eye - center;
147
148 }
149 else
150 {
151 _MVPW.makeIdentity();
152 _inverseMVPW.makeIdentity();
153 _eyeDir = osg::Vec3d(0,0,1);
154 }
155
156 }
157
158 void addIntersection(const osg::NodePath& nodePath, const osg::Vec3d& intersectionPoint)
159 {
160 bool needToResetHitIter = _hitList.empty();
161 _hitList.push_back(NodePathIntersectionPair(nodePath, intersectionPoint));
162 if (needToResetHitIter) _hitIter = _hitList.begin();
163 }
164
165 void setMousePosition(float pixel_x, float pixel_y)
166 {
168 }
169
170 protected:
171 bool projectWindowXYIntoObject(const osg::Vec2d& windowCoord, osg::Vec3d& nearPoint, osg::Vec3d& farPoint) const;
172
173 public:
175 IntersectionList::const_iterator _hitIter;
176
177 protected:
178
181
184
185};
186
194{
195 public:
196
197
199
205 virtual void setParentDragger(Dragger* parent) { _parentDragger = parent; }
206
208 const Dragger* getParentDragger() const { return _parentDragger; }
209
211 virtual const CompositeDragger* getComposite() const { return 0; }
212
214 virtual CompositeDragger* getComposite() { return 0; }
215
216
217 void setHandleEvents(bool flag);
218 bool getHandleEvents() const { return _handleEvents; }
219
220 void setActivationModKeyMask(unsigned int mask) { _activationModKeyMask = mask; }
221 unsigned int getActivationModKeyMask() const { return _activationModKeyMask; }
222
225
228
229
230 virtual void traverse(osg::NodeVisitor& nv);
231
233 virtual bool handle(const PointerInfo&, const osgGA::GUIEventAdapter&, osgGA::GUIActionAdapter&) { return false; }
234
235
236 typedef std::vector< osg::ref_ptr<Constraint> > Constraints;
237
238 void addConstraint(Constraint* constraint);
239 template<class T> void addConstraint(const osg::ref_ptr<T>& c) { addConstraint(c.get()); }
240
241 void removeConstraint(Constraint* constraint);
242 template<class T> void removeConstraint(const osg::ref_ptr<T>& c) { removeConstraint(c.get()); }
243
245 const Constraints& getConstraints() const { return _constraints; }
246
247
248 typedef std::vector< osg::ref_ptr<DraggerCallback> > DraggerCallbacks;
249
251 template<class T> void addDraggerCallback(const osg::ref_ptr<T>& dc) { addDraggerCallback(dc.get()); }
252
254 template<class T> void removeDraggerCallback(const osg::ref_ptr<T>& dc) { removeDraggerCallback(dc.get()); }
255
258
261
263 virtual void setupDefaultGeometry() {}
264
265 virtual bool receive(const MotionCommand& command);
266 virtual void dispatch(MotionCommand& command);
267
268 void setDraggerActive(bool active) { _draggerActive = active; }
269 bool getDraggerActive() const { return _draggerActive; }
270
275 virtual void setIntersectionMask(osg::Node::NodeMask intersectionMask) { _intersectionMask = intersectionMask; }
277
279 bool inverted() const;
280
283
284protected:
285
288
289 virtual ~Dragger();
290
291
294
301
303
305
310
311};
312
313
319{
320 public:
321
323
324 typedef std::vector< osg::ref_ptr<Dragger> > DraggerList;
325
326 virtual const CompositeDragger* getComposite() const { return this; }
327 virtual CompositeDragger* getComposite() { return this; }
328
329 virtual void setParentDragger(Dragger* parent);
330
331 virtual bool handle(const PointerInfo& pi, const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa);
332
333 // Composite-specific methods below
334 virtual bool addDragger(Dragger* dragger);
335 template<class T> bool addDragger(const osg::ref_ptr<T>& dc) { return addDragger(dc.get()); }
336
337 virtual bool removeDragger(Dragger* dragger);
338 template<class T> bool removeDragger(const osg::ref_ptr<T>& dc) { return removeDragger(dc.get()); }
339
340 unsigned int getNumDraggers() const { return _draggerList.size(); }
341
342 Dragger* getDragger(unsigned int i) { return _draggerList[i].get(); }
343 const Dragger* getDragger(unsigned int i) const { return _draggerList[i].get(); }
344
345 bool containsDragger(const Dragger* dragger) const;
346 template<class T> bool containsDragger(const osg::ref_ptr<T>& dc) const { return containsDragger(dc.get()); }
347
348 DraggerList::iterator findDragger(const Dragger* dragger);
349
350 virtual void setIntersectionMask(osg::Node::NodeMask intersectionMask);
351
352 protected:
353
356
357 virtual ~CompositeDragger() {}
358
360};
361
369
374
375}
376
377#endif
Matrixd Matrix
Definition Matrix:27
Vec4f Vec4
Definition Vec4:21
std::vector< Node * > NodePath
A vector of Nodes pointers which is used to describe the path from a root node to a descendant.
Definition Node:47
The osgManipulator library is a NodeKit that extends the core scene graph to support 3D interactive m...
Definition AntiSquish:23
void OSGMANIPULATOR_EXPORT setDrawableToAlwaysCull(osg::Drawable &drawable)
Culls the drawable all the time.
void OSGMANIPULATOR_EXPORT setMaterialColor(const osg::Vec4 &color, osg::Node &node)
Convenience function for setting the material color on a node.
OSGMANIPULATOR_EXPORT void computeNodePathToRoot(osg::Node &node, osg::NodePath &np)
Computes the nodepath from the given node all the way up to the root.
Camera - is a subclass of Transform which represents encapsulates the settings of a Camera.
Definition Camera:45
osg::Matrixd & getProjectionMatrix()
Get the projection matrix.
Definition Camera:216
const Viewport * getViewport() const
Get the const viewport.
Definition Camera:156
osg::Matrixd & getViewMatrix()
Get the view matrix.
Definition Camera:250
Copy Op(erator) used to control whether shallow or deep copy is used during copy construction and clo...
Definition CopyOp:41
@ SHALLOW_COPY
Definition CopyOp:47
Pure virtual base class for drawable geometry.
Definition Drawable:89
void getLookAt(Vec3f &eye, Vec3f &center, Vec3f &up, value_type lookDistance=1.0f) const
Get to the position and orientation of a modelview matrix, using the same convention as gluLookAt.
MatrixTransform - is a subclass of Transform which has an osg::Matrix which represents a 4x4 transfor...
Definition MatrixTransform:26
Base class for all internal nodes in the scene graph.
Definition Node:72
unsigned int NodeMask
This is a set of bits (flags) that represent the Node.
Definition Node:363
Visitor for type safe operations on osg::Nodes.
Definition NodeVisitor:82
Smart pointer for observed objects, that automatically set pointers to them to null when they are del...
Definition observer_ptr:39
Smart pointer for handling referenced counted objects.
Definition ref_ptr:32
T * get() const
Definition ref_ptr:117
Stores a set of modes and attributes which represent a set of OpenGL state.
Definition StateSet:46
General purpose double pair, uses include representation of texture coordinates.
Definition Vec2d:29
General purpose double triple for use as vertices, vectors and normals.
Definition Vec3d:30
const osg::Matrix computeWindowMatrix() const
Compute the Window Matrix which takes projected coords into Window coordinates.
Definition Viewport:129
Definition GUIActionAdapter:62
Event class for storing Keyboard, mouse and window events.
Definition GUIEventAdapter:82
Base class for motion commands that are generated by draggers.
Definition Command:31
Command for translating in a line.
Definition Command:105
Command for translating in a plane.
Definition Command:142
Command for 1D scaling.
Definition Command:183
Command for 2D scaling.
Definition Command:228
Command for uniform 3D scaling.
Definition Command:273
Command for rotation in 3D.
Definition Command:309
Definition Constraint:36
DraggerCallback()
Definition Constraint:38
Definition Constraint:60
virtual bool receive(const MotionCommand &)
Receive motion commands.
virtual bool receive(const Scale2DCommand &command)
const osg::MatrixTransform * getTransform() const
Definition Dragger:69
@ HANDLE_SCALED_UNIFORM
Definition Dragger:53
@ HANDLE_ROTATE_3D
Definition Dragger:54
@ HANDLE_SCALED_2D
Definition Dragger:52
@ HANDLE_SCALED_1D
Definition Dragger:51
@ HANDLE_TRANSLATE_IN_PLANE
Definition Dragger:50
@ HANDLE_TRANSLATE_IN_LINE
Definition Dragger:49
osg::Matrix _worldToLocal
Definition Dragger:79
virtual bool receive(const TranslateInPlaneCommand &command)
virtual bool receive(const Rotate3DCommand &command)
osg::observer_ptr< osg::MatrixTransform > _transform
Definition Dragger:75
virtual bool receive(const TranslateInLineCommand &command)
DraggerTransformCallback(osg::MatrixTransform *transform, int handleCommandMask=HANDLE_ALL)
virtual bool receive(const Scale1DCommand &command)
osg::MatrixTransform * getTransform()
Definition Dragger:68
virtual bool receive(const ScaleUniformCommand &command)
osg::Matrix _startMotionMatrix
Definition Dragger:76
osg::Matrix _localToWorld
Definition Dragger:78
unsigned int _handleCommandMask
Definition Dragger:73
Definition Dragger:84
void next()
Definition Dragger:108
void setCamera(osg::Camera *camera)
Definition Dragger:136
void setMousePosition(float pixel_x, float pixel_y)
Definition Dragger:165
osg::Matrix _MVPW
Definition Dragger:182
IntersectionList::const_iterator _hitIter
Definition Dragger:175
osg::Vec3d _eyeDir
Definition Dragger:180
osg::Vec3d _nearPoint
Definition Dragger:179
IntersectionList _hitList
Definition Dragger:174
std::list< NodePathIntersectionPair > IntersectionList
Definition Dragger:114
osg::Matrix _inverseMVPW
Definition Dragger:183
const osg::Vec3d & getEyeDir() const
Definition Dragger:127
void getNearFarPoints(osg::Vec3d &nearPoint, osg::Vec3d &farPoint) const
Definition Dragger:129
void addIntersection(const osg::NodePath &nodePath, const osg::Vec3d &intersectionPoint)
Definition Dragger:158
std::pair< osg::NodePath, osg::Vec3d > NodePathIntersectionPair
Definition Dragger:113
void setNearFarPoints(osg::Vec3d nearPoint, osg::Vec3d farPoint)
Definition Dragger:121
bool projectWindowXYIntoObject(const osg::Vec2d &windowCoord, osg::Vec3d &nearPoint, osg::Vec3d &farPoint) const
osg::Vec3d _farPoint
Definition Dragger:179
osg::Vec3d getLocalIntersectPoint() const
Definition Dragger:117
void reset()
Definition Dragger:98
PointerInfo(const PointerInfo &rhs)
Definition Dragger:89
bool contains(const osg::Node *node) const
bool completed() const
Definition Dragger:106
Constraints _constraints
Definition Dragger:307
const Constraints & getConstraints() const
Definition Dragger:245
osgManipulator::PointerInfo _pointer
Definition Dragger:302
bool _activationPermittedByKeyEvent
Definition Dragger:300
virtual void setupDefaultGeometry()
Setup default geometry for dragger.
Definition Dragger:263
unsigned int _activationModKeyMask
Definition Dragger:295
Dragger * getParentDragger()
Definition Dragger:207
virtual void setIntersectionMask(osg::Node::NodeMask intersectionMask)
Set/Get the traversal mask used by this dragger when looking for intersections during event handling.
Definition Dragger:275
bool _activationPermittedByModKeyMask
Definition Dragger:298
void removeTransformUpdating(MatrixTransform *transform)
osg::Node::NodeMask _intersectionMask
Definition Dragger:309
virtual const CompositeDragger * getComposite() const
Returns 0 if this Dragger is not a CompositeDragger.
Definition Dragger:211
virtual bool handle(const osgGA::GUIEventAdapter &ea, osgGA::GUIActionAdapter &aa)
void setActivationMouseButtonMask(unsigned int mask)
Definition Dragger:223
bool getDraggerActive() const
Definition Dragger:269
bool inverted() const
Return true if the axis of the Locator are inverted requiring the faces of any cubes used from render...
void addTransformUpdating(MatrixTransform *transform, int handleCommandMask=DraggerTransformCallback::HANDLE_ALL)
int _activationKeyEvent
Definition Dragger:297
virtual void traverse(osg::NodeVisitor &nv)
Traverse downwards : calls children's accept method with NodeVisitor.
void removeConstraint(const osg::ref_ptr< T > &c)
Definition Dragger:242
DraggerCallbacks _draggerCallbacks
Definition Dragger:308
virtual bool receive(const MotionCommand &command)
bool _draggerActive
Definition Dragger:293
void addConstraint(Constraint *constraint)
unsigned int getActivationMouseButtonMask() const
Definition Dragger:224
void setHandleEvents(bool flag)
Dragger * _parentDragger
Definition Dragger:304
void addDraggerCallback(DraggerCallback *dc)
const DraggerCallbacks & getDraggerCallbacks() const
Definition Dragger:257
virtual void dispatch(MotionCommand &command)
unsigned int getActivationModKeyMask() const
Definition Dragger:221
void removeConstraint(Constraint *constraint)
void setActivationKeyEvent(int key)
Definition Dragger:226
int getActivationKeyEvent() const
Definition Dragger:227
void addConstraint(const osg::ref_ptr< T > &c)
Definition Dragger:239
osg::Node::NodeMask getIntersectionMask() const
Definition Dragger:276
virtual bool handle(const PointerInfo &, const osgGA::GUIEventAdapter &, osgGA::GUIActionAdapter &)
Definition Dragger:233
bool getHandleEvents() const
Definition Dragger:218
META_Node(osgManipulator, Dragger)
osg::ref_ptr< DraggerCallback > _selfUpdater
Definition Dragger:306
Dragger(const Dragger &rhs, const osg::CopyOp &copyop=osg::CopyOp::SHALLOW_COPY)
DraggerCallbacks & getDraggerCallbacks()
Definition Dragger:256
void addDraggerCallback(const osg::ref_ptr< T > &dc)
Definition Dragger:251
const Dragger * getParentDragger() const
Definition Dragger:208
void setActivationModKeyMask(unsigned int mask)
Definition Dragger:220
std::vector< osg::ref_ptr< DraggerCallback > > DraggerCallbacks
Definition Dragger:248
Constraints & getConstraints()
Definition Dragger:244
unsigned int _activationMouseButtonMask
Definition Dragger:296
virtual CompositeDragger * getComposite()
Returns 0 if this Dragger is not a CompositeDragger.
Definition Dragger:214
void removeDraggerCallback(DraggerCallback *dc)
void removeDraggerCallback(const osg::ref_ptr< T > &dc)
Definition Dragger:254
std::vector< osg::ref_ptr< Constraint > > Constraints
Definition Dragger:236
void setDraggerActive(bool active)
Definition Dragger:268
virtual void setParentDragger(Dragger *parent)
Set/Get parent dragger.
Definition Dragger:205
bool _handleEvents
Definition Dragger:292
void applyAppropriateFrontFace(osg::StateSet *ss) const
apply the appropriate FrontFace setting to provided StateSet to ensure that the rendering of hull of ...
bool _activationPermittedByMouseButtonMask
Definition Dragger:299
CompositeDragger allows to create complex draggers that are composed of a hierarchy of Draggers.
Definition Dragger:319
bool containsDragger(const osg::ref_ptr< T > &dc) const
Definition Dragger:346
virtual ~CompositeDragger()
Definition Dragger:357
std::vector< osg::ref_ptr< Dragger > > DraggerList
Definition Dragger:324
bool containsDragger(const Dragger *dragger) const
virtual void setParentDragger(Dragger *parent)
Set/Get parent dragger.
META_Node(osgManipulator, CompositeDragger)
CompositeDragger(const CompositeDragger &rhs, const osg::CopyOp &copyop=osg::CopyOp::SHALLOW_COPY)
virtual CompositeDragger * getComposite()
Returns 0 if this Dragger is not a CompositeDragger.
Definition Dragger:327
DraggerList _draggerList
Definition Dragger:359
virtual bool handle(const PointerInfo &pi, const osgGA::GUIEventAdapter &ea, osgGA::GUIActionAdapter &aa)
virtual bool addDragger(Dragger *dragger)
const Dragger * getDragger(unsigned int i) const
Definition Dragger:343
bool removeDragger(const osg::ref_ptr< T > &dc)
Definition Dragger:338
CompositeDragger()
Definition Dragger:354
Dragger * getDragger(unsigned int i)
Definition Dragger:342
virtual const CompositeDragger * getComposite() const
Returns 0 if this Dragger is not a CompositeDragger.
Definition Dragger:326
DraggerList::iterator findDragger(const Dragger *dragger)
virtual bool removeDragger(Dragger *dragger)
bool addDragger(const osg::ref_ptr< T > &dc)
Definition Dragger:335
virtual void setIntersectionMask(osg::Node::NodeMask intersectionMask)
Set/Get the traversal mask used by this dragger when looking for intersections during event handling.
unsigned int getNumDraggers() const
Definition Dragger:340
#define OSGMANIPULATOR_EXPORT
Definition Export:27

osg logo
Generated at Wed Jul 23 2025 00:00:00 for the OpenSceneGraph by doxygen 1.14.0.