root/OpenSceneGraph/trunk/include/osgGA/NodeTrackerManipulator @ 10764

Revision 10764, 7.1 kB (checked in by robert, 5 years ago)

<iterator>, <stdlib.h> and <ctype.h> includes required for QNX compiler

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
RevLine 
[5328]1/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
[3340]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
14#ifndef OSGGA_NODETRACKERMANIPULATOR
15#define OSGGA_NODETRACKERMANIPULATOR 1
16
17#include <osgGA/MatrixManipulator>
[3398]18
[3340]19#include <osg/Quat>
[5016]20#include <osg/observer_ptr>
[3340]21
[10764]22#include <iterator>
23
[3340]24namespace osgGA{
25
26class OSGGA_EXPORT NodeTrackerManipulator : public MatrixManipulator
27{
28    public:
29
30        NodeTrackerManipulator();
31
32        virtual const char* className() const { return "NodeTrackerManipulator"; }
33
[7102]34        typedef std::vector< osg::observer_ptr<osg::Node> >   ObserverNodePath;
[3340]35
[5375]36        void setTrackNodePath(const osg::NodePath& nodePath)
37        {
38           _trackNodePath.clear();
39           _trackNodePath.reserve(nodePath.size());
40           std::copy(nodePath.begin(), nodePath.end(), std::back_inserter(_trackNodePath));
41        }
42
[7102]43        void setTrackNodePath(const ObserverNodePath& nodePath) { _trackNodePath = nodePath; }
44        ObserverNodePath& getTrackNodePath() { return _trackNodePath; }
[3340]45
[3398]46        void setTrackNode(osg::Node* node);
47        osg::Node* getTrackNode() { return _trackNodePath.empty() ? 0 : _trackNodePath.back().get(); }
48        const osg::Node* getTrackNode() const { return _trackNodePath.empty() ? 0 : _trackNodePath.back().get(); }
49
[3343]50        enum TrackerMode
51        {
[3498]52            /** Track the center of the node's bounding sphere, but not rotations of the node. 
[7648]53              * For databases which have a CoordinateSystemNode, the orientation is kept relative the coordinate frame if the center of the node.
[3498]54              */
[3343]55            NODE_CENTER,
[3498]56            /** Track the center of the node's bounding sphere, and the azimuth rotation (about the z axis of the current coordinate frame).
[7648]57              * For databases which have a CoordinateSystemNode, the orientation is kept relative the coordinate frame if the center of the node.
[3498]58              */
[3495]59            NODE_CENTER_AND_AZIM,
[3498]60            /** Tack the center of the node's bounding sphere, and the all rotations of the node.
61              */
[6461]62            NODE_CENTER_AND_ROTATION
[3343]63        };
64       
65        void setTrackerMode(TrackerMode mode);
[4756]66        TrackerMode getTrackerMode() const { return _trackerMode; }
[3343]67
68
[3340]69        enum RotationMode
70        {
[3498]71            /** Use a trackball style manipulation of the view direction w.r.t the tracked orientation.
72              */
[3495]73            TRACKBALL,
[3498]74            /** Allow the elevation and azimuth angles to be adjust w.r.t the tracked orientation.
75              */
[6461]76            ELEVATION_AZIM
[3340]77        };
78       
79        void setRotationMode(RotationMode mode);
80        RotationMode getRotationMode() const { return _rotationMode; }
81
82
83        /** set the position of the matrix manipulator using a 4x4 Matrix.*/
84        virtual void setByMatrix(const osg::Matrixd& matrix);
85
86        /** set the position of the matrix manipulator using a 4x4 Matrix.*/
87        virtual void setByInverseMatrix(const osg::Matrixd& matrix) { setByMatrix(osg::Matrixd::inverse(matrix)); }
88
89        /** get the position of the manipulator as 4x4 Matrix.*/
90        virtual osg::Matrixd getMatrix() const;
91
92        /** get the position of the manipulator as a inverse matrix of the manipulator, typically used as a model view matrix.*/
93        virtual osg::Matrixd getInverseMatrix() const;
94
[7648]95        /** Get the FusionDistanceMode. Used by SceneView for setting up stereo convergence.*/
[3340]96        virtual osgUtil::SceneView::FusionDistanceMode getFusionDistanceMode() const { return osgUtil::SceneView::USE_FUSION_DISTANCE_VALUE; }
97
[7648]98        /** Get the FusionDistanceValue. Used by SceneView for setting up stereo convergence.*/
[3340]99        virtual float getFusionDistanceValue() const { return _distance; }
100
101        /** Attach a node to the manipulator.
102            Automatically detaches previously attached node.
103            setNode(NULL) detaches previously nodes.
104            Is ignored by manipulators which do not require a reference model.*/
105        virtual void setNode(osg::Node*);
106
107        /** Return node if attached.*/
108        virtual const osg::Node* getNode() const;
109
110        /** Return node if attached.*/
111        virtual osg::Node* getNode();
112
[3497]113        virtual void computeHomePosition();
114
[3340]115        /** Move the camera to the default position.
116            May be ignored by manipulators if home functionality is not appropriate.*/
117        virtual void home(const GUIEventAdapter& ea,GUIActionAdapter& us);
118       
119        /** Start/restart the manipulator.*/
120        virtual void init(const GUIEventAdapter& ea,GUIActionAdapter& us);
121
122        /** handle events, return true if handled, false otherwise.*/
123        virtual bool handle(const GUIEventAdapter& ea,GUIActionAdapter& us);
124
125        /** Get the keyboard and mouse usage of this manipulator.*/
126        virtual void getUsage(osg::ApplicationUsage& usage) const;
127
128    protected:
129
130        virtual ~NodeTrackerManipulator();
[3398]131       
[5016]132        osg::NodePath getNodePath() const;
[3340]133
[5016]134        bool validateNodePath() const;
135
[3340]136        /** Reset the internal GUIEvent stack.*/
137        void flushMouseEventStack();
138        /** Add the current mouse GUIEvent to internal stack.*/
139        void addMouseEvent(const GUIEventAdapter& ea);
140
[3343]141        void computeNodeWorldToLocal(osg::Matrixd& worldToLocal) const;
142        void computeNodeLocalToWorld(osg::Matrixd& localToWorld) const;
[3340]143
[3343]144        void computeNodeCenterAndRotation(osg::Vec3d& center, osg::Quat& rotation) const;
145
[3340]146        void computePosition(const osg::Vec3d& eye,const osg::Vec3d& lv,const osg::Vec3d& up);
147
148        /** For the give mouse movement calculate the movement of the camera.
149            Return true is camera has moved and a redraw is required.*/
150        bool calcMovement();
151       
152        void trackball(osg::Vec3& axis,double& angle, double p1x, double p1y, double p2x, double p2y);
153        double tb_project_to_sphere(double r, double x, double y);
154
155
156        /** Check the speed at which the mouse is moving.
157            If speed is below a threshold then return false, otherwise return true.*/
158        bool isMouseMoving();
159
160
161        void clampOrientation();
162
163
[4919]164        // Internal event stack comprising last two mouse events.
[3340]165        osg::ref_ptr<const GUIEventAdapter> _ga_t1;
166        osg::ref_ptr<const GUIEventAdapter> _ga_t0;
167
168        osg::ref_ptr<osg::Node> _node;
[3398]169       
[7102]170        ObserverNodePath      _trackNodePath;
[3340]171
[3343]172        TrackerMode             _trackerMode;
[3340]173        RotationMode            _rotationMode;
174
175        bool                    _thrown;
176       
[3343]177        osg::Quat               _nodeRotation;
[3340]178        osg::Quat               _rotation;
179        float                   _distance;
180
181};
182
183}
184
185#endif
186
Note: See TracBrowser for help on using the browser.