1/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
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.
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.
13//osgManipulator - Copyright (C) 2007 Fugro-Jason B.V.
15#ifndef OSGMANIPULATOR_CONSTRAINT
16#define OSGMANIPULATOR_CONSTRAINT 1
18#include <osgManipulator/Export>
20#include <osg/observer_ptr>
24namespace osgManipulator {
27class TranslateInLineCommand;
28class TranslateInPlaneCommand;
31class ScaleUniformCommand;
35class DraggerCallback : virtual public osg::Object
41 DraggerCallback(const DraggerCallback& org, const osg::CopyOp& copyop = osg::CopyOp::SHALLOW_COPY):
42 osg::Object(org, copyop) {}
44 META_Object(osgManipulator, DraggerCallback);
47 * Receive motion commands. Returns true on success.
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); }
59class OSGMANIPULATOR_EXPORT Constraint : public osg::Referenced
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); }
74 Constraint(osg::Node& refNode) : _refNode(&refNode) {}
75 virtual ~Constraint() {}
77 osg::Node& getReferenceNode() { return *_refNode; }
78 const osg::Node& getReferenceNode() const { return *_refNode; }
80 const osg::Matrix& getLocalToWorld() const { return _localToWorld; }
81 const osg::Matrix& getWorldToLocal() const { return _worldToLocal; }
83 void computeLocalToWorldAndWorldToLocal() const;
87 osg::observer_ptr<osg::Node> _refNode;
88 mutable osg::Matrix _localToWorld;
89 mutable osg::Matrix _worldToLocal;
93 * Constraint to snap motion commands to a sugar cube grid.
95class OSGMANIPULATOR_EXPORT GridConstraint : public Constraint
99 GridConstraint(osg::Node& refNode, const osg::Vec3d& origin, const osg::Vec3d& spacing);
101 void setOrigin(const osg::Vec3d& origin) { _origin = origin; }
102 const osg::Vec3d& getOrigin() const { return _origin; }
104 void setSpacing(const osg::Vec3d& spacing) { _spacing = spacing; }
105 const osg::Vec3d& getSpacing() const { return _spacing; }
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;
115 virtual ~GridConstraint() {}
121 mutable osg::Matrix _startMatrix;
122 mutable osg::Matrix _matrix;