root/OpenSceneGraph/trunk/include/osgGA/TrackballManipulator @ 9896

Revision 9896, 6.0 kB (checked in by robert, 5 years ago)

From Martin Beckett, added get/setScrollWheelZoomDelta() support for controlling the mouse scroll wheel zoom delta.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
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
14#ifndef OSGGA_TRACKBALLMANIPULATOR
15#define OSGGA_TRACKBALLMANIPULATOR 1
16
17#include <osgGA/MatrixManipulator>
18#include <osg/Quat>
19
20namespace osgGA{
21
22class OSGGA_EXPORT TrackballManipulator : public MatrixManipulator
23{
24    public:
25        TrackballManipulator();
26
27        virtual const char* className() const { return "Trackball"; }
28
29        /** set the position of the matrix manipulator using a 4x4 Matrix.*/
30        virtual void setByMatrix(const osg::Matrixd& matrix);
31
32        /** set the position of the matrix manipulator using a 4x4 Matrix.*/
33        virtual void setByInverseMatrix(const osg::Matrixd& matrix) { setByMatrix(osg::Matrixd::inverse(matrix)); }
34
35        /** get the position of the manipulator as 4x4 Matrix.*/
36        virtual osg::Matrixd getMatrix() const;
37
38        /** get the position of the manipulator as a inverse matrix of the manipulator, typically used as a model view matrix.*/
39        virtual osg::Matrixd getInverseMatrix() const;
40
41        /** Get the FusionDistanceMode. Used by SceneView for setting up stereo convergence.*/
42        virtual osgUtil::SceneView::FusionDistanceMode getFusionDistanceMode() const { return osgUtil::SceneView::USE_FUSION_DISTANCE_VALUE; }
43
44        /** Get the FusionDistanceValue. Used by SceneView for setting up stereo convergence.*/
45        virtual float getFusionDistanceValue() const { return _distance; }
46
47        /** Attach a node to the manipulator.
48            Automatically detaches previously attached node.
49            setNode(NULL) detaches previously nodes.
50            Is ignored by manipulators which do not require a reference model.*/
51        virtual void setNode(osg::Node*);
52
53        /** Return node if attached.*/
54        virtual const osg::Node* getNode() const;
55
56        /** Return node if attached.*/
57        virtual osg::Node* getNode();
58
59        /** Move the camera to the default position.
60            May be ignored by manipulators if home functionality is not appropriate.*/
61        virtual void home(const GUIEventAdapter& ea,GUIActionAdapter& us);
62        virtual void home(double);
63       
64        /** Start/restart the manipulator.*/
65        virtual void init(const GUIEventAdapter& ea,GUIActionAdapter& us);
66
67        /** handle events, return true if handled, false otherwise.*/
68        virtual bool handle(const GUIEventAdapter& ea,GUIActionAdapter& us);
69
70        /** Get the keyboard and mouse usage of this manipulator.*/
71        virtual void getUsage(osg::ApplicationUsage& usage) const;
72
73
74        /** set the minimum distance (as ratio) the eye point can be zoomed in towards the
75            center before the center is pushed forward.*/       
76        void setMinimumZoomScale(double minimumZoomScale) { _minimumZoomScale=minimumZoomScale; }
77
78        /** get the minimum distance (as ratio) the eye point can be zoomed in */
79        double getMinimumZoomScale() const { return _minimumZoomScale; }
80
81        /** set the mouse scroll wheel zoom delta.
82          * Range -1.0 to +1.0,  -ve value inverts wheel direction and zero switches off scroll wheel. */
83        void setScroolWheelZoomDelta(double zoomDelta) { _zoomDelta = zoomDelta; }
84
85        /** get the mouse scroll wheel zoom delta. */
86        double getScroolWheelZoomDelta() const { return _zoomDelta; }
87
88        /** Set the center of the trackball. */
89        void setCenter(const osg::Vec3d& center) { _center = center; }
90
91        /** Get the center of the trackball. */
92        const osg::Vec3d& getCenter() const { return _center; }
93
94        /** Set the rotation of the trackball. */
95        void setRotation(const osg::Quat& rotation) { _rotation = rotation; }
96
97        /** Get the rotation of the trackball. */
98        const osg::Quat& getRotation() const { return _rotation; }
99
100        /** Set the distance of the trackball. */
101        void setDistance(double distance) { _distance = distance; }
102
103        /** Get the distance of the trackball. */
104        double getDistance() const { return _distance; }
105
106        /** Set the size of the trackball. */
107        void setTrackballSize(float size);
108
109        /** Get the size of the trackball. */
110        float getTrackballSize() const { return _trackballSize; }
111    protected:
112
113        virtual ~TrackballManipulator();
114
115        /** Reset the internal GUIEvent stack.*/
116        void flushMouseEventStack();
117        /** Add the current mouse GUIEvent to internal stack.*/
118        void addMouseEvent(const GUIEventAdapter& ea);
119
120        void computePosition(const osg::Vec3& eye,const osg::Vec3& lv,const osg::Vec3& up);
121
122        /** For the give mouse movement calculate the movement of the camera.
123            Return true is camera has moved and a redraw is required.*/
124        bool calcMovement();
125       
126        void trackball(osg::Vec3& axis,float& angle, float p1x, float p1y, float p2x, float p2y);
127        float tb_project_to_sphere(float r, float x, float y);
128
129
130        /** Check the speed at which the mouse is moving.
131            If speed is below a threshold then return false, otherwise return true.*/
132        bool isMouseMoving();
133
134        // Internal event stack comprising last two mouse events.
135        osg::ref_ptr<const GUIEventAdapter> _ga_t1;
136        osg::ref_ptr<const GUIEventAdapter> _ga_t0;
137
138        osg::ref_ptr<osg::Node>       _node;
139
140        double _modelScale;
141        double _minimumZoomScale;
142
143        bool _thrown;
144       
145        osg::Vec3d   _center;
146        osg::Quat    _rotation;
147        double       _distance;
148        float        _trackballSize;
149        float        _zoomDelta;
150
151};
152
153}
154
155#endif
156
Note: See TracBrowser for help on using the browser.